wsp_client_session.c

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

C
1,077 行
字号
         event->u.TR_Invoke_Ind.tcl == 2)) {        warning(0, "WSP: Can't handle TR-Invoke.ind, aborting transaction.");        debug("wap.wsp", 0, "WSP: The unhandled event:");        wap_event_dump(event);        send_abort(WSP_ABORT_PROTOERR,                   event->u.TR_Invoke_Ind.handle);        /* The sixth is a class 0 TR-Invoke.ind not handled by state tables. */    } else if (event->type == TR_Invoke_Ind) {        warning(0, "WSP: Can't handle TR-Invoke.ind, ignoring.");        debug("wap.wsp", 0, "WSP: The ignored event:");        wap_event_dump(event);        /* The seventh is any other event not handled by state tables. */    } else {        error(0, "WSP: Can't handle event. Aborting session.");        debug("wap.wsp", 0, "WSP: The unhandled event:");        wap_event_dump(event);        /* TR-Abort.req(PROTOERR) if it is some other transaction         * event than abort. */        /* Currently that means TR-Result.cnf, because we already         * tested for Invoke. */        /* FIXME We need a better way to get at event values than         * by hardcoding the types. */        if (event->type == TR_Result_Cnf) {            send_abort(WSP_ABORT_PROTOERR,                       event->u.TR_Result_Cnf.handle);        }        /* Abort(PROTOERR) all method and push transactions */        abort_methods(sm, WSP_ABORT_PROTOERR);        abort_pushes(sm, WSP_ABORT_PROTOERR);        /* S-Disconnect.ind(PROTOERR) */        indicate_disconnect(sm, WSP_ABORT_PROTOERR);    }}static WSPClientMachine *machine_create(void) {    WSPClientMachine *p;    p = gw_malloc(sizeof(WSPClientMachine));    debug("wap.wsp", 0, "WSP: Created WSPClientMachine %p", (void *) p);#define INTEGER(name) p->name = 0;#define OCTSTR(name) p->name = NULL;#define HTTPHEADERS(name) p->name = NULL;#define ADDRTUPLE(name) p->name = NULL;#define MACHINESLIST(name) p->name = list_create();#define CAPABILITIES(name) p->name = NULL;#define COOKIES(name) p->name = NULL;#define REFERER(name) p->name = NULL;#define MACHINE(fields) fields#include "wsp_client_session_machine.def"    p->state = NULL_SESSION;    /* set capabilities to default values (defined in 1.1) */    p->SDU_size = 1400;    /* Insert new machine at the _front_, because 1) it's more likely     * to get events than old machines are, so this speeds up the linear     * search, and 2) we want the newest machine to get any method     * invokes that come through before the Connect is established. */    list_insert(session_machines, 0, p);    /* handle */    p->connect_handle = -1;    p->resume_handle = -1;    return p;}static void destroy_methodmachines(List *machines) {    if (list_len(machines) > 0) {        warning(0, "Destroying WSP session with %ld active methods\n",                list_len(machines));    }    list_destroy(machines, method_machine_destroy);}static void destroy_pushmachines(List *machines) {    if (list_len(machines) > 0) {        warning(0, "Destroying WSP session with %ld active pushes\n",                list_len(machines));    }    list_destroy(machines, push_machine_destroy);}static void machine_destroy(void *pp) {    WSPClientMachine *p;    p = pp;    debug("wap.wsp", 0, "Destroying WSPClientMachine %p", pp);    list_delete_equal(session_machines, p);#define INTEGER(name) p->name = 0;#define OCTSTR(name) octstr_destroy(p->name);#define HTTPHEADERS(name) http_destroy_headers(p->name);#define ADDRTUPLE(name) wap_addr_tuple_destroy(p->name);#define MACHINESLIST(name) destroy_##name(p->name);#define CAPABILITIES(name) wsp_cap_destroy_list(p->name);#define COOKIES(name) cookies_destroy(p->name);#define REFERER(name) octstr_destroy(p->name);#define MACHINE(fields) fields#include "wsp_client_session_machine.def"    gw_free(p);}struct msm_pattern {    WAPAddrTuple *addr_tuple;    long msmid, tid;};/* This function does NOT consume its event; it leaves that task up * to the parent session */static void handle_method_event(WSPClientMachine *sm, WSPClientMethodMachine *msm, WAPEvent *current_event, WSP_PDU *pdu) {    if (msm == NULL) {        warning(0, "No method machine for event.");        wap_event_dump(current_event);        return;    }    debug("wap.wsp", 0, "WSP: method %ld, state %s, event %s",          msm->transaction_id, state_name(msm->state),           wap_event_name(current_event->type));    gw_assert(sm->session_handle == msm->session_handle);#define STATE_NAME(name)#define ROW(state_name, event, condition, action, next_state) \		{ \			struct event *e; \			e = &current_event->u.event; \			if (msm->state == state_name && \			   current_event->type == event && \			   (condition)) { \				action \				msm->state = next_state; \				debug("wap.wsp", 0, "WSP %ld/%ld: New method state %s", \					msm->session_handle, msm->transaction_id, #next_state); \				goto end; \			} \		}#include "wsp_client_method_states.def"    cant_handle_event(sm, current_event);    end:    if (msm->state == NULL_METHOD) {        method_machine_destroy(msm);        list_delete_equal(sm->methodmachines, msm);    }}static WSPClientMethodMachine *method_machine_create(WSPClientMachine *sm, long wtp_handle) {    WSPClientMethodMachine *msm;    msm = gw_malloc(sizeof(*msm));#define INTEGER(name) msm->name = 0;#define ADDRTUPLE(name) msm->name = NULL;#define EVENT(name) msm->name = NULL;#define MACHINE(fields) fields#include "wsp_client_method_machine.def"    msm->transaction_id = wtp_handle;    msm->state = NULL_METHOD;    msm->addr_tuple = wap_addr_tuple_duplicate(sm->addr_tuple);    msm->server_session_id = sm->server_session_id;    msm->session_handle = sm->session_handle;    list_append(sm->methodmachines, msm);    return msm;}static void method_machine_destroy(void *p) {    WSPClientMethodMachine *msm;    if (p == NULL)        return;    msm = p;    debug("wap.wsp", 0, "Destroying WSPClientMethodMachine %ld",          msm->transaction_id);#define INTEGER(name)#define ADDRTUPLE(name) wap_addr_tuple_destroy(msm->name);#define EVENT(name) wap_event_destroy(msm->name);#define MACHINE(fields) fields#include "wsp_client_method_machine.def"    gw_free(msm);}static void handle_push_event(WSPClientMachine *sm, WSPClientPushMachine *pm, WAPEvent *current_event, WSP_PDU *pdu) {    if (pm == NULL) {        warning(0, "No push machine for event.");        wap_event_dump(current_event);        return;    }    debug("wap.wsp", 0, "WSP(tid/pid): push %ld/%ld, state %s, event %s",          pm->transaction_id, pm->client_push_id, state_name(pm->state),           wap_event_name(current_event->type));    gw_assert(sm->server_session_id == pm->server_session_id);#define STATE_NAME(name)#define ROW(state_name, event, condition, action, next_state) \		{ \		    if (pm->state == state_name && \			current_event->type == event && \			(condition)) { \			     action \			     pm->state = next_state; \			     debug("wap.wsp", 0, "WSP %ld/%ld: New push state %s", \			           pm->session_handle, pm->transaction_id, #next_state); \				goto end; \			} \		}#include "wsp_client_push_states.def"    cant_handle_event(sm, current_event);    end:    if (pm->state == CLIENT_PUSH_NULL_STATE) {        push_machine_destroy(pm);        list_delete_equal(sm->pushmachines, pm);    }}static WSPClientPushMachine *client_push_machine_create(WSPClientMachine *sm) {    WSPClientPushMachine *m;    m = gw_malloc(sizeof(WSPClientPushMachine));#define INTEGER(name) m->name = 0;#define ADDRTUPLE(name) m->name = NULL;#define HTTPHEADER(name) m->name = http_create_empty_headers();#define MACHINE(fields) fields#include "wsp_client_push_machine.def"    m->client_push_id = counter_increase(client_push_id_counter);    m->state = CLIENT_PUSH_NULL_STATE;    m->addr_tuple = wap_addr_tuple_duplicate(sm->addr_tuple);    m->server_session_id = sm->server_session_id;    m->session_handle = sm->session_handle;    list_append(sm->pushmachines, m);    return m;      }static void push_machine_destroy(void *p) {    WSPClientPushMachine *m = NULL;       if (p == NULL)        return;    m = p;    debug("wap.wsp", 0, "Destroying WSPClientPushMachine %ld",          m->transaction_id);#define INTEGER(name) #define ADDRTUPLE(name) wap_addr_tuple_destroy(m->name);#define HTTPHEADER(name) http_destroy_headers(m->name);#define MACHINE(fields) fields#include "wsp_client_push_machine.def"    gw_free(m);}static char *state_name(WSPState state) {    switch (state) {#define STATE_NAME(name) case name: return #name;#define ROW(state, event, cond, stmt, next_state)#include "wsp_client_session_states.def"#define STATE_NAME(name) case name: return #name;#define ROW(state, event, cond, stmt, next_state)#include "wsp_client_method_states.def"#define STATE_NAME(name) case name: return #name;#define ROW(state, event, cond, stmt, next_state)#include "wsp_client_push_states.def"        default:            return "unknown wsp state";    }}static Octstr *make_connect_pdu(WSPClientMachine *m) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Connect);    pdu->u.Connect.version = 0x10;    pdu->u.Connect.capabilities = wsp_cap_pack_list(m->request_caps);        pdu->u.Connect.headers = wsp_headers_pack(m->http_headers, 0);    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}static Octstr *make_disconnect_pdu(WSPClientMachine *m) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Disconnect);    pdu->u.Disconnect.sessionid = m->server_session_id;    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}static Octstr *make_get_pdu(List *httpHeaders, Octstr *uri) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Get);    pdu->u.Get.uri = octstr_duplicate(uri);    pdu->u.Get.headers = wsp_headers_pack(httpHeaders, 0);    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}static Octstr *make_post_pdu(List *httpHeaders, Octstr *uri, Octstr *data) {    WSP_PDU *pdu;    Octstr *os;    pdu = wsp_pdu_create(Post);    pdu->u.Post.uri = octstr_duplicate(uri);    /* assume that Content-Type is one of the headers */    pdu->u.Post.headers = wsp_headers_pack(httpHeaders, 1);    pdu->u.Post.data = octstr_duplicate(data);    os = wsp_pdu_pack(pdu);    wsp_pdu_destroy(pdu);    return os;}

⌨️ 快捷键说明

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