⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mms-appl.c

📁 mms client
💻 C
📖 第 1 页 / 共 4 页
字号:
static void get_receiver(void *id, unsigned long *handle, int *method, Octstr **url, List **headers, Octstr **body, unsigned long *retries) {    struct receiver *receiver;    receiver = id;    *handle = receiver->handle;    *method = receiver->method;    *url = receiver->url;    *headers = receiver->http_headers;    *body = receiver->body;    *retries = receiver->retries;    gw_free(receiver);    counter_decrease(num_outstanding_requests);}static void notifyClientByHttp(Octstr *filename, long handle, Octstr *content) {    List *headers;    void *id;    headers = http_create_empty_headers();    http_header_add(headers, "User-Agent", GW_NAME "/" VERSION);    http_header_add(headers, "X-MMS-Filename", octstr_get_cstr(filename));    /* response will come back asynchronously */    id = remember_receiver(handle, HTTP_METHOD_POST, mmsSignalURL, headers, content, 30);    http_start_request(mms_caller, HTTP_METHOD_POST, mmsSignalURL, headers, content, 1, id, NULL);}static void *notifyClient(long status, MMS_PDU *pdu, MMSClientMachine *machine) {    FILE *fp;    Octstr *filename = NULL;    Octstr *xml;    /* some fields might need to be copied from the notification */    if (pdu->u.RetrieveConf.from == NULL)        pdu->u.RetrieveConf.from = octstr_duplicate(machine->notification->u.NotificationInd.from);    if (pdu->u.RetrieveConf.subject == NULL)        pdu->u.RetrieveConf.subject = octstr_duplicate(machine->notification->u.NotificationInd.subject);    /* Save to file in XML format */    if (status == HTTP_OK) {        filename = octstr_format("%s%ld_%ld.xml", octstr_get_cstr(mmsDirectory), pdu->u.RetrieveConf.date, machine->machine_id);        fp = fopen(octstr_get_cstr(filename), "w");        xml = mms_pdu_to_xml(pdu);        octstr_print(fp, xml);        fclose(fp);        octstr_destroy(xml);        if (mmsSignalFile != NULL) {            /* append filename to signal file */            fp = fopen(octstr_get_cstr(mmsSignalFile), "a");            octstr_print(fp, octstr_format("%s\n", octstr_get_cstr(filename)));            fclose(fp);                    }        if (mmsSignalURL != NULL) {            notifyClientByHttp(filename, machine->machine_id, xml);            machine->filename = filename;        }    }}/* check whether the network interface is there */static int checkInterface(Octstr *interface) {    FILE *fh;    char buf[512];    int found = 0;    Octstr *line;    fh = fopen("/proc/net/dev", "r");    if (fh) {        // skipping first 2 lines        fgets(buf, sizeof buf, fh); /* eat line */        fgets(buf, sizeof buf, fh);        while (! found && fgets(buf, sizeof buf, fh)) {            line = octstr_create(buf);            found = octstr_search(line, interface, 0) >= 0;            octstr_destroy(line);        }        fclose(fh);    }    return found;}static int get_addr(char *ifname, struct sockaddr *ifaddr) {    struct ifreq *ifr;    struct ifreq ifrr;    struct sockaddr_in sa;    int sockfd;    ifr = &ifrr;    ifrr.ifr_addr.sa_family = AF_INET;    strncpy(ifrr.ifr_name, ifname, sizeof(ifrr.ifr_name));    if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {        fprintf(stderr, "Cannot open socket.\n");        return -2;    }    if (ioctl(sockfd, SIOCGIFADDR, ifr) < 0) {        printf("No %s interface.\n", ifname);        return -1;    }    *ifaddr = ifrr.ifr_addr;    /*printf("Address for %s: %s\n", ifname, inet_ntoa(inaddrr(ifr_addr.sa_data)));*/    close(sockfd);    return 0;}WAPAddrTuple *getRequestTuple(Octstr *interface) {    struct sockaddr localaddr;    Octstr *localAddr;    struct hostent hostinfo;    /* get the correct local IP address */    get_addr(octstr_get_cstr(interface), &localaddr);    localAddr = gw_netaddr_to_octstr(AF_INET, (struct in_addr *) &localaddr.sa_data);     return wap_addr_tuple_create(wapIpAddress, wapPort, localAddr, 9201);}static void sendWSPConnectRequest(WAPAddrTuple *addrTuple, long handle) {    WAPEvent *e;    /* start connection */    e = wap_event_create(S_Connect_Req);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.S_Connect_Req.addr_tuple = wap_addr_tuple_duplicate(addrTuple);    e->u.S_Connect_Req.session_handle = handle;    wsp_client_session_dispatch_event(e);}static void sendWSPDisconnectRequest(long handle) {    WAPEvent *e;    /* start connection */    e = wap_event_create(S_Disconnect_Req);    e->u.S_Disconnect_Req.session_handle = handle;    wsp_client_session_dispatch_event(e);}static void sendWSPMethodAbort(long transaction_id, long handle) {    WAPEvent *e;    /* start connection */    e = wap_event_create(S_MethodAbort_Req);    e->u.S_MethodAbort_Req.session_handle = handle;    e->u.S_MethodAbort_Req.transaction_id = transaction_id;    wsp_client_session_dispatch_event(e);}static void sendWspAcknowledgement(Octstr *transaction_id, MMSClientMachine *machine) {    MMS_PDU *pdu;    WAPEvent *e;    pdu = mms_pdu_create(AcknowledgeInd);    pdu->u.AcknowledgeInd.x_mms_transaction_id = octstr_duplicate(transaction_id);    pdu->u.AcknowledgeInd.x_mms_mms_version = octstr_imm("1.0");    machine->transaction_id = counter_increase(mms_transaction_counter);    e = wap_event_create(S_MethodInvoke_Req);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.S_MethodInvoke_Req.client_transaction_id = machine->transaction_id;    e->u.S_MethodInvoke_Req.session_handle = machine->machine_id;    e->u.S_MethodInvoke_Req.method = octstr_imm("POST");    e->u.S_MethodInvoke_Req.request_uri = mmsscUrl;    e->u.S_MethodInvoke_Req.request_body = mms_pdu_pack(pdu);    wsp_client_session_dispatch_event(e);}static void sendWspNotifyResponse(Octstr *transaction_id, long status, MMSClientMachine *machine) {    MMS_PDU *pdu;    WAPEvent *e;    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;    machine->transaction_id = counter_increase(mms_transaction_counter);    e = wap_event_create(S_MethodInvoke_Req);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.S_MethodInvoke_Req.client_transaction_id = machine->transaction_id;    e->u.S_MethodInvoke_Req.session_handle = machine->machine_id;    e->u.S_MethodInvoke_Req.method = octstr_imm("POST");    e->u.S_MethodInvoke_Req.request_uri = mmsscUrl;    e->u.S_MethodInvoke_Req.request_body = mms_pdu_pack(pdu);    wsp_client_session_dispatch_event(e);}static void notifySendClientDeliveryReport() {    /* TODO send delivery report to client */}MMS_PDU *createSendReqPDU(MMSClientSendMachine *machine) {    MMS_PDU *pdu;    time_t now;        now = time(NULL);    pdu = mms_pdu_create(SendReq);    pdu->u.SendReq.x_mms_transaction_id =       octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.handle);    pdu->u.SendReq.x_mms_mms_version =          octstr_imm("1.0");    pdu->u.SendReq.date =                       (long) now;    pdu->u.SendReq.from =                       octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.from);    pdu->u.SendReq.from_charset =               machine->mms_send_req->u.MMS_Message_Request.from_charset;    pdu->u.SendReq.to =                         octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.to);    pdu->u.SendReq.to_charset =                 machine->mms_send_req->u.MMS_Message_Request.to_charset;    pdu->u.SendReq.cc =                         octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.cc);    pdu->u.SendReq.cc_charset =                 machine->mms_send_req->u.MMS_Message_Request.cc_charset;    pdu->u.SendReq.bcc =                        octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.bcc);    pdu->u.SendReq.bcc_charset =                machine->mms_send_req->u.MMS_Message_Request.bcc_charset;    pdu->u.SendReq.subject =                    octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.subject);    pdu->u.SendReq.x_mms_message_class =        machine->mms_send_req->u.MMS_Message_Request.message_class;    pdu->u.SendReq.x_mms_expiry =               machine->mms_send_req->u.MMS_Message_Request.expiry;    pdu->u.SendReq.x_mms_expiry_absrelind =     machine->mms_send_req->u.MMS_Message_Request.expiry_type;    pdu->u.SendReq.x_mms_delivery_time =        machine->mms_send_req->u.MMS_Message_Request.delivery_time;    pdu->u.SendReq.x_mms_delivery_time_absrelind = machine->mms_send_req->u.MMS_Message_Request.delivery_time_type;    pdu->u.SendReq.x_mms_priority =             machine->mms_send_req->u.MMS_Message_Request.priority;    pdu->u.SendReq.x_mms_sender_visibility =    machine->mms_send_req->u.MMS_Message_Request.sender_visibility;    pdu->u.SendReq.x_mms_delivery_report =      machine->mms_send_req->u.MMS_Message_Request.delivery_report;    pdu->u.SendReq.x_mms_read_reply =           machine->mms_send_req->u.MMS_Message_Request.read_reply;    pdu->u.SendReq.content_type =               octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.content_type);    pdu->u.SendReq.data =                       octstr_duplicate(machine->mms_send_req->u.MMS_Message_Request.message);}static void sendWSPMSendReq(MMSClientSendMachine *machine) {    MMS_PDU *pdu;    WAPEvent *e;    machine->transaction_id = counter_increase(mms_transaction_counter);    pdu = createSendReqPDU(machine);    e = wap_event_create(S_MethodInvoke_Req);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.S_MethodInvoke_Req.client_transaction_id = machine->transaction_id;    e->u.S_MethodInvoke_Req.session_handle = machine->machine_id;    e->u.S_MethodInvoke_Req.method = octstr_imm("POST");    e->u.S_MethodInvoke_Req.request_uri = mmsscUrl;    e->u.S_MethodInvoke_Req.request_body = mms_pdu_pack(pdu);    wsp_client_session_dispatch_event(e);    mms_pdu_destroy(pdu);}static void wspGet(Octstr *url, MMSClientMachine *machine) {    WAPEvent *e;    machine->transaction_id = counter_increase(mms_transaction_counter);    e = wap_event_create(S_MethodInvoke_Req);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.S_MethodInvoke_Req.client_transaction_id = machine->transaction_id;    e->u.S_MethodInvoke_Req.session_handle = machine->machine_id;    e->u.S_MethodInvoke_Req.method = octstr_imm("GET");    e->u.S_MethodInvoke_Req.request_uri = octstr_duplicate(url);    wsp_client_session_dispatch_event(e);}static void start_timerTO_A_bearer(Timer *timer, long session_handle, long delay) {    WAPEvent *e;    /* start connection */    e = wap_event_create(TimerTO_A_bearer);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.TimerTO_A_bearer.session_handle = session_handle;    e->u.TimerTO_A_bearer.delay = delay;       gwtimer_start(timer, delay, e);}static void start_timerTO_Http_Client(Timer *timer, long session_handle, long delay) {    WAPEvent *e;    /* start connection */    e = wap_event_create(TimerTO_Http_Client);    /* no client headers needed for MMS       leave capability negotiation to default */    e->u.TimerTO_Http_Client.session_handle = session_handle;    gwtimer_start(timer, delay, e);}/* MMS over HTTP */static void sendHTTPMSendReq(MMSClientSendMachine *machine) {    MMS_PDU *pdu;    WAPEvent *e;    List *headers;    void *id;    Octstr *body;    machine->transaction_id = counter_increase(mms_transaction_counter);    pdu = createSendReqPDU(machine);    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);    mms_pdu_destroy(pdu);}static void httpGet(Octstr *url, MMSClientMachine *machine) {    List *headers;    void *id;    headers = http_create_empty_headers();    http_header_add(headers, "User-Agent", GW_NAME "/" VERSION);    id = remember_receiver(machine->machine_id, HTTP_METHOD_GET, url, headers, NULL, 30);    http_start_request(mms_caller, HTTP_METHOD_GET, url, headers, NULL, 1, id, NULL);}static void sendHttpAcknowledgement(Octstr *transaction_id, MMSClientMachine *machine) {    MMS_PDU *pdu;    Octstr *body;    List *headers;    void *id;

⌨️ 快捷键说明

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