Esempio n. 1
0
static int remove_long(long *p, Octstr *os)
{
    long pos;
    
    pos = octstr_parse_long(p, os, 0, 10);
    if (pos == -1)
    	return -1;
    octstr_delete(os, 0, pos);
    return 0;
}
Esempio n. 2
0
int mms_cfg_get_int(mCfg *cfg, mCfgGrp *grp, Octstr *name, long *n)
{
     Octstr *val = mms_cfg_get(cfg, grp, name);
     int ret;
     if (!val)
	  return -1;     
     ret = octstr_parse_long(n, val, 0, 0);
     octstr_destroy(val);
     return (ret == -1)  ? -1 : 0;
}
Esempio n. 3
0
static long eat_number(Octstr *ostr) {
	long result;
	long pos;

	pos = octstr_parse_long(&result, ostr, 0, 10);
	if (pos < 0)
		return INT_MIN;

	octstr_delete(ostr, 0, pos);
	return result;
}
Esempio n. 4
0
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
{
    Octstr *os;
    int ret;
    
    os = cfg_get(grp, varname);
    if (os == NULL)
    	return -1;
    if (octstr_parse_long(n, os, 0, 0) == -1)
    	ret = -1;
    else
    	ret = 0;
    octstr_destroy(os);
    return ret;
}
Esempio n. 5
0
File: date.c Progetto: frese/mbuni
int date_parse_iso (struct universaltime *ut, Octstr *os)
{
    long pos = 0;
    int c;

    /* assign defaults */
    ut->month = 0;
    ut->day = 1;
    ut->hour = 0;
    ut->minute = 0;
    ut->second = 0;

    if ((pos = octstr_parse_long(&(ut->year), os, pos, 10)) < 0)
        return -1;
    if (ut->year < 70)
        ut->year += 2000;
    else if (ut->year < 100)
	ut->year += 1900;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
	pos++;
    if ((pos = octstr_parse_long(&(ut->month), os, pos, 10)) < 0)
	return 0;

    /* 0-based months */
    if (ut->month > 0)
        ut->month--;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->day), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->hour), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->minute), os, pos, 10)) < 0)
	return 0;

    while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
        pos++;
    if ((pos = octstr_parse_long(&(ut->second), os, pos, 10)) < 0)
	return 0;

    return 0;
}
Esempio n. 6
0
Octstr *parse_date(Octstr *date)
{
    long date_value;

    if (octstr_get_char(date, 4) != '-')
        goto error;
    if (octstr_get_char(date, 7) != '-')
        goto error;
    if (octstr_get_char(date, 10) != 'T')
        goto error;
    if (octstr_get_char(date, 13) != ':')
        goto error;
    if (octstr_get_char(date, 16) != ':')
        goto error;
    if (octstr_get_char(date, 19) != 'Z')
        goto error;

    if (octstr_parse_long(&date_value, date, 0, 10) < 0)
        goto error;
    if (octstr_parse_long(&date_value, date, 5, 10) < 0)
        goto error;
    if (date_value < 1 || date_value > 12)
        goto error;
    if (octstr_parse_long(&date_value, date, 8, 10) < 0)
        goto error;
    if (date_value < 1 || date_value > 31)
        goto error;
    if (octstr_parse_long(&date_value, date, 11, 10) < 0)
        goto error;
    if (date_value < 0 || date_value > 23)
        goto error;
    if (octstr_parse_long(&date_value, date, 14, 10) < 0)
        goto error;
    if (date_value < 0 || date_value > 59)
        goto error;
    if (date_value < 0 || date_value > 59)
        goto error;
    if (octstr_parse_long(&date_value, date, 17, 10) < 0)
        goto error;

    return date;

error:
    warning(0, "parse_date: not an ISO date");
    return NULL;
}
Esempio n. 7
0
File: smsc.c Progetto: sivirk/kannel
SMSCenter *smsc_open(CfgGroup *grp)
{
    SMSCenter *smsc;
    Octstr *type, *host, *username, *password, *phone, *device;
    Octstr *preferred_prefix, *allowed_prefix, *denied_prefix;
    Octstr *alt_chars, *allow_ip;
    Octstr *sema_smscnua, *sema_homenua, *sema_report;
    Octstr *sender_prefix;

    long iwaitreport;
    long port, receive_port, our_port;
    long keepalive;
    long ois_debug;
    long alt_dcs;
    int typeno;


    type = cfg_get(grp, octstr_imm("smsc"));
    if (type == NULL) {
	error(0, "Required field 'smsc' missing for smsc group.");
	return NULL;
    }
    if (octstr_compare(type, octstr_imm("cimd")) == 0)
    	typeno = SMSC_TYPE_CIMD;
    else if (octstr_compare(type, octstr_imm("emi_x25")) == 0)
    	typeno = SMSC_TYPE_EMI_X25;
    else if (octstr_compare(type, octstr_imm("sema")) == 0)
    	typeno = SMSC_TYPE_SEMA_X28;
    else if (octstr_compare(type, octstr_imm("ois")) == 0)
    	typeno = SMSC_TYPE_OIS;
    else {
	error(0, "Unknown SMSC type '%s'", octstr_get_cstr(type));
	octstr_destroy(type);
	return NULL;
    }

    host = cfg_get(grp, octstr_imm("host"));
    if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1)
    	port = 0;
    if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1)
    	receive_port = 0;
    if (cfg_get_integer(&our_port, grp, octstr_imm("our-port")) == -1)
    	our_port = 0;
    username = cfg_get(grp, octstr_imm("smsc-username"));
    password = cfg_get(grp, octstr_imm("smsc-password"));
    phone = cfg_get(grp, octstr_imm("phone"));
    device = cfg_get(grp, octstr_imm("device"));
    preferred_prefix = cfg_get(grp, octstr_imm("preferred-prefix"));
    allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix"));
    denied_prefix = cfg_get(grp, octstr_imm("denied-prefix"));
    alt_chars = cfg_get(grp, octstr_imm("alt-charset"));

    allow_ip = cfg_get(grp, octstr_imm("connect-allow-ip"));

    sema_smscnua = cfg_get(grp, octstr_imm("smsc_nua"));
    sema_homenua = cfg_get(grp, octstr_imm("home_nua"));
    sema_report = cfg_get(grp, octstr_imm("wait_report"));
    if (sema_report == NULL)
    	iwaitreport = 1;
    else
    	octstr_parse_long(&iwaitreport, sema_report, 0, 0);

    if (cfg_get_integer(&keepalive, grp, octstr_imm("keepalive")) == -1)
    	keepalive = 0;

    if (cfg_get_integer(&alt_dcs, grp, octstr_imm("alt-dcs")) == -1)
    	alt_dcs = 0;
    if (alt_dcs > 1)
        alt_dcs = 1;

    if (cfg_get_integer(&ois_debug, grp, octstr_imm("ois-debug-level")) == -1)
    	ois_debug = 0;

    sender_prefix = cfg_get(grp, octstr_imm("sender-prefix"));
    if (sender_prefix == NULL)
        sender_prefix = octstr_create("never");

    smsc = NULL;

    switch (typeno) {
    case SMSC_TYPE_CIMD:
        if (host == NULL || port == 0 || username == NULL || password == NULL)
            error(0, "Required field missing for CIMD center.");
        else
            smsc = cimd_open(octstr_get_cstr(host),
	    	    	     port, 
	    	    	     octstr_get_cstr(username), 
			     octstr_get_cstr(password));
        break;

    case SMSC_TYPE_EMI_X25:
        if (phone == NULL || device == NULL || username == NULL ||
            password == NULL)
            error(0, "Required field missing for EMI_X25 center.");
        else
            smsc = emi_open(octstr_get_cstr(phone), 
	    	    	    octstr_get_cstr(device), 
			    octstr_get_cstr(username), 
			    octstr_get_cstr(password));
        break;

    case SMSC_TYPE_SEMA_X28:
        if (device == NULL || sema_smscnua == NULL || sema_homenua == NULL)
            error(0, "Required field missing for SEMA center.");
        else
            smsc = sema_open(octstr_get_cstr(sema_smscnua), 
	    	    	     octstr_get_cstr(sema_homenua), 
			     octstr_get_cstr(device),
                             iwaitreport);
        break;

    case SMSC_TYPE_OIS:
        if (host == NULL || port == 0 || receive_port == 0)
            error(0, "Required field missing for OIS center.");
        else
            smsc = ois_open(receive_port, 
	    	    	    octstr_get_cstr(host), 
			    port, 
	    	    	    ois_debug);
        break;

        /* add new SMSCes here */

    default: 		/* Unknown SMSC type */
        break;
    }

    if (smsc != NULL) {
	if (cfg_get_integer(&smsc->alt_charset, grp, 
	    	    	    octstr_imm("alt-charset")) == -1)
	    smsc->alt_charset = 0;
    	if (preferred_prefix == NULL)
	    smsc->preferred_prefix = NULL;
	else
	    smsc->preferred_prefix = 
	    	gw_strdup(octstr_get_cstr(preferred_prefix));
    	if (allowed_prefix == NULL)
	    smsc->allowed_prefix = NULL;
	else
	    smsc->allowed_prefix = gw_strdup(octstr_get_cstr(allowed_prefix));
    	if (denied_prefix == NULL)
	    smsc->denied_prefix = NULL;
	else
	    smsc->denied_prefix = gw_strdup(octstr_get_cstr(denied_prefix));
    }

    octstr_destroy(type);
    octstr_destroy(host);
    octstr_destroy(username);
    octstr_destroy(password);
    octstr_destroy(phone);
    octstr_destroy(device);
    octstr_destroy(preferred_prefix);
    octstr_destroy(denied_prefix);
    octstr_destroy(allowed_prefix);
    octstr_destroy(alt_chars);
    octstr_destroy(allow_ip);
    octstr_destroy(sema_smscnua);
    octstr_destroy(sema_homenua);
    octstr_destroy(sema_report);
    octstr_destroy(sender_prefix);
    return smsc;
}
Esempio n. 8
0
long date_parse_http(Octstr *date)
{
    long pos;
    struct universaltime t;
    Octstr *monthstr = NULL;

    /* First, skip the leading day-of-week string. */
    pos = octstr_search_char(date, ' ', 0);
    if (pos < 0 || pos == octstr_len(date) - 1)
        return -1;
    pos++;  /* Skip the space */

    /* Distinguish between the three acceptable formats */
    if (isdigit(octstr_get_char(date, pos)) &&
        octstr_get_char(date, pos + 2) == ' ') {
        if (octstr_len(date) - pos < (long)strlen("06 Nov 1994 08:49:37 GMT"))
            goto error;
        if (octstr_parse_long(&t.day, date, pos, 10) != pos + 2)
            goto error;
        monthstr = octstr_copy(date, pos + 3, 3);
        if (octstr_parse_long(&t.year, date, pos + 7, 10) != pos + 11)
            goto error;
        if (octstr_parse_long(&t.hour, date, pos + 12, 10) != pos + 14)
            goto error;
        if (octstr_parse_long(&t.minute, date, pos + 15, 10) != pos + 17)
            goto error;
        if (octstr_parse_long(&t.second, date, pos + 18, 10) != pos + 20)
            goto error;
        /* Take the GMT part on faith. */
    } else if (isdigit(octstr_get_char(date, pos)) &&
               octstr_get_char(date, pos + 2) == '-') {
        if (octstr_len(date) - pos < (long)strlen("06-Nov-94 08:49:37 GMT"))
            goto error;
        if (octstr_parse_long(&t.day, date, pos, 10) != pos + 2)
            goto error;
        monthstr = octstr_copy(date, pos + 3, 3);
        if (octstr_parse_long(&t.year, date, pos + 7, 10) != pos + 9)
            goto error;
        if (t.year > 60)
            t.year += 1900;
        else
            t.year += 2000;
        if (octstr_parse_long(&t.hour, date, pos + 10, 10) != pos + 12)
            goto error;
        if (octstr_parse_long(&t.minute, date, pos + 13, 10) != pos + 15)
            goto error;
        if (octstr_parse_long(&t.second, date, pos + 16, 10) != pos + 18)
            goto error;
        /* Take the GMT part on faith. */
    } else {
        if (octstr_len(date) - pos < (long)strlen(" 6 08:49:37 1994"))
            goto error;
        monthstr = octstr_copy(date, pos, 3);
        if (octstr_parse_long(&t.day, date, pos + 4, 10) != pos + 6)
            goto error;
        if (octstr_parse_long(&t.hour, date, pos + 7, 10) != pos + 9)
            goto error;
        if (octstr_parse_long(&t.minute, date, pos + 10, 10) != pos + 12)
            goto error;
        if (octstr_parse_long(&t.second, date, pos + 13, 10) != pos + 15)
            goto error;
        if (octstr_parse_long(&t.year, date, pos + 16, 10) != pos + 20)
            goto error;
    }

    for (t.month = 0; t.month < 12; t.month++) {
        if (octstr_str_compare(monthstr, monthname[t.month]) == 0)
            break;
    }
    if (t.month == 12)
        goto error;

    octstr_destroy(monthstr);
    return date_convert_universal(&t);

error:
    octstr_destroy(monthstr);
    return -1;
}
Esempio n. 9
0
int main(int argc, char **argv)
{
    output_t outputti = NORMAL_OUT;
    FILE *fp = NULL;
    Octstr *output = NULL;
    Octstr *filename = NULL;
    Octstr *wml_text = NULL;
    Octstr *charset = NULL;
    Octstr *wml_binary = NULL;
    int i, ret = 0, opt, file = 0, zero = 0, numstatus = 0, wml_strict = 1;
    long num = 0;

    /* You can give an wml text file as an argument './wml_tester main.wml' */

    gwlib_init();

    while ((opt = getopt(argc, argv, "hsbzrn:f:c:")) != EOF) {
        switch (opt) {
        case 'h':
            help();
            exit(0);
        case 's':
            if (outputti == NORMAL_OUT)
                outputti = SOURCE_OUT;
            else {
                help();
                exit(0);
            }
            break;
        case 'b':
            if (outputti == NORMAL_OUT)
                outputti = BINARY_OUT;
            else {
                help();
                exit(0);
            }
            break;
        case 'z':
            zero = 1;
            break;
        case 'r':
            wml_strict = 0;
            break;
        case 'n':
            numstatus = octstr_parse_long(&num, octstr_imm(optarg), 0, 0);
            if (numstatus == -1) {
                /* Error in the octstr_parse_long */
                error(num, "Error in the handling of argument to option n");
                help();
                panic(0, "Stopping.");
            }
            break;
        case 'f':
            file = 1;
            filename = octstr_create(optarg);
            fp = fopen(optarg, "a");
            if (fp == NULL)
                panic(0, "Couldn't open output file.");
            break;
        case 'c':
            charset = octstr_create(optarg);
            break;
        case '?':
        default:
            error(0, "Invalid option %c", opt);
            help();
            panic(0, "Stopping.");
        }
    }

    if (optind >= argc) {
        error(0, "Missing arguments.");
        help();
        panic(0, "Stopping.");
    }

    if (outputti == BINARY_OUT)
        log_set_output_level(GW_PANIC);
    wml_init(wml_strict);

    while (optind < argc) {
        wml_text = octstr_read_file(argv[optind]);
        if (wml_text == NULL)
            panic(0, "Couldn't read WML source file.");

        if (zero)
            set_zero(wml_text);

        for (i = 0; i <= num; i++) {
            ret = wml_compile(wml_text, charset, &wml_binary, NULL);
            if (i < num)
                octstr_destroy(wml_binary);
        }
        optind++;

        output = octstr_format("wml_compile returned: %d\n\n", ret);

        if (ret == 0) {
            if (fp == NULL)
                fp = stdout;

            if (outputti != BINARY_OUT) {
                if (outputti == SOURCE_OUT) {
                    octstr_insert(output, wml_text, octstr_len(output));
                    octstr_append_char(output, '\n');
                }

                octstr_append(output, octstr_imm(
                                  "Here's the binary output: \n\n"));
                octstr_print(fp, output);
            }

            if (file && outputti != BINARY_OUT) {
                fclose(fp);
                log_open(octstr_get_cstr(filename), 0, GW_NON_EXCL);
                octstr_dump(wml_binary, 0);
                log_close_all();
                fp = fopen(octstr_get_cstr(filename), "a");
            } else if (outputti != BINARY_OUT)
                octstr_dump(wml_binary, 0);
            else
                octstr_print(fp, wml_binary);

            if (outputti != BINARY_OUT) {
                octstr_destroy(output);
                output = octstr_format("\n And as a text: \n\n");
                octstr_print(fp, output);

                octstr_pretty_print(fp, wml_binary);
                octstr_destroy(output);
                output = octstr_format("\n\n");
                octstr_print(fp, output);
            }
        }

        octstr_destroy(wml_text);
        octstr_destroy(output);
        octstr_destroy(wml_binary);
    }

    if (file) {
        fclose(fp);
        octstr_destroy(filename);
    }

    if (charset != NULL)
        octstr_destroy(charset);

    wml_shutdown();
    gwlib_shutdown();

    return ret;
}
Esempio n. 10
0
/* Convert an HTML entity into a single character and advance `*html' past
   the entity. */
