Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    Octstr *os1, *os2;

    gwlib_init();
    
    os1 = octstr_create("");
    octstr_append_from_hex(os1, "411810124550421715161a");
    os2 = octstr_duplicate(os1);
    debug("", 0, "Orginal GSM charset data:");
    octstr_dump(os1, 0);        
    charset_gsm_to_utf8(os1);
    debug("", 0, "Same data mapped to URT-8 charset:");
    octstr_dump(os1, 0);  
    charset_utf8_to_gsm(os1);
    debug("", 0, "Same data mapped back again to GSM charset:");
    octstr_dump(os1, 0);  

    if (octstr_compare(os1, os2) != 0) 
        panic(0, "Data is not the same after re-mapping!");
    else
        debug("",0,"Data is same, ok.");

    octstr_destroy(os1);
    octstr_destroy(os2);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 2
0
int main(void) {
	Octstr *os, *os2, *os3, *os4;

	gwlib_init();

	os = octstr_format("hi, %% %-5.*s, <%*s>, %-5d + %05d = %d, -%5.2f",
			   3, "world", 3, "", 1, 2, 3, 3.1415927);
	octstr_dump(os, 0);
	
	os2 = octstr_format("<%S>", os);
	octstr_dump(os2, 0);
	
	octstr_format_append(os2, "yeehaa!");
	octstr_dump(os2, 0);
	
	os3 = octstr_format("NULL=%p &os=%p", (void *) NULL, (void *) &os);
	octstr_dump(os3, 0);
	
	os4 = octstr_format("Encode %E and limited %-10.10E", os, os);
	octstr_dump(os4, 0);

	octstr_destroy(os);
	octstr_destroy(os2);
	octstr_destroy(os3);
	
	gwlib_shutdown();
	
	return 0;
}
Ejemplo n.º 3
0
int main()
{    
    Octstr *os;    
    long i;    
    gw_prioqueue_t *queue;    
    
    gwlib_init();
    
    /* os = octstr_imm("iareanmsgotx"); */    
    os = octstr_imm("123456789");   

    queue = gw_prioqueue_create(my_cmp);    
    
    for (i=0; i < octstr_len(os); i++) {        
        char a[2];       
        a[0] = octstr_get_char(os, i);       
        a[1] = '\0';        
        gw_prioqueue_insert(queue, octstr_create(a));    
    }    
    
    gw_prioqueue_foreach(queue, my_dump);    
    while ((os = gw_prioqueue_remove(queue))) {        
        debug("", 0, "%s", octstr_get_cstr(os));        
        octstr_destroy(os);    
    }   
    
    debug("", 0, "gw_prioqueue_len=%ld", gw_prioqueue_len(queue));    
    
    gwlib_shutdown();    
    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    Cfg *cfg;
    int ret = 1;
    Octstr *name;
    int i;
    
    gwlib_init();

    for (i = 1; i < argc; ++i) {
        name = octstr_create(argv[i]);
        cfg = cfg_create(name);
        octstr_destroy(name);
        ret = cfg_read(cfg);
        info(0, "cfg_read returned %d", ret);
        if (ret == 0)
            cfg_dump(cfg);
        cfg_destroy(cfg);
    }
    
    info(0, "Shutting down.");
    gwlib_shutdown();

    return ret;
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
	Octstr *os1;
	Octstr *os2;
	time_t start, diff;

    gwlib_init();

    os1 = octstr_create(argv[1]);
    os2 = octstr_create(argv[2]);

    counter = counter_create();
    start = time(NULL);
    for_each_file(os1, 1, count_file);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);

#ifdef HAVE_NFTW
    counter_set(counter, 0);
    start = time(NULL);
    for_each_file2(os2, 1, count_file2);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);
