📄 mms-appl.c
字号:
e->u.MMS_Message_Request.content_type = octstr_duplicate(http_cgi_variable(args, "content-type")); e->u.MMS_Message_Request.message = octstr_duplicate(http_cgi_variable(args, "message")); e->u.MMS_Message_Request.delivery_notification_url = octstr_duplicate(http_cgi_variable(args, "delivery-notification-url")); e->u.MMS_Message_Request.response_url = octstr_duplicate(http_cgi_variable(args, "response-url")); if (e->u.MMS_Message_Request.response_url == NULL) /* block until the response is available */ e->u.MMS_Message_Request.http_client = client; /* queue the request */ list_produce(queue, e); return e->u.MMS_Message_Request.response_url != NULL;}static void handle_client_machine(MMSClientMachine *sm, WAPEvent *current_event, MMS_PDU *pdu) { debug("wap.mms", 0, "MMS: machine %p, state %s, event %s", (void *) sm, state_name(sm->state), wap_event_name(current_event->type));#define STATE_NAME(name)#define ROW(state_name, event, condition, action, next_state) \ { \ struct event *e; \ e = ¤t_event->u.event; \ if (sm->state == state_name && \ current_event->type == event && \ (condition)) { \ action \ sm->state = next_state; \ debug("mms.wsp", 0, "WSP %ld: New state %s", \ sm->machine_id, #next_state); \ goto end; \ } \ }#include "mms/mms_receiver_states.def" end: wap_event_destroy(current_event); if (sm->state == NULL_STATE) mms_destroy_client_machine(sm);}static void handle_client_send_machine(MMSClientSendMachine *sm, WAPEvent *current_event, MMS_PDU *pdu) { debug("wap.mms", 0, "MMS: machine %p, state %s, event %s", (void *) sm, state_name(sm->state), wap_event_name(current_event->type));#define STATE_NAME(name)#define ROW(state_name, event, condition, action, next_state) \ { \ struct event *e; \ e = ¤t_event->u.event; \ if (sm->state == state_name && \ current_event->type == event && \ (condition)) { \ action \ sm->state = next_state; \ debug("mms.wsp", 0, "WSP %ld: New state %s", \ sm->machine_id, #next_state); \ goto end; \ } \ }#include "mms/mms_sender_states.def" end: if (current_event->type != MMS_Message_Request) /* we're hanging onto the message request */ wap_event_destroy(current_event); if (sm->state == NULL_STATE) mms_destroy_client_send_machine(sm);}static void mms_control_thread(void *arg) { HTTPClient *client; Octstr *ip, *url, *body, *answer; List *hdrs, *args, *reply_hdrs; int status; for (;;) { client = http_accept_request(mms_control_port, &ip, &url, &hdrs, &body, &args); if (client == NULL) break; reply_hdrs = http_create_empty_headers(); http_header_add(reply_hdrs, "Content-type", "text/html"); http_header_add(reply_hdrs, "Pragma", "no-cache"); http_header_add(reply_hdrs, "Cache-Control", "no-cache"); info(0, "mms-appl: Got HTTP request <%s> from <%s>", octstr_get_cstr(url), octstr_get_cstr(ip)); /* * determine which kind of HTTP request this is any * call the necessary routine for it */ /* dialup control */ if (octstr_compare(url, mms_control_url) == 0) { if (handle_mms_request(client, hdrs, body, args)) { /* asynchronous, return a response immediately, there will be a callback when the result comes in */ status = HTTP_OK; http_send_reply(client, status, reply_hdrs, answer); } } else { answer = octstr_create("Unknown request."); status = HTTP_NOT_FOUND; http_send_reply(client, status, reply_hdrs, answer); octstr_destroy(answer); } octstr_destroy(ip); octstr_destroy(url); http_destroy_headers(hdrs); octstr_destroy(body); http_destroy_cgiargs(args); http_destroy_headers(reply_hdrs); }}static void bearer_polling_thread(void *arg) { Octstr *event; int prev_bearer_status = 0, current_bearer_status; int polling, i, j; WAPEvent *e; /* keep it simple, check the bearer service regularly and inform any active state machines of changes */ while (run_status == running) { sleep(BEARER_POLLING_INTERVAL); current_bearer_status = checkInterface(interface); if (prev_bearer_status == 0 && current_bearer_status == 1) { sendBearerEvent(); } else if (prev_bearer_status == 1 && current_bearer_status == 0) { sendBearerLostEvent(); } if (current_bearer_status == 1) { int bearerneeded = 0; /* check how many state machines still need a bearer */ i = list_len(clientMachines); /* if (i > 0) { j = 0; while ((!bearerneeded) && j < i) bearerneeded = ((MMSClientMachine *)list_get(clientMachines, j))->state != CLIENT_WAITING; } */ if (i > 0) bearerneeded = 1; if (!bearerneeded) { i = list_len(clientSendMachines); /* if (i > 0) { j = 0; while ((!bearerneeded) && j < i) bearerneeded = ((MMSClientSendMachine *)list_get(clientSendMachines, j))->state != SEND_DELIVERY_WAITING; } */ if (i > 0) bearerneeded = 1; } if (!bearerneeded) /* bearer no longer needed */ stopbearerservice(); } prev_bearer_status = current_bearer_status; }}/*********************************************************************** * Thread to handle failed HTTP requests and retries to deliver the * information to the HTTP server. The thread uses the http_requests * queue that is spooled by url_result_thread in case the HTTP requests * fails. */static void http_queue_thread(void *arg) { void *id; Msg *msg; Octstr *req_url; List *req_headers; Octstr *req_body; unsigned long handle, retries; int method; while ((id = list_consume(http_requests)) != NULL) { /* * Sleep for a while in order not to block other operting requests. * Defaults to 10 sec. if not given via http-queue-delay directive in * smsbox group. */ if (http_queue_delay > 0) gwthread_sleep(http_queue_delay); debug("Mms.http",0,"HTTP: Queue contains %ld outstanding requests", list_len(http_requests)); /* * Get all required HTTP request data from the queue and reconstruct * the id pointer for later lookup in url_result_thread. */ get_receiver(id, &handle, &method, &req_url, &req_headers, &req_body, &retries); if (retries < max_http_retries) { id = remember_receiver(handle, method, req_url, req_headers, req_body, ++retries); debug("sms.http",0,"HTTP: Retrying request <%s> (%ld/%ld)", octstr_get_cstr(req_url), retries, max_http_retries); /* re-queue this request to the HTTPCaller list */ http_start_request(mms_caller, method, req_url, req_headers, req_body, 1, id, NULL); } msg_destroy(msg); octstr_destroy(req_url); http_destroy_headers(req_headers); octstr_destroy(req_body); }}static void url_result_thread(void *arg) { Octstr *final_url, *reply_body; List *reply_headers; int status, method; Octstr *req_url; List *req_headers; Octstr *req_body; void *id; unsigned long handle, retries; MMSClientSendMachine *sendmachine = NULL; MMSClientMachine *machine = NULL; unsigned int queued; /* indicate if processes reply is requeued */ for (;;) { id = http_receive_result(mms_caller, &status, &final_url, &reply_headers, &reply_body); if (id == NULL) break; debug("mms", 0, "http response received for %s", octstr_get_cstr(final_url)); get_receiver(id, &handle, &method, &req_url, &req_headers, &req_body, &retries); if (http_status_class(status) == HTTP_STATUS_SUCCESSFUL && octstr_len(reply_body) > 0) { /* feed back to state machine */ WAPEvent *e; e = wap_event_create(HTTP_Request_Completed_Event); e->u.HTTP_Request_Completed_Event.session_handle = handle; e->u.HTTP_Request_Completed_Event.status = status; e->u.HTTP_Request_Completed_Event.response_body = reply_body; reply_body = NULL; list_produce(queue, e); } else if (max_http_retries > retries) { id = remember_receiver(handle, method, req_url, req_headers, req_body, retries); list_produce(http_requests, id); queued++; goto requeued; } else { /* exhausted all the retries, get back to state machine */ WAPEvent *e; e = wap_event_create(HTTP_Request_Completed_Event); e->u.HTTP_Request_Completed_Event.session_handle = handle; e->u.HTTP_Request_Completed_Event.status = status; list_produce(queue, e); error(0, "unable to complete HTTP request %s", final_url); } } requeued: octstr_destroy(final_url); http_destroy_headers(reply_headers); octstr_destroy(reply_body); octstr_destroy(req_url); http_destroy_headers(req_headers); octstr_destroy(req_body);}static void main_thread(void *arg) { WAPEvent *e, *res; MMS_PDU *pdu; long sid; WAPAddrTuple *tuple; Cfg *cfg; MMSClientMachine *clientMachine; MMSClientSendMachine *clientSendMachine; cfg = (Cfg *)arg; while (run_status == running && (e = list_consume(queue)) != NULL) { pdu = NULL; /* Pdu needs to be unpacked in certain cases */ if (e->type == S_Unit_Push_Ind) { pdu = mms_pdu_unpack(e->u.S_Unit_Push_Ind.push_body); if (pdu == NULL) { warning(0, "MMS: Broken PDU ignored."); wap_event_destroy(e); } } if (e->type == S_MethodResult_Ind) { pdu = mms_pdu_unpack(e->u.S_MethodResult_Ind.response_body); if (pdu == NULL) { warning(0, "MMS: Broken PDU ignored."); wap_event_destroy(e); } } if (e->type == HTTP_Request_Completed_Event && e->u.HTTP_Request_Completed_Event.status != HTTP_NO_CONTENT) { pdu = mms_pdu_unpack(e->u.HTTP_Request_Completed_Event.response_body); if (pdu == NULL) { warning(0, "MMS: Broken PDU ignored."); wap_event_destroy(e); } } clientMachine = findClientMachine(e, pdu); if (clientMachine != NULL) { handle_client_machine(clientMachine, e, pdu); if (pdu != clientMachine->notification && pdu != clientMachine->retrieveconf) /* no need to hang on */ mms_pdu_destroy(pdu); } else { clientSendMachine = findClientSendMachine(e, pdu); if (clientSendMachine != NULL) { handle_client_send_machine(clientSendMachine, e, pdu); if (pdu != clientSendMachine->sendconf) mms_pdu_destroy(pdu); } else wap_event_destroy(e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -