📄 xml2wbxml.c
字号:
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 List *push_headers_create(size_t content_len){ List *push_headers; Octstr *mos; mos = NULL; push_headers = http_create_empty_headers(); if (use_hardcoded) http_header_add(push_headers, "Content-Type", "multipart/related;" " boundary=asdlfkjiurwgasf; type=\"application/xml\""); else http_header_add(push_headers, "Content-Type", octstr_get_cstr(mos = make_multipart_value(boundary))); if (use_headers) http_add_basic_auth(push_headers, username, password); add_push_application_id(&push_headers, appid_flag, use_string); add_connection_header(&push_headers, connection); if (use_dlr_mask) add_dlr_mask(&push_headers, dlr_mask); if (use_dlr_url) add_dlr_url(&push_headers, dlr_url); octstr_destroy(mos); /* add initiator... */ if (initiator_uri) http_header_add(push_headers, "X-Wap-Initiator-URI", octstr_get_cstr(initiator_uri)); return push_headers;}static Octstr *push_content_create(void){ Octstr *push_content, *wap_content; Octstr *wap_file_content, *pap_content, *pap_file_content, *bpos, *bcos;/* * 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 = gwlist_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;} 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);}static void help(void) { info(0, "Usage: test_ppg [options] push_url [content_file pap_file]"); info(0, " or"); info(0, "Usage: test_ppg [options] [conf_file]"); info(0, "Implements push initiator for wap push. Push services are "); info(0, "located in push_url, push content in the file content file."); info(0, "File pap_file contains pap control document that controls"); info(0, "pushing"); info(0, "If option -H is not used, command line has either three or one"); info(0, "arguments:"); info(0, " a) the url of the push proxy gateway"); info(0, " b) a file containing the content to be pushed"); info(0, " c) a pap document controlling pushing"); info(0, " or"); info(0, " a) a test configuration file, containing all these"); info(0, "Option -H cannot be used with a configuration file. If it is"); info(0, "used, the push url is the only argument."); info(0, "Options are:"); info(0, "-h"); info(0, "print this info"); info(0, "-c content qualifier"); info(0, "Define content type of the push content. Wml, multipart, nil,"); info(0, "scrap, sl, and si accepted. Si is default, nil (no content"); info(0, " type at all) and scrap (random string) are used for debugging"); info(0, "-a application id");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -