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

📄 test_ppg.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 3 页
字号:
}static Octstr *push_content_create(void){    Octstr *push_content,            *wap_content;    Octstr *wap_file_content,           *pap_content,           *pap_file_content,           *bpos,           *bcos;    wap_content = NULL;    push_content = NULL;    if (use_hardcoded) {        push_content = octstr_create("\r\n\r\n"                  "--asdlfkjiurwgasf\r\n"                  "Content-Type: application/xml\r\n\r\n"                  "<?xml version=\"1.0\"?>"                  "<!DOCTYPE pap PUBLIC \"-//WAPFORUM//DTD PAP//EN\""                             " \"http://www.wapforum.org/DTD/pap_1.0.dtd\">"                  "<pap>"                        "<push-message push-id=\"9fjeo39jf084@pi.com\""                          " deliver-before-timestamp=\"2002-11-01T06:45:00Z\""                          " deliver-after-timestamp=\"2000-02-27T06:45:00Z\""                          " progress-notes-requested=\"false\">"			     "<address address-value=\"WAPPUSH=+358408676001/"			 	"TYPE=PLMN@ppg.carrier.com\">"                             "</address>"                             "<quality-of-service"                               " priority=\"low\""                               " delivery-method=\"unconfirmed\""                               " network-required=\"true\""                               " network=\"GSM\""                               " bearer-required=\"true\""                               " bearer=\"SMS\">"                             "</quality-of-service>"                        "</push-message>"                  "</pap>\r\n\r\n"                           "--asdlfkjiurwgasf\r\n"                  "Content-Type: text/vnd.wap.si\r\n\r\n"                  "<?xml version=\"1.0\"?>"                  "<!DOCTYPE si PUBLIC \"-//WAPFORUM//DTD SI 1.0//EN\" "                    " \"http://www.wapforum.org/DTD/si.dtd\">"                  "<si>"                      "<indication href=\"http://wap.iobox.fi\""                          " si-id=\"1@wiral.com\""                          " action=\"signal-high\""                          " created=\"1999-06-25T15:23:15Z\""                          " si-expires=\"2002-12-30T00:00:00Z\">"                          "Want to test a fetch?"                      "</indication>"                   "</si>\r\n\r\n"                 "--asdlfkjiurwgasf--\r\n\r\n"                 "");    } else {        add_content_type(content_flag, &wap_content);        add_content_transfer_encoding_type(content_transfer_encoding,                                            wap_content);        add_part_header(content_header, &wap_content);        /* Read the content file. (To be pushed)*/        if ((wap_file_content =                 octstr_read_file(octstr_get_cstr(content_file))) == NULL)	         panic(0, "Stopping");        if (accept_binary) {            octstr_delete_matching(wap_file_content, octstr_imm(" "));            octstr_delete_matching(wap_file_content, octstr_imm("\n"));            octstr_delete_matching(wap_file_content, octstr_imm("\r"));            if (!octstr_is_all_hex(wap_file_content))                panic(0, "non-hex chars in the content file, cannot continue");            octstr_hex_to_binary(wap_file_content);                    }	transfer_encode(content_transfer_encoding, wap_file_content);        octstr_append(wap_content, wap_file_content);        octstr_destroy(wap_file_content);        /* Read the control file. (To control pushing)*/        pap_content = octstr_format("%s", "Content-Type: application/xml");        add_delimiter(&pap_content);        add_delimiter(&pap_content);        if ((pap_file_content =                 octstr_read_file(octstr_get_cstr(pap_file))) ==  NULL)	        panic(0, "Stopping");                octstr_append(pap_content, pap_file_content);        octstr_destroy(pap_file_content);        if (wap_content == NULL || pap_content == NULL)	        panic(0, "Cannot open the push content files");        push_content = octstr_create("");        if (add_preamble)            octstr_append(push_content, octstr_imm("the parser should discard this"));        octstr_append(push_content,             bpos = make_part_delimiter(octstr_imm(boundary)));        /*octstr_append(push_content, octstr_imm("\r\n"));*/ /* Do we accept an additional                                                           * clrf ? */        octstr_append(push_content, pap_content);        octstr_append(push_content, bpos);        octstr_destroy(bpos);        octstr_append(push_content, wap_content);        octstr_append(push_content,             bcos = make_close_delimiter(octstr_imm(boundary)));        if (add_epilogue) {            octstr_append(push_content, octstr_imm("\r\n"));            octstr_append(push_content, octstr_imm("the parser should discard this"));        }        octstr_destroy(bcos);        octstr_destroy(pap_content);        octstr_destroy(wap_content);    }    return push_content;}static void make_url(Octstr **url){    if (use_config && !use_headers) {        octstr_append(*url, octstr_imm("?username="));        octstr_append(*url, username ? username : octstr_imm("default"));        octstr_append(*url, octstr_imm("&password="));        octstr_append(*url, password ? password: octstr_imm("default"));    }}static void start_push(HTTPCaller *caller, long i)   {    List *push_headers;    Octstr *push_content;    long *id;        push_content = push_content_create();    push_headers = push_headers_create(octstr_len(push_content));    if (verbose) {       debug("test.ppg", 0, "we have push content");       octstr_dump(push_content, 0);       debug("test.ppg", 0, "and headers");       http_header_dump(push_headers);    }    id = gw_malloc(sizeof(long));    *id = i;    make_url(&push_url);    debug("test.ppg", 0, "TEST_PPG: starting to push job %ld", i);    http_start_request(caller, HTTP_METHOD_POST, push_url, push_headers,                        push_content, 0, id, ssl_client_certkey_file);    debug("test.ppg", 0, "push done");    octstr_destroy(push_content);    http_destroy_headers(push_headers);}/* * Try log in defined number of times, when got response 401 and authentica- * tion info is in headers. */static int receive_push_reply(HTTPCaller *caller){    void *id;    long *trid;    int http_status,        tries;    List *reply_headers;    Octstr *final_url,           *auth_url,           *reply_body,           *os,           *push_content,           *auth_reply_body;    WAPEvent *e;    List *retry_headers;        http_status = HTTP_UNAUTHORIZED;    tries = 0;    id = http_receive_result(caller, &http_status, &final_url, &reply_headers,                             &reply_body);    if (id == NULL || http_status == -1 || final_url == NULL) {        error(0, "push failed, no reason found");        goto push_failed;    }    while (use_headers && http_status == HTTP_UNAUTHORIZED && tries < retries) {        debug("test.ppg", 0, "try number %d", tries);        debug("test.ppg", 0, "authentication failure, get a challenge");        http_destroy_headers(reply_headers);        push_content = push_content_create();        retry_headers = push_headers_create(octstr_len(push_content));        http_add_basic_auth(retry_headers, username, password);        trid = gw_malloc(sizeof(long));        *trid = tries;        http_start_request(caller, HTTP_METHOD_POST, final_url, retry_headers,                            push_content, 0, trid, NULL);        debug("test.ppg ", 0, "TEST_PPG: doing response to %s",               octstr_get_cstr(final_url));        octstr_destroy(push_content);        http_destroy_headers(retry_headers);                trid = http_receive_result(caller, &http_status, &auth_url,                                    &reply_headers, &auth_reply_body);        if (trid == NULL || http_status == -1 || auth_url == NULL) {            error(0, "unable to send authorisation, no reason found");            goto push_failed;        }           debug("test.ppg", 0, "TEST_PPG: send authentication to %s, retry %ld",                octstr_get_cstr(auth_url), *(long *) trid);        gw_free(trid);        octstr_destroy(auth_reply_body);        octstr_destroy(auth_url);        ++tries;    }    if (http_status == HTTP_NOT_FOUND) {        error(0, "push failed, service not found");        goto push_failed;    }    if (http_status == HTTP_FORBIDDEN) {        error(0, "push failed, service forbidden");        goto push_failed;    }    if (http_status == HTTP_UNAUTHORIZED) {        if (use_headers)            error(0, "tried %ld times, stopping", retries);        else	        error(0, "push failed, authorisation failure");        goto push_failed;    }            debug("test.ppg", 0, "TEST_PPG: push %ld done: reply from,  %s",           *(long *) id, octstr_get_cstr(final_url));    gw_free(id);    octstr_destroy(final_url);    if (verbose)        debug("test.ppg", 0, "TEST_PPG: reply headers were");    while ((os = list_extract_first(reply_headers)) != NULL) {        if (verbose)            octstr_dump(os, 0);         octstr_destroy(os);    }    if (verbose) {        debug("test.ppg", 0, "TEST_PPG: reply body was");        octstr_dump(reply_body, 0);    }    e = NULL;    if (pap_compile(reply_body, &e) < 0) {        warning(0, "TEST_PPG: receive_push_reply: cannot compile pap message");        goto parse_error;    }    switch (e->type) {        case Push_Response:	        debug("test.ppg", 0, "TEST_PPG: and type push response");	    break;        case Bad_Message_Response:	        debug("test.ppg", 0, "TEST_PPG: and type bad message response");        break;        default:            warning(0, "TEST_PPG: unknown event received from %s",                     octstr_get_cstr(final_url));        break;    }    octstr_destroy(reply_body);    wap_event_destroy(e);    http_destroy_headers(reply_headers);    return 0;push_failed:    gw_free(id);    octstr_destroy(final_url);    octstr_destroy(reply_body);    http_destroy_headers(reply_headers);    return -1;parse_error:    octstr_destroy(reply_body);    http_destroy_headers(reply_headers);    wap_event_destroy(e);    return -1;}static void push_thread(void *arg){    HTTPCaller *caller;    long succeeded, failed, in_queue;    unsigned long i;    caller = arg;    succeeded = 0;    failed = 0;       in_queue = 0;    i = 0;    for (;;) {        while (in_queue < MAX_IN_QUEUE) {	        i = counter_increase(counter);            if (i >= max_pushes)	            goto receive_rest;            start_push(caller, i);            if (wait)                gwthread_sleep(wait_seconds);            ++in_queue;        }        while (in_queue >= MAX_IN_QUEUE) {	        if (receive_push_reply(caller) == -1)	            ++failed;            else	            ++succeeded;            --in_queue;        }    }receive_rest:    while (in_queue > 0) {        if (receive_push_reply(caller) == -1)	        ++failed;        else	        ++succeeded;        --in_queue;    }    http_caller_destroy(caller);    info(0, "TEST_PPG: In thread %ld %ld succeeded, %ld failed",          (long) gwthread_self(), succeeded, failed);

⌨️ 快捷键说明

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