📄 mms-appl.c
字号:
pdu->u.AcknowledgeInd.x_mms_transaction_id = octstr_duplicate(transaction_id); pdu->u.AcknowledgeInd.x_mms_mms_version = octstr_imm("1.0"); body = mms_pdu_pack(pdu); headers = http_create_empty_headers(); http_header_add(headers, "User-Agent", GW_NAME "/" VERSION); http_header_add(headers, "Content-Type", "application/vnd.wap.mms-message"); id = remember_receiver(machine->machine_id, HTTP_METHOD_POST, mmsscUrl, headers, body, 30); http_start_request(mms_caller, HTTP_METHOD_POST, mmsscUrl, headers, body, 1, id, NULL);}static void sendHttpNotifyResponse(Octstr *transaction_id, long status, MMSClientMachine *machine) { MMS_PDU *pdu; Octstr *body; List *headers; void *id; pdu = mms_pdu_create(NotifyRespInd); pdu->u.NotifyRespInd.x_mms_transaction_id = octstr_duplicate(transaction_id); pdu->u.NotifyRespInd.x_mms_mms_version = octstr_imm("1.0"); pdu->u.NotifyRespInd.x_mms_status = status; body = mms_pdu_pack(pdu); headers = http_create_empty_headers(); http_header_add(headers, "User-Agent", GW_NAME "/" VERSION); http_header_add(headers, "Content-Type", "application/vnd.wap.mms-message"); id = remember_receiver(machine->machine_id, HTTP_METHOD_POST, mmsscUrl, headers, body, 30); http_start_request(mms_caller, HTTP_METHOD_POST, mmsscUrl, headers, body, 1, id, NULL);}static int find_client_by_machine_id(void *mms_ptr, void *id_ptr) { MMSClientMachine *mms = mms_ptr; long *idp = id_ptr; return mms->machine_id == *idp;}static int find_client_send_by_machine_id(void *mms_ptr, void *id_ptr) { MMSClientSendMachine *mms = mms_ptr; long *idp = id_ptr; return mms->machine_id == *idp;}static int find_client_send_by_message_id(void *mms_ptr, void *id_ptr) { MMSClientSendMachine *mms = mms_ptr; Octstr *idp = id_ptr; return octstr_compare(mms->sendconf->u.SendConf.message_id, idp) == 0;}static MMSClientMachine *findClientMachine(WAPEvent *event, MMS_PDU *pdu) { long machine_id; MMSClientMachine *machine = NULL; switch (event->type) { case S_Unit_Push_Ind: if (pdu->type == NotificationInd) { /* machine that will handle this */ machine = mms_create_client_machine(pdu); list_append(clientMachines, machine); } break; case S_Connect_Cnf: machine_id = event->u.S_Connect_Cnf.session_handle; break; case S_Disconnect_Ind: machine_id = event->u.S_Disconnect_Ind.session_handle; break; case S_MethodInvoke_Cnf: machine_id = event->u.S_MethodInvoke_Cnf.session_handle; break; case S_MethodResult_Ind: machine_id = event->u.S_MethodResult_Ind.session_handle; break; case S_MethodAbort_Ind: machine_id = event->u.S_MethodAbort_Ind.session_handle; break; case TimerTO_A_bearer: machine_id = event->u.TimerTO_A_bearer.session_handle; break; case Bearer_Event: machine_id = event->u.Bearer_Event.session_handle; break; case HTTP_Request_Completed_Event: machine_id = event->u.HTTP_Request_Completed_Event.session_handle; break; } if (machine == NULL) machine = list_search(clientMachines, &machine_id, find_client_by_machine_id); return machine;}static MMSClientSendMachine *findClientSendMachine(WAPEvent *event, MMS_PDU *pdu) { long machine_id = -1; Octstr *message_id; MMSClientSendMachine *machine = NULL; switch (event->type) { case S_Unit_Push_Ind: if (pdu->type == DeliveryInd) message_id = pdu->u.DeliveryInd.message_id; break; case S_Connect_Cnf: machine_id = event->u.S_Connect_Cnf.session_handle; break; case S_Disconnect_Ind: machine_id = event->u.S_Disconnect_Ind.session_handle; break; case S_MethodInvoke_Cnf: machine_id = event->u.S_MethodInvoke_Cnf.session_handle; break; case S_MethodResult_Ind: machine_id = event->u.S_MethodResult_Ind.session_handle; break; case S_MethodAbort_Ind: machine_id = event->u.S_MethodAbort_Ind.session_handle; break; case TimerTO_A_bearer: machine_id = event->u.TimerTO_A_bearer.session_handle; break; case Bearer_Event: machine_id = event->u.Bearer_Event.session_handle; break; case MMS_Message_Request: machine = mms_create_client_send_machine(event); list_append(clientSendMachines, machine); break; case HTTP_Request_Completed_Event: machine_id = event->u.HTTP_Request_Completed_Event.session_handle; break; } if (machine == NULL) machine = list_search(clientSendMachines, &machine_id, find_client_send_by_machine_id); if (machine == NULL) machine = list_search(clientSendMachines, &message_id, find_client_send_by_message_id); return machine;}void startbearerservice() { if (modemConn != NULL) startdialup(NULL, modemConn);}void stopbearerservice() { if (modemConn != NULL) stopdialup(NULL, modemConn);}/* send to every active machine */static void sendBearerEvent() { MMSClientMachine *clientMachine; MMSClientSendMachine *clientSendMachine; WAPEvent *e; long i; for (i = 0; i < list_len(clientMachines); i++) { clientMachine = list_get(clientMachines, i); e = wap_event_create(Bearer_Event); e->u.Bearer_Event.session_handle = clientMachine->machine_id; list_insert(queue, 0, e); } for (i = 0; i < list_len(clientSendMachines); i++) { clientSendMachine = list_get(clientSendMachines, i); e = wap_event_create(Bearer_Event); e->u.Bearer_Event.session_handle = clientSendMachine->machine_id; list_insert(queue, 0, e); }}/* send to every active machine */static void sendBearerLostEvent() { MMSClientMachine *clientMachine; MMSClientSendMachine *clientSendMachine; WAPEvent *e; long i; for (i = 0; i < list_len(clientMachines); i++) { clientMachine = list_get(clientMachines, i); e = wap_event_create(Bearer_Lost_Event); e->u.Bearer_Lost_Event.session_handle = clientMachine->machine_id; list_insert(queue, 0, e); } for (i = 0; i < list_len(clientSendMachines); i++) { clientSendMachine = list_get(clientSendMachines, i); e = wap_event_create(Bearer_Lost_Event); e->u.Bearer_Lost_Event.session_handle = clientSendMachine->machine_id; list_insert(queue, 0, e); }}static void clientHttpResponse(HTTPClient *client, MMS_PDU *pdu) { Octstr *answer; List *reply_hdrs; int status; reply_hdrs = http_create_empty_headers(); http_header_add(reply_hdrs, "Pragma", "no-cache"); http_header_add(reply_hdrs, "Cache-Control", "no-cache"); if (pdu == NULL) { /* no response */ http_header_add(reply_hdrs, "Content-type", "text/html"); answer = octstr_create("Timed Out"); status = HTTP_NOT_FOUND; } else { http_header_add(reply_hdrs, "Content-type", "text/xml"); answer = mms_pdu_to_xml(pdu); status = HTTP_OK; } http_send_reply(client, status, reply_hdrs, answer); octstr_destroy(answer); http_destroy_headers(reply_hdrs);}static void clientHttpInform(Octstr *responseUrl, MMS_PDU *pdu, MMSClientSendMachine *machine) { List *headers; Octstr *body; headers = http_create_empty_headers(); http_header_add(headers, "User-Agent", GW_NAME "/" VERSION); http_header_add(headers, "Content-type", "text/xml"); body = mms_pdu_to_xml(pdu); /* response will come back asynchronously */ http_start_request(mms_caller, HTTP_METHOD_GET, mmsSignalURL, headers, body, 1, &machine->machine_id, NULL);}static void notifySendClient(HTTPClient *client, Octstr *responseUrl, MMS_PDU *pdu, MMSClientSendMachine *machine) { if (client != NULL) clientHttpResponse(client, pdu); else clientHttpInform(responseUrl, pdu, machine);}static int handle_mms_request(HTTPClient *client, List *headers, Octstr *body, List *args) { WAPEvent *e; Octstr *tmp_string; e = wap_event_create(MMS_Message_Request); /* read arguments from web into event */ tmp_string = NULL; tmp_string = http_cgi_variable(args, "handle"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%ld", &e->u.MMS_Message_Request.handle); tmp_string = NULL; tmp_string = http_cgi_variable(args, "timeout"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%ld", &e->u.MMS_Message_Request.timeout); else /* default is 15 minutes */ e->u.MMS_Message_Request.timeout = 900; e->u.MMS_Message_Request.from = octstr_duplicate(http_cgi_variable(args, "from")); tmp_string = NULL; tmp_string = http_cgi_variable(args, "from-charset"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.from_charset); e->u.MMS_Message_Request.to = octstr_duplicate(http_cgi_variable(args, "to")); tmp_string = NULL; tmp_string = http_cgi_variable(args, "to-charset"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.to_charset); e->u.MMS_Message_Request.cc = octstr_duplicate(http_cgi_variable(args, "cc")); tmp_string = NULL; tmp_string = http_cgi_variable(args, "cc-charset"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.cc_charset); e->u.MMS_Message_Request.bcc = octstr_duplicate(http_cgi_variable(args, "bcc")); tmp_string = NULL; tmp_string = http_cgi_variable(args, "bcc-charset"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.bcc_charset); e->u.MMS_Message_Request.subject = octstr_duplicate(http_cgi_variable(args, "subject")); tmp_string = NULL; tmp_string = http_cgi_variable(args, "subject-charset"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.subject_charset); tmp_string = NULL; tmp_string = http_cgi_variable(args, "message-class"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.message_class); tmp_string = NULL; tmp_string = http_cgi_variable(args, "expiry"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%ld", &e->u.MMS_Message_Request.expiry); tmp_string = NULL; tmp_string = http_cgi_variable(args, "expiry-type"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.expiry_type); tmp_string = NULL; tmp_string = http_cgi_variable(args, "delivery-time"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%ld", &e->u.MMS_Message_Request.delivery_time); tmp_string = NULL; tmp_string = http_cgi_variable(args, "delivery-time-type"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.delivery_time_type); tmp_string = NULL; tmp_string = http_cgi_variable(args, "priority"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.priority); tmp_string = NULL; tmp_string = http_cgi_variable(args, "sender-visibility"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.sender_visibility); tmp_string = NULL; tmp_string = http_cgi_variable(args, "delivery-report"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.delivery_report); tmp_string = NULL; tmp_string = http_cgi_variable(args, "read-reply"); if (tmp_string != NULL) sscanf(octstr_get_cstr(tmp_string),"%d", &e->u.MMS_Message_Request.read_reply); e->u.MMS_Message_Request.content_type = octstr_duplicate(http_cgi_variable(args, "content-type"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -