33 #ifndef _IDENTT_QUERY_MAILSMS_SERVICE_HPP_ 34 #define _IDENTT_QUERY_MAILSMS_SERVICE_HPP_ 43 template <
class HttpServerT>
69 identt::utils::SharedTable::pointer stptr,
70 typename std::shared_ptr<HttpServerT> server,
71 ::identt::query::HelpQuery::pointer helpquery,
73 :
identt::query::
ServiceBase<HttpServerT>(IDENTT_SERVICE_SCOPE_HTTP | IDENTT_SERVICE_SCOPE_HTTPS)
75 if (!(this->myscope & scope))
return;
78 helpquery->add({scope,
"POST _identt/identity/api/v1/getmailstosend", {
79 "params : lastid, limit, payload[] ",
80 "Needs shared secret in header.",
81 "This will fetch the mail/sms that need sending.",
82 "If request payload contains items marked done they will be marked deleted",
83 "This is to be used only by an internal program" 87 server->resource[
"/_identt/identity/api/v1/getmailstosend$"][
"POST"]
88 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
89 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
91 LOG(INFO) << request->path;
95 ::identt::mail::MailQueryT mailq;
98 int stat =
json2pb( request->content.string() , &mailq , err);
101 form2pb( request->content.string() , &mailq);
106 auto it=request->header.find(
"Shared-Secret");
107 if (it==request->header.end())
109 if (it->second != stptr->shared_secret.Get())
111 mailq.set_shared_secret(it->second);
115 if (stptr->is_master.Get())
120 hclient.
SendToMaster(stptr,::identt::hrpc::M_PENDING,&mailq);
123 mailq.clear_shared_secret();
129 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
132 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
133 std::string output =
err2json(SydentErrors.at(ecode),e.what());
134 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
137 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
138 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
139 }
catch (std::exception& e)
141 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
142 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
158 #endif // _IDENTT_QUERY_MAILSMS_SERVICE_HPP_ void HttpOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em, const char *content_type, std::string &payload, bool add_cors)
HttpOKAction : OK Action template.
Definition: ServiceBase.hpp:154
Definition: MailSmsService.hpp:44
Sydent Exceptions.
Definition: SydentQuery.hpp:91
void PendingAction(::identt::utils::SharedTable::pointer stptr, identt::mail::MailQueryT *mailq)
PendingAction : Get Pending as required.
Definition: MailSmsService.cc:46
void HttpErrorAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em)
HttpErrorAction : Error Action Template no payload maybe template.
Definition: ServiceBase.hpp:85
Definition: BaseUtils.hpp:52
void pb2json(const google::protobuf::Message *msg, std::string &str)
pb2json : Convert protobuf to json
Definition: ProtoJson.cc:415
Definition: MailSmsService.hpp:42
Definition: ServiceBase.hpp:55
Definition: CryptoBase.hpp:49
Definition: BaseUtils.hpp:89
MailSmsService(identt::utils::SharedTable::pointer stptr, typename std::shared_ptr< HttpServerT > server, ::identt::query::HelpQuery::pointer helpquery, unsigned int scope)
MailSmsService : constructor.
Definition: MailSmsService.hpp:68
std::string err2json(const std::string errorcode, const std::string error)
err2json : Generate a Json for Error Message
Definition: ProtoJson.cc:511
bool JsonRequest(typename HttpServerT::ReqPtr request)
JsonRequest : Check if request is json from Content-Type and Accept fields.
Definition: ServiceBase.hpp:178
Definition: HrpcClient.hpp:46
int json2pb(const std::string &json, google::protobuf::Message *msg, std::string &err)
json2pb : Convert json to protobuf
Definition: ProtoJson.cc:446
bool SendToMaster(::identt::utils::SharedTable::pointer stptr, ::identt::hrpc::MasterCmdTypeE service_id, google::protobuf::Message *msg, bool nothrow=false)
SendToMaster : send to master and get output.