static void convert_html_entity(Octstr *sms, Octstr *html, long *pos)
{
    static struct {
        char *entity;
        int latin1;
    }
    tab[] = {
        { "&amp;", '&' },
        { "&lt;", '<' },
        { "&gt;", '>' },

        /* The following is copied from

        	http://www.hut.fi/~jkorpela/HTML3.2/latin1.html

           by Jukka Korpela. Hand and script edited to form this
           table. */

        { "&nbsp;", ' ' },
        { "&iexcl;", 161 },
        { "&cent;", 162 },
        { "&pound;", 163 },
        { "&curren;", 164 },
        { "&yen;", 165 },
        { "&brvbar;", 166 },
        { "&sect;", 167 },
        { "&uml;", 168 },
        { "&copy;", 169 },
        { "&ordf;", 170 },
        { "&laquo;", 171 },
        { "&not;", 172 },
        { "&shy;", 173 },
        { "&reg;", 174 },
        { "&macr;", 175 },
        { "&deg;", 176 },
        { "&plusmn;", 177 },
        { "&sup2;", 178 },
        { "&sup3;", 179 },
        { "&acute;", 180 },
        { "&micro;", 181 },
        { "&para;", 182 },
        { "&middot;", 183 },
        { "&cedil;", 184 },
        { "&sup1;", 185 },
        { "&ordm;", 186 },
        { "&raquo;", 187 },
        { "&frac14;", 188 },
        { "&frac12;", 189 },
        { "&frac34;", 190 },
        { "&iquest;", 191 },
        { "&Agrave;", 192 },
        { "&Aacute;", 193 },
        { "&Acirc;", 194 },
        { "&Atilde;", 195 },
        { "&Auml;", 196 },
        { "&Aring;", 197 },
        { "&AElig;", 198 },
        { "&Ccedil;", 199 },
        { "&Egrave;", 200 },
        { "&Eacute;", 201 },
        { "&Ecirc;", 202 },
        { "&Euml;", 203 },
        { "&Igrave;", 204 },
        { "&Iacute;", 205 },
        { "&Icirc;", 206 },
        { "&Iuml;", 207 },
        { "&ETH;", 208 },
        { "&Ntilde;", 209 },
        { "&Ograve;", 210 },
        { "&Oacute;", 211 },
        { "&Ocirc;", 212 },
        { "&Otilde;", 213 },
        { "&Ouml;", 214 },
        { "&times;", 215 },
        { "&Oslash;", 216 },
        { "&Ugrave;", 217 },
        { "&Uacute;", 218 },
        { "&Ucirc;", 219 },
        { "&Uuml;", 220 },
        { "&Yacute;", 221 },
        { "&THORN;", 222 },
        { "&szlig;", 223 },
        { "&agrave;", 224 },
        { "&aacute;", 225 },
        { "&acirc;", 226 },
        { "&atilde;", 227 },
        { "&auml;", 228 },
        { "&aring;", 229 },
        { "&aelig;", 230 },
        { "&ccedil;", 231 },
        { "&egrave;", 232 },
        { "&eacute;", 233 },
        { "&ecirc;", 234 },
        { "&euml;", 235 },
        { "&igrave;", 236 },
        { "&iacute;", 237 },
        { "&icirc;", 238 },
        { "&iuml;", 239 },
        { "&eth;", 240 },
        { "&ntilde;", 241 },
        { "&ograve;", 242 },
        { "&oacute;", 243 },
        { "&ocirc;", 244 },
        { "&otilde;", 245 },
        { "&ouml;", 246 },
        { "&divide;", 247 },
        { "&oslash;", 248 },
        { "&ugrave;", 249 },
        { "&uacute;", 250 },
        { "&ucirc;", 251 },
        { "&uuml;", 252 },
        { "&yacute;", 253 },
        { "&thorn;", 254 },
        { "&yuml;", 255 },
    };
    int num_tab = sizeof(tab) / sizeof(tab[0]);
    long i, code;
    size_t len;
    char buf[1024];

    if (octstr_get_char(html, *pos + 1) == '#') {
        if (octstr_get_char(html, *pos + 2) == 'x' || octstr_get_char(html, *pos + 2) == 'X')
            i = octstr_parse_long(&code, html, *pos + 3, 16); /* hex */
        else
            i = octstr_parse_long(&code, html, *pos + 2, 10); /* decimal */
        if (i > 0) {
            if (code < 256)
                octstr_append_char(sms, code);
            *pos = i + 1;
            if (octstr_get_char(html, *pos) == ';')
                ++(*pos);
        } else {
            ++(*pos);
            octstr_append_char(sms, '&');
        }
    } else {
        for (i = 0; i < num_tab; ++i) {
            len = strlen(tab[i].entity);
            octstr_get_many_chars(buf, html, *pos, len);
            buf[len] = '\0';
            if (strcmp(buf, tab[i].entity) == 0) {
                *pos += len;
                octstr_append_char(sms, tab[i].latin1);
                break;
            }
        }
        if (i == num_tab) {
            ++(*pos);
            octstr_append_char(sms, '&');
        }
    }
}
Esempio n. 11
0
static Cfg *init_bearerbox(Cfg *cfg)
{
    CfgGroup *grp;
    Octstr *log, *val;
    long loglevel, store_dump_freq, value;
    int lf, m;
#ifdef HAVE_LIBSSL
    Octstr *ssl_server_cert_file;
    Octstr *ssl_server_key_file;
    int ssl_enabled = 0;
#endif /* HAVE_LIBSSL */
    Octstr *http_proxy_host = NULL;
    long http_proxy_port = -1;
    int http_proxy_ssl = 0;
    List *http_proxy_exceptions = NULL;
    Octstr *http_proxy_username = NULL;
    Octstr *http_proxy_password = NULL;
    Octstr *http_proxy_exceptions_regex = NULL;

    /* defaults: use localtime and markers for access-log */
    lf = m = 1;
	
    grp = cfg_get_single_group(cfg, octstr_imm("core"));

    log = cfg_get(grp, octstr_imm("log-file"));
    if (log != NULL) {
        if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1)
            loglevel = 0;
        log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL);
        octstr_destroy(log);
    }
    if ((val = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) {
        long level;
        Octstr *facility;
        if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) {
            log_set_syslog_facility(octstr_get_cstr(facility));
            octstr_destroy(facility);
        }
        if (octstr_compare(val, octstr_imm("none")) == 0) {
            log_set_syslog(NULL, 0);
        } else if (octstr_parse_long(&level, val, 0, 10) > 0) {
            log_set_syslog("bearerbox", level);
        }
        octstr_destroy(val);
    } else {
        log_set_syslog(NULL, 0);
    }

    if (check_config(cfg) == -1)
        panic(0, "Cannot start with corrupted configuration");

    /* determine which timezone we use for access logging */
    if ((log = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) {
        lf = (octstr_case_compare(log, octstr_imm("gmt")) == 0) ? 0 : 1;
        octstr_destroy(log);
    }

    /* should predefined markers be used, ie. prefixing timestamp */
    cfg_get_bool(&m, grp, octstr_imm("access-log-clean"));

    /* custom access-log format  */
    if ((log = cfg_get(grp, octstr_imm("access-log-format"))) != NULL) {
        bb_alog_init(log);
        octstr_destroy(log);
    }

    /* open access-log file */
    if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
        alog_open(octstr_get_cstr(log), lf, m ? 0 : 1);
        octstr_destroy(log);
    }

    if (cfg_get_integer(&store_dump_freq, grp,
                           octstr_imm("store-dump-freq")) == -1)
        store_dump_freq = -1;

    log = cfg_get(grp, octstr_imm("store-file"));
    /* initialize the store file */
    if (log != NULL) {
        warning(0, "'store-file' option deprecated, please use 'store-location' and 'store-type' instead.");
        val = octstr_create("file");
    } else {
        log = cfg_get(grp, octstr_imm("store-location"));
        val = cfg_get(grp, octstr_imm("store-type"));
    }
    if (store_init(val, log, store_dump_freq, msg_pack, msg_unpack_wrapper) == -1)
        panic(0, "Could not start with store init failed.");
    octstr_destroy(val);
    octstr_destroy(log);

    cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port"));
