コード例 #1
0
ファイル: mtbatch.c プロジェクト: LeeVidor/kannel-mongodb
static void init_batch(Octstr *cfilename, Octstr *rfilename)
{
    Octstr *receivers;
    long lineno = 0; 

    content = octstr_read_file(octstr_get_cstr(cfilename)); 
    octstr_strip_crlfs(content);
    if (content == NULL) 
        panic(0,"Can not read content file `%s'.", 
              octstr_get_cstr(cfilename));
    info(0,"SMS-Text: <%s>", octstr_get_cstr(content));

    info(0,"Loading receiver list. This may take a while...");
    receivers = octstr_read_file(octstr_get_cstr(rfilename)); 
    if (receivers == NULL) 
        panic(0,"Can not read receivers file `%s'.", 
              octstr_get_cstr(rfilename)); 

    lines = octstr_split(receivers, octstr_imm("\n")); 
    lineno = gwlist_len(lines);
    if (lineno <= 0) 
        panic(0,"Receiver file seems empty!");

    info(0,"Receivers file `%s' contains %ld destination numbers.",
         octstr_get_cstr(rfilename), lineno);

    counter = counter_create();
}
コード例 #2
0
ファイル: mms_resolve_shell.c プロジェクト: markjeee/mbuni
static Octstr *mms_resolve(Octstr *phonenum, char *src_int, char *src_id, 
			   void *module_data, void *settings_p, void *proxyrelays_p)
{
     Octstr *s;
     FILE *fp;
     char buf[4096];

     if (script == NULL || octstr_len(script) == 0)
	  return 0;
     
     s = octstr_format("%s '%s' '%s' '%s'",
		       octstr_get_cstr(script), octstr_get_cstr(phonenum) ,
		       src_int ? src_int : "", src_id ? src_id : "");
     fp = popen(octstr_get_cstr(s), "r");
     octstr_destroy(s);

     fgets(buf, sizeof buf, fp);
     s = octstr_create(buf);
     octstr_strip_crlfs(s);

     pclose(fp);
     
     if (octstr_len(s) == 0) {
        octstr_destroy(s);
        return NULL;
     }

     return s;
}
コード例 #3
0
ファイル: test_octstr_dump.c プロジェクト: gburiticato/kannel
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;
}
コード例 #4
0
ファイル: parse.c プロジェクト: Phonebooth/kannel
Octstr *parse_get_line(ParseContext *context)
{
    Octstr *result;
    long pos;

    gw_assert(context != NULL);

    pos = octstr_search_char(context->data, '\n', context->pos);
    if (pos < 0 || pos >= context->limit) {
        context->error = 1;
        return NULL;
    }
    
    result = octstr_copy(context->data, context->pos, pos - context->pos);
    context->pos = pos + 1;

    octstr_strip_crlfs(result);

    return result;
}