#endif

    counter_destroy(counter);
    octstr_destroy(os1);
    octstr_destroy(os2);
    gwlib_shutdown();
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
    int cf_index;
    Octstr *type;
    
    gwlib_init();
    
    cf_index = get_and_set_debugs(argc, argv, check_args);
    
    if (argv[cf_index] == NULL) {
        debug("",0,"Usage: %s <store-file>", argv[0]);
        goto error;
    }

    type = octstr_create("file");
    
    /* init store subsystem */
    store_init(type, octstr_imm(argv[cf_index]), -1, msg_pack, msg_unpack_wrapper);

    /* pass every entry in the store to callback print_msg() */
    store_load(print_msg);

    info(0, "Store file contains %d msg entries", counter);
    info(0, "Shutting down.");
    
error:
    gwlib_shutdown();

    return 1;
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    Octstr *os;
    char id[UUID_STR_LEN + 1];
    uuid_t uid;

    gwlib_init();

    debug("uuid",0,"Creating UUID");
    uuid_generate(uid);
    debug("uuid",0,"Parse into char");
    uuid_unparse(uid, id);
    debug("uuid",0,"Create Octstr");
    os = octstr_create(id);
    debug("uuid",0,"UUID is: %s", octstr_get_cstr(os));
    debug("uuid",0,"Removing dashes");
    octstr_replace(os, octstr_imm("-"), octstr_imm(""));
    debug("uuid",0,"UUID is: %s", octstr_get_cstr(os));

    octstr_destroy(os);
    uuid_clear(uid);

    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
    Connection *conn;
    Octstr *host = NULL;
    int port, i;
    
    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

    host = octstr_create(argv[1]);    
    port = atoi(argv[2]);
    i = 50;
    
    debug("",0,"Connecting to host '%s', port %d, looping %i times.", 
          octstr_get_cstr(host), port, i);
    
    for (i = 0; i <= 50; i++) {
        conn = conn_open_tcp(host, port, NULL);
        if (conn == NULL) {
            panic(0, "Couldn't connect.");
        }
        debug("",0,"%d: connected.", i);
        gwthread_sleep(0.2);
        debug("",0,"%d: closing.", i);
        conn_destroy(conn);
    }

    octstr_destroy(host);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 9