#ifdef HAVE_LIBSSL
    cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl"));
#endif /* HAVE_LIBSSL */

    http_proxy_host = cfg_get(grp, 
    	    	    	octstr_imm("http-proxy-host"));
    http_proxy_username = cfg_get(grp, 
    	    	    	    octstr_imm("http-proxy-username"));
    http_proxy_password = cfg_get(grp, 
    	    	    	    octstr_imm("http-proxy-password"));
    http_proxy_exceptions = cfg_get_list(grp,
    	    	    	    octstr_imm("http-proxy-exceptions"));
    http_proxy_exceptions_regex = cfg_get(grp,
    	    	    	    octstr_imm("http-proxy-exceptions-regex"));

    conn_config_ssl (grp);

    /*
     * Make sure we have "ssl-server-cert-file" and "ssl-server-key-file" specified
     * in the core group since we need it to run SSL-enabled internal box 
     * connections configured via "smsbox-port-ssl = yes" and "wapbox-port-ssl = yes".
     * Check only these, because for "admin-port-ssl" and "sendsms-port-ssl" for the 
     * SSL-enabled HTTP servers are probed within gw/bb_http.c:httpadmin_start()
     */
#ifdef HAVE_LIBSSL
    ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file"));
    ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file"));
    if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) {
       /* we are fine, at least files are specified in the configuration */
    } else {
        cfg_get_bool(&ssl_enabled, grp, octstr_imm("smsbox-port-ssl"));
        cfg_get_bool(&ssl_enabled, grp, octstr_imm("wapbox-port-ssl"));
        if (ssl_enabled) {
	       panic(0, "You MUST specify cert and key files within core group for SSL-enabled inter-box connections!");
        }
    }
    octstr_destroy(ssl_server_cert_file);
    octstr_destroy(ssl_server_key_file);
