📄 wap_push_ota.c
字号:
static void make_confirmed_push_request(WAPEvent *e){ WAPEvent *wsp_event; List *push_headers; gw_assert(e->type == Po_ConfirmedPush_Req); push_headers = add_push_flag(e); wsp_event = wap_event_create(S_ConfirmedPush_Req); wsp_event->u.S_ConfirmedPush_Req.server_push_id = e->u.Po_ConfirmedPush_Req.server_push_id; wsp_event->u.S_ConfirmedPush_Req.push_headers = push_headers; if (e->u.Po_ConfirmedPush_Req.push_body != NULL) wsp_event->u.S_ConfirmedPush_Req.push_body = octstr_duplicate(e->u.Po_ConfirmedPush_Req.push_body); else wsp_event->u.S_ConfirmedPush_Req.push_body = NULL; wsp_event->u.S_ConfirmedPush_Req.session_id = e->u.Po_ConfirmedPush_Req.session_handle; debug("wap.push.ota", 0, "OTA: making confirmed push request to wsp"); dispatch_to_wsp(wsp_event);}static void make_unit_push_request(WAPEvent *e){ WAPEvent *wsp_event; List *push_headers; Octstr *smsc_id; Octstr *dlr_url; Octstr *smsbox_id; Octstr *push_body; Octstr *service_name; gw_assert(e->type == Po_Unit_Push_Req); gw_assert(e->u.Po_Unit_Push_Req.addr_tuple); gw_assert(e->u.Po_Unit_Push_Req.service_name); smsc_id = octstr_duplicate(e->u.Po_Unit_Push_Req.smsc_id); dlr_url = octstr_duplicate(e->u.Po_Unit_Push_Req.dlr_url); smsbox_id = octstr_duplicate(e->u.Po_Unit_Push_Req.smsbox_id); push_body = octstr_duplicate(e->u.Po_Unit_Push_Req.push_body); service_name = octstr_duplicate(e->u.Po_Unit_Push_Req.service_name); push_headers = add_push_flag(e); wsp_event = wap_event_create(S_Unit_Push_Req); wsp_event->u.S_Unit_Push_Req.addr_tuple = wap_addr_tuple_duplicate(e->u.Po_Unit_Push_Req.addr_tuple); wsp_event->u.S_Unit_Push_Req.push_id = e->u.Po_Unit_Push_Req.push_id; wsp_event->u.S_Unit_Push_Req.push_headers = push_headers; wsp_event->u.S_Unit_Push_Req.address_type = e->u.Po_Unit_Push_Req.address_type; if (smsc_id != NULL) wsp_event->u.S_Unit_Push_Req.smsc_id = smsc_id; else wsp_event->u.S_Unit_Push_Req.smsc_id = NULL; if (dlr_url != NULL) wsp_event->u.S_Unit_Push_Req.dlr_url = dlr_url; else wsp_event->u.S_Unit_Push_Req.dlr_url = NULL; wsp_event->u.S_Unit_Push_Req.dlr_mask = e->u.Po_Unit_Push_Req.dlr_mask; if (smsbox_id != NULL) wsp_event->u.S_Unit_Push_Req.smsbox_id = smsbox_id; else wsp_event->u.S_Unit_Push_Req.smsbox_id = NULL; wsp_event->u.S_Unit_Push_Req.service_name = service_name; if (push_body != NULL) wsp_event->u.S_Unit_Push_Req.push_body = push_body; else wsp_event->u.S_Unit_Push_Req.push_body = NULL; dispatch_to_wsp_unit(wsp_event); debug("wap.push.ota", 0, "OTA: made connectionless session service" " request");}static void abort_push(WAPEvent *e){ WAPEvent *wsp_event; long reason; reason = e->u.Po_PushAbort_Req.reason; gw_assert(e->type == Po_PushAbort_Req); reason_assert(reason); wsp_event = wap_event_create(S_PushAbort_Req); wsp_event->u.S_PushAbort_Req.push_id = e->u.Po_PushAbort_Req.push_id; wsp_event->u.S_PushAbort_Req.reason = reason; wsp_event->u.S_PushAbort_Req.session_handle = e->u.Po_PushAbort_Req.session_id; dispatch_to_wsp(wsp_event); }/* * Add push flag into push headers. Push flag is defined in ota, p. 17-18. * If there is no flags set, no Push-Flag header is added. */static List *add_push_flag(WAPEvent *e){ int push_flag, trusted, authenticated, last; Octstr *buf; List *headers; flags_assert(e); if (e->type == Po_Unit_Push_Req) { trusted = e->u.Po_Unit_Push_Req.trusted << 1; authenticated = e->u.Po_Unit_Push_Req.authenticated; last = e->u.Po_Unit_Push_Req.last << 2; headers = http_header_duplicate(e->u.Po_Unit_Push_Req.push_headers); } else if (e->type == Po_Push_Req) { trusted = e->u.Po_Push_Req.trusted << 1; authenticated = e->u.Po_Push_Req.authenticated; last = e->u.Po_Push_Req.last << 2; headers = http_header_duplicate(e->u.Po_Push_Req.push_headers); } else if (e->type == Po_ConfirmedPush_Req) { trusted = e->u.Po_ConfirmedPush_Req.trusted << 1; authenticated = e->u.Po_ConfirmedPush_Req.authenticated; last = e->u.Po_ConfirmedPush_Req.last << 2; headers = http_header_duplicate( e->u.Po_ConfirmedPush_Req.push_headers); } else { debug("wap.ota", 0, "OTA: no push flag when the event is: \n"); wap_event_dump(e); return NULL; } push_flag = 0; push_flag = push_flag | authenticated | trusted | last; if (push_flag) { buf = octstr_format("%d", push_flag); http_header_add(headers, "Push-Flag", octstr_get_cstr(buf)); octstr_destroy(buf); } return headers;}static void flags_assert(WAPEvent *e){ if (e->type == Po_Unit_Push_Req) { gw_assert(e->u.Po_Unit_Push_Req.trusted == 0 || e->u.Po_Unit_Push_Req.trusted == 1); gw_assert(e->u.Po_Unit_Push_Req.authenticated == 0 || e->u.Po_Unit_Push_Req.authenticated == 1); gw_assert(e->u.Po_Unit_Push_Req.last == 0 || e->u.Po_Unit_Push_Req.last == 1); } else if (e->type == Po_Push_Req) { gw_assert(e->u.Po_Push_Req.trusted == 0 || e->u.Po_Push_Req.trusted == 1); gw_assert(e->u.Po_Push_Req.authenticated == 0 || e->u.Po_Push_Req.authenticated == 1); gw_assert(e->u.Po_Push_Req.last == 0 || e->u.Po_Push_Req.last == 1); } else if (e->type == Po_ConfirmedPush_Req) { gw_assert(e->u.Po_ConfirmedPush_Req.trusted == 0 || e->u.Po_ConfirmedPush_Req.trusted == 1); gw_assert(e->u.Po_ConfirmedPush_Req.authenticated == 0 || e->u.Po_ConfirmedPush_Req.authenticated == 1); gw_assert(e->u.Po_ConfirmedPush_Req.last == 0 || e->u.Po_ConfirmedPush_Req.last == 1); }}/* * Accepted reasons are defined in ota 6.3.3. */static void reason_assert(long reason){ gw_assert(reason == WSP_ABORT_USERREQ || reason == WSP_ABORT_USERRFS || reason == WSP_ABORT_USERPND || reason == WSP_ABORT_USERDCR || reason == WSP_ABORT_USERDCU);}/* * When server is requesting a session with a client, content type and applic- * ation headers must be present (this behaviour is defined in ota, p. 14). * We check headers for them and add them if they are not already present. * X-WAP-Application-Id has been added by ppg module. */static void check_session_request_headers(List *headers){ if (!http_type_accepted(headers, "application/wnd.wap.sia")) http_header_add(headers, "Content-Type", "application/vnd.wap.sia"); }/* * Pack contact points and application id list into sia content type. It is * defined in ota, p. 18. */static Octstr *pack_sia(List *headers){ Octstr *sia_content; WSP_PDU *pdu; pdu = wsp_pdu_create(sia); pdu->u.sia.version = CURRENT_VERSION; pdu->u.sia.application_id_list = pack_appid_list(headers); pdu->u.sia.contactpoints = pack_server_address(); sia_content = wsp_pdu_pack(pdu); wsp_pdu_destroy(pdu); http_destroy_headers(headers); return sia_content;}/* * Input: List of headers containing only X-Wap-Application-Id headers, values * being numeric application id codes. (Ppg module does coding of the header * value part of the X-WAP-Application-Id header). * Output: Octstr containing them in a byte list (one id per byte). * * Returns: Octstr containing headers, if succesfull, otherwise an empty * octstr. */static Octstr *pack_appid_list(List *headers){ Octstr *appid_os, *header_name, *header_value; long i; size_t len; i = 0; appid_os = octstr_create(""); len = (size_t) list_len(headers); gw_assert(len); while (i < len) { http_header_get(headers, i, &header_name, &header_value); gw_assert(octstr_compare(header_name, octstr_imm("X-WAP-Application-Id")) == 0); octstr_format_append(appid_os, "%S", header_value); octstr_destroy(header_name); octstr_destroy(header_value); ++i; } return appid_os;}/* * NB: This data includes bearer information. We use IPv4 values. Address Type * is defined in wsp, table 16, p. 65 */static Octstr *pack_server_address(void){ Octstr *address, *ip_address; unsigned char address_len; long port; int bearer_type; bearer_type = GSM_CSD_IPV4; port = CONNECTED_PORT; mutex_lock(bearerbox->mutex); ip_address = octstr_duplicate(bearerbox->address); address_len = octstr_len(bearerbox->address); mutex_unlock(bearerbox->mutex); address = octstr_create(""); octstr_append_char(address, address_len); octstr_set_bits(address, 0, 1, 1); /* bearer type included */ octstr_set_bits(address, 1, 1, 1); /* port number included */ octstr_append_char(address, bearer_type); octstr_append_decimal(address, port); octstr_append(address, ip_address); octstr_destroy(ip_address); return address;}/* * Returns bearerbox ip address. Resolve it, if the address is localhost. Do * not panic here. Even if we cannot do push, we still can do pull. */ static Octstr *name(Octstr *in){ if (octstr_compare(in, octstr_imm("localhost")) != 0) return octstr_duplicate(in); else return octstr_duplicate(get_official_ip());}static BearerboxAddress *bearerbox_address_create(void) { BearerboxAddress *ba; ba = gw_malloc(sizeof(BearerboxAddress)); ba->mutex = mutex_create(); ba->address = NULL; return ba;}static void bearerbox_address_destroy(BearerboxAddress *ba){ if (ba == NULL) return; octstr_destroy(ba->address); mutex_destroy(ba->mutex); gw_free(ba);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -