wsp_client_session.c

来自「mms client」· C语言 代码 · 共 1,077 行 · 第 1/3 页

C
1,077 行
字号
static Octstr *make_suspend_pdu(WSPClientMachine *m) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Suspend);    pdu->u.Suspend.sessionid = m->server_session_id;    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}static Octstr *make_resume_pdu(List *caps, List *headers) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Resume);    pdu->u.Resume.capabilities = wsp_cap_pack_list(caps);        pdu->u.Resume.headers = wsp_headers_pack(headers, 0);    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}static int transaction_belongs_to_session(void *wsp_ptr, void *tuple_ptr) {    WSPClientMachine *wsp;    WAPAddrTuple *tuple;    wsp = wsp_ptr;    tuple = tuple_ptr;    return wap_addr_tuple_same(wsp->addr_tuple, tuple);}static int find_by_session_handle(void *wsp_ptr, void *id_ptr) {    WSPClientMachine *wsp = wsp_ptr;    long *idp = id_ptr;    return wsp->session_handle == *idp;}static int find_by_method_id(void *wspm_ptr, void *id_ptr) {    WSPClientMethodMachine *msm = wspm_ptr;    long *idp = id_ptr;    return msm->transaction_id == *idp;}static int find_by_push_id(void *m_ptr, void *id_ptr) {    WSPClientPushMachine *m = m_ptr;    long *idp = id_ptr;    return m->transaction_id == *idp;}static WSPClientMethodMachine *find_client_method_machine(WSPClientMachine *sm, long id) {    return list_search(sm->methodmachines, &id, find_by_method_id);}static WSPClientPushMachine *find_push_machine(WSPClientMachine *m, long id) {    return list_search(m->pushmachines, &id, find_by_push_id);}static int same_client(void *a, void *b) {    WSPClientMachine *sm1, *sm2;    sm1 = a;    sm2 = b;    return wap_addr_tuple_same(sm1->addr_tuple, sm2->addr_tuple);}static void disconnect_other_sessions(WSPClientMachine *sm) {    List *old_sessions;    WAPEvent *disconnect;    WSPClientMachine *sm2;    long i;    old_sessions = list_search_all(session_machines, sm, same_client);    if (old_sessions == NULL)        return;    for (i = 0; i < list_len(old_sessions); i++) {        sm2 = list_get(old_sessions, i);        if (sm2 != sm) {            disconnect = wap_event_create(Disconnect_Event);            handle_session_event(sm2, disconnect, NULL);        }    }    list_destroy(old_sessions, NULL);}static List *unpack_new_headers(WSPClientMachine *sm, Octstr *hdrs) {    List *new_headers;    if (hdrs && octstr_len(hdrs) > 0) {        new_headers = wsp_headers_unpack(hdrs, 0);        if (sm->http_headers == NULL)            sm->http_headers = http_create_empty_headers();        http_header_combine(sm->http_headers, new_headers);        return new_headers;    }    return NULL;}static WAPEvent *make_abort(long reason, long handle) {    WAPEvent *wtp_event;    wtp_event = wap_event_create(TR_Abort_Req);    wtp_event->u.TR_Abort_Req.abort_type = 0x01;    wtp_event->u.TR_Abort_Req.abort_reason = reason;    wtp_event->u.TR_Abort_Req.handle = handle;    return wtp_event;}static void send_abort(long reason, long handle) {    WAPEvent *wtp_event;    wtp_event = make_abort(reason, handle);    dispatch_to_wtp_init(wtp_event);}static void sendResultResponse(long handle) {    WAPEvent *wtp_event;    /* TR-Result.res */    wtp_event = wap_event_create(TR_Result_Res);    wtp_event->u.TR_Result_Res.handle = handle;    dispatch_to_wtp_init(wtp_event);}static void sendResultDataResponse(long handle) {    WAPEvent *wtp_event;    /* TR-Result.res */    wtp_event = wap_event_create(TR_Result_Res);    wtp_event->u.TR_Result_Res.handle = handle;    dispatch_to_wtp_init(wtp_event);}static void send_invoke(WSPClientMachine *m, Octstr *pdu, long handle, long acknowledgement, long class) {    WAPEvent *wtp_event;    wtp_event = wap_event_create(TR_Invoke_Req);    wtp_event->u.TR_Invoke_Req.addr_tuple = wap_addr_tuple_duplicate(m->addr_tuple);    wtp_event->u.TR_Invoke_Req.up_flag = acknowledgement;    wtp_event->u.TR_Invoke_Req.tcl = class;    wtp_event->u.TR_Invoke_Req.handle = handle;    wtp_event->u.TR_Invoke_Req.user_data = pdu;    dispatch_to_wtp_init(wtp_event);}static void indicate_disconnect(WSPClientMachine *sm, long reason) {    WAPEvent *new_event;    new_event = wap_event_create(S_Disconnect_Ind);    new_event->u.S_Disconnect_Ind.reason_code = reason;    new_event->u.S_Disconnect_Ind.redirect_security = 0;    new_event->u.S_Disconnect_Ind.redirect_addresses = 0;    new_event->u.S_Disconnect_Ind.error_headers = NULL;    new_event->u.S_Disconnect_Ind.error_body = NULL;    new_event->u.S_Disconnect_Ind.session_handle = sm->session_handle;    dispatch_to_appl(new_event);}static void indicate_suspend(WSPClientMachine *sm, long reason) {    WAPEvent *new_event;    new_event = wap_event_create(S_Suspend_Ind);    new_event->u.S_Suspend_Ind.reason = reason;    new_event->u.S_Suspend_Ind.session_id = sm->server_session_id;    dispatch_to_appl(new_event);}static void indicate_resume(WSPClientMachine *sm, WAPAddrTuple *tuple, List *headers) {    WAPEvent *new_event;    new_event = wap_event_create(S_Resume_Ind);    new_event->u.S_Resume_Ind.addr_tuple = wap_addr_tuple_duplicate(tuple);    new_event->u.S_Resume_Ind.client_headers = http_header_duplicate(headers);    new_event->u.S_Resume_Ind.session_id = sm->session_handle;    dispatch_to_appl(new_event);}static void indicate_push(WSPClientMachine *sm, WSP_PDU *pdu) {    WAPEvent *new_event;    new_event = wap_event_create(S_Push_Ind);    new_event->u.S_Push_Ind.push_headers = wsp_headers_unpack(pdu->u.Push.headers, 1);    new_event->u.S_Push_Ind.push_body = octstr_duplicate(pdu->u.Push.data);    new_event->u.S_Push_Ind.session_handle = sm->session_handle;    dispatch_to_appl(new_event);}static void indicate_pushabort(WSPClientPushMachine *spm, long reason) {    WAPEvent *ota_event;    ota_event = wap_event_create(S_PushAbort_Ind);    ota_event->u.S_PushAbort_Ind.push_id = spm->client_push_id;    ota_event->u.S_PushAbort_Ind.reason = reason;    ota_event->u.S_PushAbort_Ind.session_id = spm->session_handle;    dispatch_to_appl(ota_event);}static void indicate_confirmedpush(WSPClientMachine *sm, WSP_PDU *pdu, long client_push_id) {    WAPEvent *new_event;    new_event = wap_event_create(S_ConfirmedPush_Ind);    new_event->u.S_ConfirmedPush_Ind.client_push_id = client_push_id;    new_event->u.S_ConfirmedPush_Ind.push_headers = wsp_headers_unpack(pdu->u.ConfirmedPush.headers, 1);    new_event->u.S_ConfirmedPush_Ind.push_body = octstr_duplicate(pdu->u.ConfirmedPush.data);    new_event->u.S_ConfirmedPush_Ind.session_handle = sm->session_handle;}static void confirm_connect(WSPClientMachine *sm, List *httpHeaders, List *caps) {    WAPEvent *new_event;    new_event = wap_event_create(S_Connect_Cnf);    new_event->u.S_Connect_Cnf.negotiated_capabilities = wsp_cap_duplicate_list(caps);    new_event->u.S_Connect_Cnf.server_headers = http_header_duplicate(httpHeaders);    new_event->u.S_Connect_Cnf.session_handle = sm->session_handle;    dispatch_to_appl(new_event);}static void confirm_resume(WSPClientMachine *sm, List *httpHeaders) {    WAPEvent *new_event;    new_event = wap_event_create(S_Resume_Cnf);    new_event->u.S_Resume_Cnf.server_headers = http_header_duplicate(httpHeaders);    new_event->u.S_Resume_Cnf.session_handle = sm->session_handle;    dispatch_to_appl(new_event);}static void confirm_methodinvoke(WSPClientMethodMachine *msm) {    WAPEvent *new_event;    new_event = wap_event_create(S_MethodInvoke_Cnf);    new_event->u.S_MethodInvoke_Cnf.client_transaction_id = msm->transaction_id;    new_event->u.S_MethodInvoke_Cnf.session_handle = msm->session_handle;    dispatch_to_appl(new_event);}static void method_abort(WSPClientMethodMachine *msm, long reason) {    WAPEvent *wtp_event;    /* Send TR-Abort.req(reason) */    wtp_event = wap_event_create(TR_Abort_Req);    /* FIXME: Specs are unclear about this; we may indeed have to     * guess abort whether this is a WSP or WTP level abort code */    if (reason < WSP_ABORT_PROTOERR) {        wtp_event->u.TR_Abort_Req.abort_type = 0x00;    } else {        wtp_event->u.TR_Abort_Req.abort_type = 0x01;    }    wtp_event->u.TR_Abort_Req.abort_reason = reason;    wtp_event->u.TR_Abort_Req.handle = msm->transaction_id;    dispatch_to_wtp_init(wtp_event);}static void indicate_method_result(WSPClientMethodMachine *msm, List *headers, Octstr *body, long status) {    WAPEvent *new_event;    /* Send S-MethodResult.ind */    new_event = wap_event_create(S_MethodResult_Ind);    new_event->u.S_MethodResult_Ind.client_transaction_id = msm->transaction_id;    new_event->u.S_MethodResult_Ind.status = status;    new_event->u.S_MethodResult_Ind.response_headers = http_header_duplicate(headers);    new_event->u.S_MethodResult_Ind.response_body = octstr_duplicate(body);    new_event->u.S_MethodResult_Ind.session_handle = msm->session_handle;    dispatch_to_appl(new_event);}static void indicate_method_abort(WSPClientMethodMachine *msm, long reason) {    WAPEvent *new_event;    /* Send S-MethodAbort.ind(reason) */    new_event = wap_event_create(S_MethodAbort_Ind);    new_event->u.S_MethodAbort_Ind.transaction_id = msm->transaction_id;    new_event->u.S_MethodAbort_Ind.reason = reason;    new_event->u.S_MethodAbort_Ind.session_handle = msm->session_handle;    dispatch_to_appl(new_event);}static void abort_methods(WSPClientMachine *sm, long reason) {    WAPEvent *ab;    WSPClientMethodMachine *msm;    long i, len;    ab = wap_event_create(Abort_Event);    ab->u.Abort_Event.reason = reason;    /* This loop goes backward because it has to deal with the     * possibility of method machines disappearing after their event. */    len = list_len(sm->methodmachines);    for (i = len - 1; i >= 0; i--) {        msm = list_get(sm->methodmachines, i);        handle_method_event(sm, msm, ab, NULL);    }    wap_event_destroy(ab);}static void abort_method(WSPClientMachine *sm, long handle, long reason) {    WSPClientMethodMachine *msm;    WAPEvent *ab;    /* abort(PROTOERR) the method transaction */            ab = wap_event_create(Abort_Event);    ab->u.Abort_Event.reason = reason;    msm = find_client_method_machine(sm, handle);    handle_method_event(sm, msm, ab, NULL);}static void abort_pushes(WSPClientMachine *sm, long reason) {    WAPEvent *ab;    WSPClientPushMachine *psm;    long i, len;    ab = wap_event_create(Abort_Event);    ab->u.Abort_Event.reason = reason;    len = list_len(sm->pushmachines);    for (i = len - 1; i >= 0; i--) {        psm = list_get(sm->pushmachines, i);        handle_push_event(sm, psm, ab, NULL);    }    wap_event_destroy(ab);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?