#endif /* HAVE_LIBSSL */

    /* if all seems to be OK by the first glimpse, real start-up */

    outgoing_sms = gwlist_create();
    incoming_sms = gwlist_create();
    outgoing_wdp = gwlist_create();
    incoming_wdp = gwlist_create();

    outgoing_sms_counter = counter_create();
    incoming_sms_counter = counter_create();
    incoming_dlr_counter = counter_create();
    outgoing_dlr_counter = counter_create();
    outgoing_wdp_counter = counter_create();
    incoming_wdp_counter = counter_create();

    status_mutex = mutex_create();

    outgoing_sms_load = load_create();
    /* add 60,300,-1 entries */
    load_add_interval(outgoing_sms_load, 60);
    load_add_interval(outgoing_sms_load, 300);
    load_add_interval(outgoing_sms_load, -1);
    incoming_sms_load = load_create();
    /* add 60,300,-1 entries */
    load_add_interval(incoming_sms_load, 60);
    load_add_interval(incoming_sms_load, 300);
    load_add_interval(incoming_sms_load, -1);
    incoming_dlr_load = load_create();
    /* add 60,300,-1 entries to dlr */
    load_add_interval(incoming_dlr_load, 60);
    load_add_interval(incoming_dlr_load, 300);
    load_add_interval(incoming_dlr_load, -1);
    outgoing_dlr_load = load_create();
    /* add 60,300,-1 entries to dlr */
    load_add_interval(outgoing_dlr_load, 60);
    load_add_interval(outgoing_dlr_load, 300);
    load_add_interval(outgoing_dlr_load, -1);

    setup_signal_handlers();
    
    /* http-admin is REQUIRED */
    httpadmin_start(cfg);

    if (cfg_get_integer(&max_incoming_sms_qlength, grp,
                           octstr_imm("maximum-queue-length")) == -1)
        max_incoming_sms_qlength = -1;
    else {
        warning(0, "Option 'maximum-queue-length' is deprecated! Please use"
                          " 'sms-incoming-queue-limit' instead!");
    }

    if (max_incoming_sms_qlength == -1 &&
        cfg_get_integer(&max_incoming_sms_qlength, grp,
                                  octstr_imm("sms-incoming-queue-limit")) == -1)
        max_incoming_sms_qlength = -1;
        
    if (cfg_get_integer(&max_outgoing_sms_qlength, grp,
                                  octstr_imm("sms-outgoing-queue-limit")) == -1)
        max_outgoing_sms_qlength = -1;

    if (max_outgoing_sms_qlength < 0)
        max_outgoing_sms_qlength = DEFAULT_OUTGOING_SMS_QLENGTH;

    if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0)
        http_set_client_timeout(value);