0
int main(void)
{
    gwlib_init();
    log_set_output_level(GW_INFO);
    check_reversible();
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 10
0
int main(void)
{
    gwlib_init();
    log_set_output_level(GW_INFO);
    check_comparisons();
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 11
0
int main(void) {
	gwlib_init();
	log_set_output_level(GW_INFO);
	main_for_list_add_and_delete();
	main_for_extract();
	main_for_producer_and_consumer();
	gwlib_shutdown();
	return 0;
}
Ejemplo n.º 12
0
int main(int argc, char **argv) {
	int cf_index;
	Octstr *filename, *version;

	gwlib_init();
	list_dict = dict_create(32, msg_list_destroy_item);

	cf_index = get_and_set_debugs(argc, argv, check_args);
	setup_signal_handlers();

	if (argv[cf_index] == NULL)
		filename = octstr_create("httpClient.conf");
	else
		filename = octstr_create(argv[cf_index]);

	cfg = cfg_create(filename);

	/* Adding cfg-checks to core */
	cfg_add_hooks(smppbox_is_allowed_in_group, smppbox_is_single_group);

	if (cfg_read(cfg) == -1)
		panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename));

	octstr_destroy(filename);

	version = octstr_format("httpClient version %s gwlib", GW_VERSION);
	report_versions(octstr_get_cstr(version));
	octstr_destroy(version);

	struct server_type *res = NULL;
	res = sqlbox_init_mysql(cfg);
	sqlbox_configure_mysql(cfg);

	init_smpp_server_box(cfg);
	http_client_box_run();

	//gwthread_join_every(sql_to_smpp);
	//gwthread_join_every(smpp_to_sql);
	smpp_server_box_shutdown();

	dict_destroy(list_dict);
	list_dict = NULL;

	cfg_destroy(cfg);

	if (restart_httpbox) {
		gwthread_sleep(1.0);
	}

	gw_smpp_leave();
	gwlib_shutdown();

	if (restart_httpbox)
		execvp(argv[0], argv);
	return 0;
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    Octstr *data, *filename, *mac, *key;
    unsigned char macbuf[EVP_MAX_MD_SIZE], *p;
    int mac_len;
#ifdef HAVE_LIBSSL
    HMAC_CTX ctx;
#endif

    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

    if (argc < 3)
        panic(0, "Syntax: %s <key> <file>\n", argv[0]);
  
    key = octstr_create(argv[1]);    
    filename = octstr_create(argv[2]);
    data = octstr_read_file(octstr_get_cstr(filename));

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

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

#ifdef HAVE_LIBSSL
    HMAC_Init(&ctx, octstr_get_cstr(key), octstr_len(key), EVP_sha1());
    p = HMAC(EVP_sha1(), octstr_get_cstr(key), octstr_len(key), 
         octstr_get_cstr(data), octstr_len(data), 
         macbuf, &mac_len);
    HMAC_cleanup(&ctx);
#else
    macbuf[0] = 0;
    mac_len = 0;
    p = macbuf;
    warning(0, "No SSL support. Can't calculate HMAC value.");
#endif
    
    mac = octstr_create_from_data(p, mac_len);
    octstr_binary_to_hex(mac, 0);
    
    debug("",0,"HMAC of file `%s' and key `%s' is:", 
          octstr_get_cstr(filename), octstr_get_cstr(key));
    octstr_dump(mac, 0);      

    octstr_destroy(data);
    octstr_destroy(mac);
    octstr_destroy(key);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 14
0
int main(void) {
	Counter *c;
	long threads[THREADS];
	long i;
	
	gwlib_init();
	log_set_output_level(GW_INFO);
	c = counter_create();
	for (i = 0; i < THREADS; ++i)
		threads[i] = gwthread_create(check, c);
	for (i = 0; i < THREADS; ++i)
		gwthread_join(threads[i]);
	
	return 0;
}
Ejemplo n.º 15
0
int main(int argc, char **argv)
{
    int opt;

    gwlib_init();

    host = octstr_create("localhost");

    while ((opt = getopt(argc, argv, "v:h:p:c:")) != EOF) {
        switch (opt) {
            case 'v':
                log_set_output_level(atoi(optarg));
                break;

            case 'h':
                octstr_destroy(host);
                host = octstr_create(optarg);
                break;

            case 'p':
                port = atoi(optarg);
                break;

            case 'c':
                no_conn = atoi(optarg);
                break;

            case '?':
            default:
                error(0, "Invalid option %c", opt);
                help();
                panic(0, "Stopping.");
        }
    }

    if (!optind) {
        help();
        exit(0);
    }

    run_connects();

    octstr_destroy(host);

    gwlib_shutdown();

    return 0;
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
int main(int argc, char **argv) {
    int port;

    gwlib_init();

    if (argc != 3)
        panic(0, "Bad argument list\n%s", usage);

    port = atoi(argv[2]);

    if (strcmp(argv[1], "client") == 0)
        client(port);
    else
        server(port);
    return 0;
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
    Octstr *re, *os;
    pcre *regexp;
    int ovector[PCRE_OVECCOUNT];
    int rc;

    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

    os = octstr_create(argv[1]);
    re = octstr_create(argv[2]);

    info(0, "step 1: generic functions");

    /* compile */
    if ((regexp = gw_pcre_comp(re, 0)) == NULL)
        panic(0, "pcre compilation failed!");

    /* execute */
    rc = gw_pcre_exec(regexp, os, 0, 0, ovector, PCRE_OVECCOUNT);
    if (rc == PCRE_ERROR_NOMATCH) {
        info(0, "RE: pcre <%s> did not match on string <%s>.",
             octstr_get_cstr(re), octstr_get_cstr(os));
    } else if (rc < 0) {
        error(0, "RE: pcre <%s> execution failed with error %d.",
              octstr_get_cstr(re), rc);
    } else {
        info(0, "RE: pcre <%s> matches.", octstr_get_cstr(re));
    }
    
    info(0, "step 2: wrapper functions");

    debug("pcre",0,"RE: pcre_match <%s> on <%s> did: %s",
          octstr_get_cstr(re), octstr_get_cstr(os),
          gw_pcre_match(re, os) ? "match" : "NOT match");

    debug("pcre",0,"RE: pcre_match_pre on <%s> did: %s",
          octstr_get_cstr(os),
          gw_pcre_match_pre(regexp, os) ? "match" : "NOT match");

    octstr_destroy(re);
    octstr_destroy(os);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 19
0
int main(void)
{
    Dict *dict;
    Octstr *foo, *bar;
    unsigned long i;

    gwlib_init();

    foo = octstr_imm("foo");
    bar = octstr_imm("bar");

    debug("",0,"Dict simple test.");
    dict = dict_create(10, NULL);
    dict_put(dict, foo, bar);
    info(0, "foo gives %s", octstr_get_cstr(dict_get(dict, foo)));
    if (dict_key_count(dict) == 1)
        info(0, "there is but one foo.");
    else
        error(0, "key count is %ld, should be 1.", dict_key_count(dict));
    dict_destroy(dict);

    debug("",0,"Dict extended/huge test.");
    dict = dict_create(HUGE_SIZE, (void (*)(void *))octstr_destroy);
    for (i = 1; i <= HUGE_SIZE; i++) {
        unsigned long val;
        Octstr *okey, *oval;
        uuid_t id;
        char key[UUID_STR_LEN + 1];
        uuid_generate(id);
        uuid_unparse(id, key);
        val = gw_rand();
        okey = octstr_create(key);
        oval = octstr_format("%ld", val);
        dict_put(dict, okey, oval);
    }
    gwthread_sleep(5); /* give hash table some time */
    if (dict_key_count(dict) == HUGE_SIZE)
        info(0, "ok, got %d entries in the dictionary.", HUGE_SIZE);
    else
        error(0, "key count is %ld, should be %d.", dict_key_count(dict), HUGE_SIZE);
    dict_destroy(dict);

    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char **argv)
{
    int cf_index;
    Octstr *filename;

    gwlib_init();

    cf_index = get_and_set_debugs(argc, argv, check_args);
    setup_signal_handlers();

    if (argv[cf_index] == NULL) {
        filename = octstr_create("sqlbox.conf");
    } else {
        filename = octstr_create(argv[cf_index]);
    }

    cfg = cfg_create(filename);

    /* Adding cfg-checks to core */

    cfg_add_hooks(sqlbox_is_allowed_in_group, sqlbox_is_single_group);

    if (cfg_read(cfg) == -1)
        panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename));

    octstr_destroy(filename);

    report_versions("sqlbox");

    init_sqlbox(cfg);

    sqlboxc_run((void *)sqlbox_port);

    cfg_destroy(cfg);
    if (restart_sqlbox) {
        gwthread_sleep(1.0);
    }

    gw_sql_leave();
    gwlib_shutdown();

    if (restart_sqlbox)
        execvp(argv[0], argv);
    return 0;
}
Ejemplo n.º 21
0
int main(int argc, char **argv)
{
    Octstr *data, *enc;

    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

    data = octstr_create(argv[1]);
    enc = md5(data);

    debug("",0,"MD5 <%s>", octstr_get_cstr(enc));

    octstr_destroy(data);
    octstr_destroy(enc);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[]) {
	int i;
	int opt;

	gwlib_init();

	progname = argv[0];
	srandom(0);  /* Make "random" data reproducible */

	for (i = 1; i < argc; i++) {
		for (opt = 0; options[opt].option; opt++) {
			if (strcmp(argv[i], options[opt].option) == 0) {
				if (i + 1 >= argc) {
					fprintf(stderr, "%s: missing argument to %s",
						progname, argv[i]);
					exit(2);
				}
				if (options[opt].number) {
					* (int *) options[opt].location = atoi(argv[i+1]);
				} else {
					* (char **) options[opt].location = argv[i+1];
				}
				i++;
				break;
			}
		}
		if (options[opt].option)
			continue;
		if (strcmp(argv[i], "--help") == 0) {
			usage(stdout);
			exit(0);
		}
		if (argv[i][0] == '-') {
			fprintf(stderr, "%s: unknown option %s\n",
				progname, argv[i]);
			usage(stderr);
			exit(2);
		}
	}

	sockfd = wait_for_client(port);
	main_loop();
	return 0;
}
Ejemplo n.º 23
0
int main(void)
{
    Octstr *ip;
    Octstr *allowed;
    Octstr *denied;
    int result;
    int i;
    static struct {
	char *allowed;
	char *denied;
	char *ip;
	int should_be_allowed;
    } tab[] = {
	{ "127.0.0.1", "", "127.0.0.1", 1 },
	{ "127.0.0.1", "", "127.0.0.2", 1 },
	{ "127.0.0.1", "*.*.*.*", "127.0.0.1", 1 },
	{ "127.0.0.1", "*.*.*.*", "1.2.3.4", 0 },
	{ "127.0.0.1", "127.0.0.*", "1.2.3.4", 1 },
	{ "127.0.0.1", "127.0.0.*", "127.0.0.2", 0 },
    };
    
    gwlib_init();
    log_set_output_level(GW_INFO);
        
    for (i = 0; (size_t) i < sizeof(tab) / sizeof(tab[0]); ++i) {
	allowed = octstr_imm(tab[i].allowed);
	denied = octstr_imm(tab[i].denied);
	ip = octstr_imm(tab[i].ip);
	result = is_allowed_ip(allowed, denied, ip);
	if (!!result != !!tab[i].should_be_allowed) {
	    panic(0, "is_allowed_ip did not work for "
	    	     "allowed=<%s> denied=<%s> ip=<%s>, "
		     "returned %d should be %d",
		     octstr_get_cstr(allowed),
		     octstr_get_cstr(denied),
		     octstr_get_cstr(ip),
		     result,
		     tab[i].should_be_allowed);
	}
    }

    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 24
0
int main(int argc, char **argv)
{
    Octstr *data, *enc;

    gwlib_init();

    get_and_set_debugs(argc, argv, NULL);

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

    data = octstr_create(argv[1]);
    enc = md5(data);

    debug("",0,"MD5:");
    octstr_dump(enc, 0);

    octstr_destroy(enc);
    enc = md5digest(data);

    debug("",0,"MD5 (digest):");
    octstr_dump(enc, 0);

#ifdef HAVE_LIBSSL
    OpenSSL_add_all_digests();
    
    octstr_destroy(enc);
    enc = our_hash_func(data);

    debug("",0,"SHA1:");
    octstr_dump(enc, 0);

    octstr_binary_to_hex(enc, 0);
    debug("",0,"SHA1 (digest):");
    octstr_dump(enc, 0);
#endif

    octstr_destroy(data);
    octstr_destroy(enc);
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 25
0
int main(void)
{
    struct universaltime ut;
    Octstr *os;
    Octstr *buf;
    
    gwlib_init();
    buf = octstr_create("");
    while ((os = read_line(stdin, buf)) != NULL) {
	if (parse_date(&ut, os) == -1)
	    panic(0, "Bad line: %s", octstr_get_cstr(os));
	printf("%ld %s\n", date_convert_universal(&ut), octstr_get_cstr(os));
	octstr_destroy(os);
    }

    log_set_output_level(GW_PANIC);
    gwlib_shutdown();

    return 0;
}
Ejemplo n.º 26
0
static void remove_pid_file(void)
{
    if (!pid_file)
        return;

    /* ensure that only pidfile owner can remove it */
    if (pidfile_owner_pid != getpid())
        return;

    if (-1 == unlink(pid_file)) {
        int initdone = gwlib_initialized();
        /* we are called at exit so gwlib may be shutdown already, init again */
        if (!initdone) {
            gwlib_init();
            log_set_syslog("kannel", 0);
        }
        error(errno, "Could not unlink pid-file `%s'", pid_file);
        if (!initdone)
            gwlib_shutdown();
    }
}
Ejemplo n.º 27
0
int main(int argc, char **argv)
{
    Octstr *s;
    struct universaltime ut;
    
    gwlib_init();
    
    get_and_set_debugs(argc, argv, NULL);

    s = octstr_create("2009-02-10T10:02:03");
    if (date_parse_iso(&ut, s) == -1) {
        panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
    }
    info(0, "%s : %04ld-%02ld-%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
    octstr_destroy(s);

    s = octstr_create("2009-02-10");
    if (date_parse_iso(&ut, s) == -1) {
        panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
    }
    info(0, "%s : %04ld-%02ld-%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
    octstr_destroy(s);
    
    s = octstr_create("20090210T10:02:03");
    if (date_parse_iso(&ut, s) == -1) {
        panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
    }
    info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
    octstr_destroy(s);

    s = octstr_create("20090210");
    if (date_parse_iso(&ut, s) == -1) {
        panic(0, "date_parse_iso failed: %s", octstr_get_cstr(s));
    }
    info(0, "%s : %04ld%02ld%02ldT%02ld:%02ld:%02ld", octstr_get_cstr(s), ut.year, ut.month+1, ut.day, ut.hour, ut.minute, ut.second);
    octstr_destroy(s);
    
    gwlib_shutdown();
    return 0;
}
Ejemplo n.º 28
0
int main(void)
{
    List *list;
    char id[UUID_STR_LEN + 1];
    int i;
     
    gwlib_init();

    debug("",0,"List performance test.");
    list = gwlist_create();
        
    /* generate UUIDs and populate the list */
    debug("", 0, "Creating %d UUIDs for the list.", HUGE_SIZE);
    for (i = 0; i < HUGE_SIZE; i++) {
        Octstr *os;
        uuid_t uid;
        uuid_generate(uid);
        uuid_unparse(uid, id);
        os = octstr_create(id);
        gwlist_append(list, os);
        uuid_clear(uid);
    }
    debug("",0,"Objects in the list: %ld", gwlist_len(list));

    /* try to sort */
    debug("",0,"Sorting.");
    gwlist_sort(list, my_sort_cmp);
    debug("",0,"Sorting done.");
    for (i = 0; i < HUGE_SIZE; i++) {
        Octstr *os = gwlist_get(list, i);
        debug("",0,"After sort: %s %d", octstr_get_cstr(os), i);
    }       
    
    gwlist_destroy(list, octstr_destroy_item);

    gwlib_shutdown();
    return 0;
}
int main(int argc, char **argv) 
{
    Octstr *os;

    gwlib_init();
	
    if (optind >= argc) {
        os = octstr_imm("foo");
    } else {
        os = octstr_imm(argv[optind]);
    }

    /* 
     * Note: don't destroy this, check that the log file has no
     * memory leaks.
     */
	
    octstr_dump(os, 0);
	
    gwlib_shutdown();

    return 0;
}
Ejemplo n.º 30
0
int main(void) 
{
    Octstr *os, *os2, *os3, *os4, *os5;
    unsigned long long n = 18446744073709551615ull;

    gwlib_init();

    os = octstr_format("hi, %% %-5.*s, <%*s>, %-5d + %05d = %d, -%5.2f",
                       3, "world", 3, "", 1, 2, 3, 3.1415927);
    octstr_dump(os, 0);
	
    os2 = octstr_format("<%S>", os);
    octstr_dump(os2, 0);
	
    octstr_format_append(os2, "yeehaa!");
    octstr_dump(os2, 0);
	
    os3 = octstr_format("NULL=%p &os=%p", (void *) NULL, (void *) &os);
    octstr_dump(os3, 0);
	
    os4 = octstr_format("Encode %E and limited %-10.10E", os, os);
    octstr_dump(os4, 0);

    os5 = octstr_format("Encode %%llu: %llu", n);
    octstr_dump(os5, 0);

    octstr_destroy(os);
    octstr_destroy(os2);
    octstr_destroy(os3);
    octstr_destroy(os4);
    octstr_destroy(os5);
	
    gwlib_shutdown();
	
	return 0;
}