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

📄 test_ppg.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ====================================================================  * The Kannel Software License, Version 1.0  *  * Copyright (c) 2001-2004 Kannel Group   * Copyright (c) 1998-2001 WapIT Ltd.    * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  *  * 1. Redistributions of source code must retain the above copyright  *    notice, this list of conditions and the following disclaimer.  *  * 2. Redistributions in binary form must reproduce the above copyright  *    notice, this list of conditions and the following disclaimer in  *    the documentation and/or other materials provided with the  *    distribution.  *  * 3. The end-user documentation included with the redistribution,  *    if any, must include the following acknowledgment:  *       "This product includes software developed by the  *        Kannel Group (http://www.kannel.org/)."  *    Alternately, this acknowledgment may appear in the software itself,  *    if and wherever such third-party acknowledgments normally appear.  *  * 4. The names "Kannel" and "Kannel Group" must not be used to  *    endorse or promote products derived from this software without  *    prior written permission. For written permission, please   *    contact org@kannel.org.  *  * 5. Products derived from this software may not be called "Kannel",  *    nor may "Kannel" appear in their name, without prior written  *    permission of the Kannel Group.  *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,   * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  * ====================================================================  *  * This software consists of voluntary contributions made by many  * individuals on behalf of the Kannel Group.  For more information on   * the Kannel Group, please see <http://www.kannel.org/>.  *  * Portions of this software are based upon software originally written at   * WapIT Ltd., Helsinki, Finland for the Kannel project.   */ /* * A very simple push initiator for testing a push proxy gateway * * Read pap control content and push content from files, pack them into a PAP * protocol MIME message and invoke push services specified by an url. Use a  * hardcoded message boundary (asdlfkjiurwgasf), for simpler command line  * interface. * Repetitions and use of multiple threads can be requested, in addition of  * setting of some headers.  * * By Aarno Syv鋘en for Wiral Ltd and Global Networks Inc. */#define MAX_THREADS 1024#define MAX_IN_QUEUE 128#include <unistd.h>#include <stdlib.h>#include <string.h>#include "gwlib/gwlib.h"#include "gw/wap_push_pap_compiler.h"static long max_pushes = 1;static int verbose = 1,           use_hardcoded = 0,           num_urls = 0,           wait = 0,           use_headers = 0,           use_config = 0,           accept_binary = 0,            use_numeric = 0,           use_string = 0,           use_content_header = 0,           add_epilogue = 0,           add_preamble = 0;static double wait_seconds = 0.0;static Counter *counter = NULL;static char **push_data = NULL;static char *boundary = NULL;static Octstr *content_flag = NULL;static Octstr *appid_flag = NULL;static Octstr *appid_string = NULL;static Octstr *content_header = NULL;static Octstr *content_transfer_encoding = NULL;static Octstr *connection = NULL;static Octstr *delimiter = NULL;static Octstr *initiator_uri = NULL;enum { SSL_CONNECTION_OFF = 0,       DEFAULT_NUMBER_OF_RELOGS = 2};/* * Configuration variables */static int pi_ssl = SSL_CONNECTION_OFF;static long retries = DEFAULT_NUMBER_OF_RELOGS;static Octstr *ssl_client_certkey_file = NULL;static Octstr *push_url = NULL;static Octstr *pap_file = NULL;static Octstr *content_file = NULL;static Octstr *username = NULL;static Octstr *password = NULL;static void read_test_ppg_config(Octstr *name){    Cfg *cfg;    CfgGroup *grp;    cfg = cfg_create(name);    if (cfg_read(cfg) == -1)        panic(0, "Cannot read a configuration file %s, exiting",              octstr_get_cstr(name));    cfg_dump(cfg);    grp = cfg_get_single_group(cfg, octstr_imm("test-ppg"));    cfg_get_integer(&retries, grp, octstr_imm("retries"));    cfg_get_bool(&pi_ssl, grp, octstr_imm("pi-ssl"));#ifdef HAVE_LIBSSL        if (pi_ssl) {        ssl_client_certkey_file = cfg_get(grp,             octstr_imm("ssl-client-certkey-file"));        if (ssl_client_certkey_file != NULL) {            use_global_client_certkey_file(ssl_client_certkey_file);        } else {             error(0, "cannot set up SSL without client certkey file");            exit(1);        }    }#endif    grp = cfg_get_single_group(cfg, octstr_imm("configuration"));    push_url = cfg_get(grp, octstr_imm("push-url"));    pap_file =  cfg_get(grp, octstr_imm("pap-file"));    content_file =  cfg_get(grp, octstr_imm("content-file"));    if (!use_hardcoded) {        username = cfg_get(grp, octstr_imm("username"));        password = cfg_get(grp, octstr_imm("password"));    }    cfg_destroy(cfg);}static void add_delimiter(Octstr **content){    if (octstr_compare(delimiter, octstr_imm("crlf")) == 0) {        octstr_format_append(*content, "%c", '\r');    }    octstr_format_append(*content, "%c", '\n');}static void add_push_application_id(List **push_headers, Octstr *appid_flag,                                    int use_string){    if (use_string) {        list_append(*push_headers, appid_string);        return;    }    if (octstr_compare(appid_flag, octstr_imm("any")) == 0) {        if (!use_numeric)            http_header_add(*push_headers, "X-WAP-Application-Id",                             "http://www.wiral.com:*");        else            http_header_add(*push_headers, "X-WAP-Application-Id", "0");    } else if (octstr_compare(appid_flag, octstr_imm("ua")) == 0) {        if (!use_numeric)            http_header_add(*push_headers, "X-WAP-Application-Id",                             "http://www.wiral.com:wml.ua");        else            http_header_add(*push_headers, "X-WAP-Application-Id", "2");    } else if (octstr_compare(appid_flag, octstr_imm("mms")) == 0) {        if (!use_numeric)            http_header_add(*push_headers, "X-WAP-Application-Id",                             "mms.ua");        else            http_header_add(*push_headers, "X-WAP-Application-Id", "4");    } else if (octstr_compare(appid_flag, octstr_imm("scrap")) == 0) {        if (!use_numeric)            http_header_add(*push_headers, "X-WAP-Application-Id",                         "no appid at all");        else            http_header_add(*push_headers, "X-WAP-Application-Id",                             "this is not a numeric header");    }}static void add_part_header(Octstr *content_keader, Octstr **wap_content){    if (use_content_header) {        octstr_append(*wap_content, content_header);    }    add_delimiter(wap_content);}static void add_content_type(Octstr *content_flag, Octstr **wap_content){    if (octstr_compare(content_flag, octstr_imm("wml")) == 0)        *wap_content = octstr_format("%s",             "Content-Type: text/vnd.wap.wml");    else if (octstr_compare(content_flag, octstr_imm("si")) == 0)	    *wap_content = octstr_format("%s",            "Content-Type: text/vnd.wap.si");    else if (octstr_compare(content_flag, octstr_imm("sl")) == 0)	    *wap_content = octstr_format("%s",            "Content-Type: text/vnd.wap.sl");    else if (octstr_compare(content_flag, octstr_imm("multipart")) == 0)        *wap_content = octstr_format("%s",            "Content-Type: multipart/related; boundary=fsahgwruijkfldsa");    else if (octstr_compare(content_flag, octstr_imm("mms")) == 0)         *wap_content = octstr_format("%s",             "Content-Type: application/vnd.wap.mms-message");     else if (octstr_compare(content_flag, octstr_imm("scrap")) == 0)        *wap_content = octstr_format("%s", "no type at all");     else if (octstr_compare(content_flag, octstr_imm("nil")) == 0)        *wap_content = octstr_create("");    if (octstr_len(*wap_content) > 0)        add_delimiter(wap_content);}static void add_content_transfer_encoding_type(Octstr *content_flag,                                                Octstr *wap_content){    if (!content_flag)	return;    if (octstr_compare(content_flag, octstr_imm("base64")) == 0)	octstr_append_cstr(wap_content, "Content-transfer-encoding: base64");    add_delimiter(&wap_content);}static void add_connection_header(List **push_headers, Octstr *connection){    if (!connection)        return;    if (octstr_compare(connection, octstr_imm("close")) == 0)        http_header_add(*push_headers, "Connection", "close");    else if (octstr_compare(connection, octstr_imm("keep-alive")) == 0)         http_header_add(*push_headers, "Connection", "keep-alive");}static void transfer_encode (Octstr *cte, Octstr *content){    if (!cte)	return;        if (octstr_compare(cte, octstr_imm("base64")) == 0) {       octstr_binary_to_base64(content);    }}/* * Add boundary value to the multipart header. */static Octstr *make_multipart_value(const char *boundary){    Octstr *hos;        hos = octstr_format("%s", "multipart/related; boundary=");    octstr_append(hos, octstr_imm(boundary));    octstr_append(hos, octstr_imm("; type=\"application/xml\""));        return hos;}static Octstr *make_part_delimiter(Octstr *boundary){    Octstr *part_delimiter;    part_delimiter = octstr_create("");    add_delimiter(&part_delimiter);    octstr_format_append(part_delimiter, "%s", "--");    octstr_append(part_delimiter, boundary);    add_delimiter(&part_delimiter);        return part_delimiter;}static Octstr *make_close_delimiter(Octstr *boundary){    Octstr *close_delimiter;    close_delimiter = octstr_create("");    add_delimiter(&close_delimiter);    octstr_format_append(close_delimiter, "%s", "--");    octstr_append(close_delimiter, boundary);    octstr_format_append(close_delimiter, "%s", "--");    /*add_delimiter(&close_delimiter);*/    return close_delimiter;}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);    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;

⌨️ 快捷键说明

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