#ifndef NO_SMS    
    {
        List *list;
	
        list = cfg_get_multi_group(cfg, octstr_imm("smsc"));
        if (list != NULL) {
           gwlist_destroy(list, NULL); 
           if (start_smsc(cfg) == -1) {
               panic(0, "Unable to start SMSCs.");
               return NULL;
           }
        }
    }
#endif
    
#ifndef NO_WAP
    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    val = cfg_get(grp, octstr_imm("wdp-interface-name"));
    if (val != NULL && octstr_len(val) > 0)
        start_udp(cfg);
    octstr_destroy(val);

    if (cfg_get_single_group(cfg, octstr_imm("wapbox")) != NULL)
        start_wap(cfg);
#endif

    if (http_proxy_host != NULL && http_proxy_port > 0) {
    	http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl,
		       http_proxy_exceptions, http_proxy_username,
                       http_proxy_password, http_proxy_exceptions_regex);
    }

    octstr_destroy(http_proxy_host);
    octstr_destroy(http_proxy_username);
    octstr_destroy(http_proxy_password);
    octstr_destroy(http_proxy_exceptions_regex);
    gwlist_destroy(http_proxy_exceptions, octstr_destroy_item);

    return cfg;
}
Esempio n. 12
0
static Cfg *init_wapbox(Cfg *cfg)
{
    CfgGroup *grp;
    Octstr *s;
    Octstr *logfile;
    int lf, m;
    long value;

    lf = m = 1;

    cfg_dump(cfg);
    
    /*
     * Extract info from the core group.
     */
    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    if (grp == NULL)
    	panic(0, "No 'core' group in configuration.");
    
    if (cfg_get_integer(&bearerbox_port,grp,octstr_imm("wapbox-port")) == -1)
        panic(0, "No 'wapbox-port' in core group");
#ifdef HAVE_LIBSSL
    cfg_get_bool(&bearerbox_ssl, grp, octstr_imm("wapbox-port-ssl"));
#endif /* HAVE_LIBSSL */
    
    /* load parameters that could be later reloaded */
    config_reload(0);
    
    conn_config_ssl(grp);

    /*
     * And the rest of the pull info comes from the wapbox group.
     */
    grp = cfg_get_single_group(cfg, octstr_imm("wapbox"));
    if (grp == NULL)
        panic(0, "No 'wapbox' group in configuration.");
    
    bearerbox_host = cfg_get(grp, octstr_imm("bearerbox-host"));
    if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1)
        timer_freq = DEFAULT_TIMER_FREQ;

    logfile = cfg_get(grp, octstr_imm("log-file"));
    if (logfile != NULL) {
        log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL);
        info(0, "Starting to log to file %s level %ld", 
             octstr_get_cstr(logfile), logfilelevel);
    }
    octstr_destroy(logfile);

    if ((s = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) {
        long level;
        Octstr *facility;
        if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) {
            log_set_syslog_facility(octstr_get_cstr(facility));
            octstr_destroy(facility);
        }
        if (octstr_compare(s, octstr_imm("none")) == 0) {
            log_set_syslog(NULL, 0);
            debug("wap", 0, "syslog parameter is none");
        } else if (octstr_parse_long(&level, s, 0, 10) > 0) {
            log_set_syslog("wapbox", level);
            debug("wap", 0, "syslog parameter is %ld", level);
        }
        octstr_destroy(s);
    } else {
        log_set_syslog(NULL, 0);
        debug("wap", 0, "no syslog parameter");
    }

    /* determine which timezone we use for access logging */
    if ((s = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) {
        lf = (octstr_case_compare(s, octstr_imm("gmt")) == 0) ? 0 : 1;
        octstr_destroy(s);
    }

    /* should predefined markers be used, ie. prefixing timestamp */
    cfg_get_bool(&m, grp, octstr_imm("access-log-clean"));

    /* open access-log file */
    if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
        info(0, "Logging accesses to '%s'.", octstr_get_cstr(s));
        alog_open(octstr_get_cstr(s), lf, m ? 0 : 1);
        octstr_destroy(s);
    }

    if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0)
       http_set_client_timeout(value);

    /* configure the 'wtls' group */
