Пример #1
0
int main(int argc, char **argv)
{
    Octstr *data, *filename, *hex;

    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

    if (argc < 2)
        panic(0, "Syntax: %s <file>\n", argv[0]);

    filename = octstr_create(argv[1]);
    data = octstr_read_file(octstr_get_cstr(filename));

    if (data == NULL)
        panic(0, "Cannot read file.");

    /* 
     * We test if this is a text/plain file with hex values in it.
     * Therefore copy the data and trail off any CR and LF from 
     * beginning and end and test if the result is only hex chars.
     * If yes, then convert to binary before dumping.
     */
    hex = octstr_duplicate(data);
    octstr_strip_crlfs(hex);
    if (octstr_is_all_hex(hex)) {
        debug("",0,"Trying to converting from hex to binary.");
        if (octstr_hex_to_binary(hex) == 0) {
            FILE *f = fopen(argv[2], "w");
            debug("",0,"Convertion was successfull. Writing binary content to file `%s'",
                  argv[2]);
            octstr_destroy(data);
            data = octstr_duplicate(hex);
            octstr_print(f, data);
            fclose(f);
        } else {
            debug("",0,"Failed to convert from hex?!");
        }
    }                                      

    debug("",0,"Dumping file `%s':", octstr_get_cstr(filename));
    octstr_dump(data, 0);

    octstr_destroy(data);
    octstr_destroy(hex);
    gwlib_shutdown();
    return 0;
}
Пример #2
0
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=\"[email protected]\""
                          " 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/"
			 	"[email protected]\">"
                             "</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=\"[email protected]\""
                          " 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;
}