#if (HAVE_WTLS_OPENSSL)
    /* Load up the necessary keys */
    grp = cfg_get_single_group(cfg, octstr_imm("wtls"));
  
    if (grp != NULL) {
        if ((s = cfg_get(grp, octstr_imm("certificate-file"))) != NULL) {
            if (octstr_compare(s, octstr_imm("none")) == 0) {
                debug("bbox", 0, "certificate file not set");
            } else {
                /* Load the certificate into the necessary parameter */
                get_cert_from_file(s, &x509_cert);
                gw_assert(x509_cert != NULL);
                debug("bbox", 0, "certificate parameter is %s",
                   octstr_get_cstr(s));
            }
            octstr_destroy(s);
        } else
            panic(0, "No 'certificate-file' in wtls group");

        if ((s = cfg_get(grp, octstr_imm("privatekey-file"))) != NULL) {
            Octstr *password;
            password = cfg_get(grp, octstr_imm("privatekey-password"));
            if (octstr_compare(s, octstr_imm("none")) == 0) {
                debug("bbox", 0, "privatekey-file not set");
            } else {
                /* Load the private key into the necessary parameter */
                get_privkey_from_file(s, &private_key, password);
                gw_assert(private_key != NULL);
                debug("bbox", 0, "certificate parameter is %s",
                   octstr_get_cstr(s));
            }
            if (password != NULL)
                octstr_destroy(password);
            octstr_destroy(s);
        } else
            panic(0, "No 'privatekey-file' in wtls group");
    }
#endif

    /*
     * Check if we have a 'radius-acct' proxy group and start the
     * corresponding thread for the proxy.
     */
    grp = cfg_get_single_group(cfg, octstr_imm("radius-acct"));
    if (grp) {
        radius_acct_init(grp);
    }

    /*
     * We pass ppg configuration groups to the ppg module.
     */   
    grp = cfg_get_single_group(cfg, octstr_imm("ppg"));
    if (grp == NULL) { 
        cfg_destroy(cfg);
        return NULL;
    }

    return cfg;
}
Esempio n. 13
0
/******************************************************************************
 * This function handles incoming operations. Used by both receiver and sender
 * threads (i.e. sender thread uses this function for delivery and ack
 * operations).
 * Returns 1 if successfull, otherwise 0
 */
static int cgw_handle_op(SMSCConn *conn, Connection *server, struct cgwop *cgwop)
{
    PrivData *privdata = conn->data;
    Msg *msg = NULL;
    Octstr *from, *app, *sid, *to, *msgtype, *msgdata; /* for messages */
    Octstr *msid, *status, *txt;    		       /* delivery reports */
    Octstr *clid;    		       		       /* for acks */
    struct cgwop *reply = NULL;
    long trn, stat;                          /* transaction number for ack */
    Msg *dlrmsg = NULL, *origmsg = NULL;
    Octstr *ts;

    if (cgwop == NULL) return 0;

    from = cgwop_get(cgwop, octstr_imm("from"));
    app = cgwop_get(cgwop, octstr_imm("app"));
    sid = cgwop_get(cgwop, octstr_imm("session-id"));
    to = cgwop_get(cgwop, octstr_imm("to"));
    msgtype = cgwop_get(cgwop, octstr_imm("type"));
    msgdata = cgwop_get(cgwop, octstr_imm("msg"));
    txt = cgwop_get(cgwop, octstr_imm("txt"));

    msid = cgwop_get(cgwop, octstr_imm("msid"));
    status = cgwop_get(cgwop, octstr_imm("status"));
    clid = cgwop_get(cgwop, octstr_imm("client-id"));

    if (clid != NULL)
    {
        octstr_parse_long(&trn, clid, 0, 10);
        if ((trn < 0) || (trn >= CGW_TRN_MAX)) { /* invalid transaction number */
	    info(0, "cgw: Invalid transaction number: %d", (int) trn);
            trn = -1;            
	    return 0;
        }
    }

    switch (cgwop->op)
    {
    case CGW_OP_MSG:
        msg = msg_create(sms);
        time(&msg->sms.time);
        msg->sms.msgdata = cgw_decode_msg(octstr_duplicate(msgdata));
        msg->sms.sender = octstr_duplicate(from);
        msg->sms.receiver = octstr_duplicate(to);
        msg->sms.smsc_id = octstr_duplicate(conn->id);
        bb_smscconn_receive(conn, msg);

        reply = cgwop_create(CGW_OP_OK, -1);
        cgwop_add(reply, octstr_imm("session-id"), sid);
        cgwop_send(server, reply);     /* send reply */

        cgwop_destroy(reply);

        break;

    case CGW_OP_DELIVERY:
        if (privdata->dlr[trn]) {

            octstr_parse_long(&stat, status, 0, 10);
            origmsg = privdata->sendmsg[trn];

            if (origmsg == NULL) break;

            ts = octstr_create("");
            octstr_append(ts, conn->id);
            octstr_append_char(ts, '-');
            octstr_append_decimal(ts, trn);

            switch (stat) {
            case 0:     /* delivered */
                dlrmsg = dlr_find(conn->id,
                                            ts,     /* timestamp */
                                            msid,   /* destination */
                                  DLR_SUCCESS);
                break;
            case 1:     /* buffered */
                dlrmsg = dlr_find(conn->id,
                                            ts,     /* timestamp */
                                            msid,   /* destination */
                                  DLR_BUFFERED);
                break;
            case 2:     /* not delivered */
                dlrmsg = dlr_find(conn->id,
                                            ts,     /* timestamp */
                                            msid,   /* destination */
                                  DLR_FAIL);
                break;
            }

            octstr_destroy(ts);
            if (dlrmsg != NULL) {
                dlrmsg->sms.msgdata = octstr_duplicate(txt);
                bb_smscconn_receive(conn, dlrmsg);
            }
        }

        break;

    case CGW_OP_OK:
        if (trn == -1) break;     /* invalid transaction number */
        /* info(0, "cgw: Got ACK: %s", octstr_get_cstr(clid)); */

        privdata->sendtime[trn] = 0;
        privdata->unacked--;

        /* add delivery notification request if wanted */

        msg = privdata->sendmsg[trn];

        if (msg && msg->sms.dlr_url && DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask)) {
            Octstr *ts;

            ts = octstr_create("");
            octstr_append(ts, conn->id);
            octstr_append_char(ts, '-');
            octstr_append_decimal(ts, trn);

            dlr_add(conn->id, ts, msg);

            octstr_destroy(ts);
            privdata->dlr[trn] = 1;
        } else {
            privdata->dlr[trn] = 0;
        }

	/* mark as successfully sent */
        bb_smscconn_sent(conn, msg, NULL);

        break;

    case CGW_OP_STATUS:
        info(0, "CGW: Warning: Got session status");
        /* op:status messages are sent by ProviderServer to tell if there are problems with
           the session status. These are not wanted, and should never occur, as the delivery is
           cancelled, and no end-user billing is done. */

        break;


    case CGW_OP_HELLO:
        info(0, "CGW: Server said: %s", octstr_get_cstr(cgwop_get(cgwop, octstr_imm("hello"))));
        break;

    case CGW_OP_ERR:
        if (trn == -1) break;     /* invalid transaction number */

        info(0, "CGW: Received error: %s", octstr_get_cstr(txt));

        privdata->sendtime[trn] = 0;
        privdata->unacked--;

        bb_smscconn_send_failed(conn, privdata->sendmsg[trn],
                            SMSCCONN_FAILED_REJECTED, octstr_create("REJECTED"));

        break;

    default:
        info(0, "cgw: Unknown operation: %d", cgwop->op);
        return 0;
    }

    return 1;
}