static Octstr *store_spool_status(int status_type) { Octstr *ret = octstr_create(""); const char *format; struct status data; /* check if we are active */ if (spool == NULL) return ret; /* set the type based header */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret, "<table border=1>\n" "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>" "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>" "</tr>\n"); format = "<tr><td>%s</td><td>%s</td>" "<td>%04d-%02d-%02d %02d:%02d:%02d</td>" "<td>%s</td><td>%s</td><td>%s</td>" "<td>%s</td><td>%s</td><td>%s</td></tr>\n"; } else if (status_type == BBSTATUS_XML) { format = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t" "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t" "<sender>%s</sender>\n\t" "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t" "<box-id>%s</box-id>\n\t" "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t" "</message>\n"; } else { octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n"); format = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n"; } data.format = format; data.status = ret; /* ignore error because files may disappear */ for_each_file(spool, 1, status_cb, &data); /* set the type based footer */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret,"</table>"); } return ret; }
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 *pgsql_open_conn(const DBConf *db_conf) { PGconn *conn = NULL; PgSQLConf *conf = db_conf->pgsql; /* make compiler happy */ Octstr *tmp, *cs; /* sanity check */ if (conf == NULL) return NULL; cs = octstr_create(""); add1(" host=%S", conf->host); /* TODO: add hostaddr support via 'host' directive too. * This needs an octstr_is_addr(Octstr *os) checking if a given string * contains a valid IPv4 address. Obviously parsing on our own via gwlib * functions or using regex. If found, insert hostaddr instead of host * for the connection string. */ /* add1(" hostaddr=%S", conf->host); */ if (conf->port > 0) { /* add only if user set a value */ octstr_append_cstr(cs, " port="); octstr_append_decimal(cs, conf->port); } add1(" user=%S", conf->username); add1(" password=%S", conf->password); add1(" dbname=%S", conf->database); #if 0 /* TODO: This is very bad to show password in the log file */ info(0, "PGSQL: Using connection string: %s.", octstr_get_cstr(cs)); #endif conn = PQconnectdb(octstr_get_cstr(cs)); octstr_destroy(cs); if (conn == NULL) goto failed; gw_assert(conn != NULL); if (PQstatus(conn) == CONNECTION_BAD) { error(0, "PGSQL: connection to database '%s' failed!", octstr_get_cstr(conf->database)); panic(0, "PGSQL: %s", PQerrorMessage(conn)); goto failed; } info(0, "PGSQL: Connected to server at '%s'.", octstr_get_cstr(conf->host)); return conn; failed: PQfinish(conn); return NULL; }
static void mime_entity_dump_real(MIMEEntity *m, unsigned int level) { long i, items; Octstr *prefix, *type, *charset; Octstr *tmp; unsigned int j; gw_assert(m != NULL && m->headers != NULL); prefix = octstr_create(""); for (j = 0; j < level * 2; j++) octstr_append_cstr(prefix, " "); http_header_get_content_type(m->headers, &type, &charset); debug("mime.dump",0,"%sContent-Type `%s'", octstr_get_cstr(prefix), octstr_get_cstr(type)); for(i = 0; i < gwlist_len(m->headers); i++) { tmp = gwlist_get(m->headers,i); debug("mime.dump",0, "Header: %s", octstr_get_cstr(tmp)); } if (m->start != NULL) { Octstr *cid = http_header_value(m->start->headers, octstr_imm("Content-ID")); debug("mime.dump",0,"%sRelated to Content-ID <%s> MIMEEntity at address `%p'", octstr_get_cstr(prefix), octstr_get_cstr(cid), m->start); octstr_destroy(cid); } items = gwlist_len(m->multiparts); debug("mime.dump",0,"%sBody contains %ld MIME entities, size %ld", octstr_get_cstr(prefix), items, (items == 0 && m->body) ? octstr_len(m->body) : -1); octstr_destroy(prefix); octstr_destroy(type); octstr_destroy(charset); for (i = 0; i < items; i++) { MIMEEntity *e = gwlist_get(m->multiparts, i); mime_entity_dump_real(e, level + 1); } }
Octstr *smasi_pdu_pack(SMASI_PDU *pdu) { Octstr *os; Octstr *temp; os = octstr_create(""); /* * Fix lengths of octet string fields. */ switch (pdu->type) { #define NONTERMINATED(name) p = *(&p); #define COMATERMINATED(name) p = *(&p); #define PDU(name, id, fields) \ case id: { struct name *p = &pdu->u.name; fields } break; #include "smasi_pdu.def" default: error(0, "Unknown SMASI_PDU type, internal error while packing."); } switch (pdu->type) { #define NONTERMINATED(name) p = *(&p); #define COMATERMINATED(name) \ if (p->name != NULL) { octstr_append_cstr(os, #name); \ octstr_append_char(os, '='); \ octstr_append(os, p->name); \ octstr_append_char(os, ','); } #define PDU(name, id, fields) \ case id: { struct name *p = &pdu->u.name; fields } break; #include "smasi_pdu.def" default: error(0, "Unknown SMASI_PDU type, internal error while packing."); } octstr_append_char(os, '\n'); temp = pdu->needs_hyphen ? octstr_create("!") : octstr_create(""); octstr_append_cstr(temp, pdu->type_name); octstr_append_char(temp, ':'); octstr_insert(os, temp, 0); octstr_destroy(temp); return os; }
/* Return a human-readable representation of this operation code */ static Octstr *operation_name(int operation) { int i; i = operation_find(operation); if (i >= 0) return octstr_create(operations[i].name); if (operation >= RESPONSE) { i = operation_find(operation - RESPONSE); if (i >= 0) { Octstr *name = octstr_create(operations[i].name); octstr_append_cstr(name, " response"); return name; } } /* Put the operation number here when we have octstr_format */ return octstr_create("(unknown)"); }
int operate_single_mime(Octstr *p_psoHdrs, MIMEEntity *p_psoMIME, const char *p_pszWebDir) { int iRetVal = 0; Octstr *psoHdrName = NULL, *psoHdrValue = NULL; Octstr *psoMIMEOStr = NULL, *psoFileName = NULL; List *psoHdrList = NULL; int iFile = -1; if(psoMIMEOStr) { octstr_destroy(psoMIMEOStr); } /* выбираем необходимые заголовки */ psoHdrList = mime_entity_headers(p_psoMIME); /* Content-type */ psoHdrName = octstr_create("Content-type"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); if(0 == strncasecmp("application/smil", octstr_get_cstr(psoHdrValue), 16)) { goto done; } octstr_format_append(p_psoHdrs, "\r\n"); octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* Content-location */ octstr_append_cstr(psoHdrName, "Content-location"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /**/ /* формируем имя файла */ psoFileName = octstr_create(p_pszWebDir); if('/' != octstr_get_char(psoFileName, octstr_len(psoFileName) - 1)) { octstr_append_char(psoFileName, '/'); } octstr_append(psoFileName, psoHdrValue); /* создаем файл */ iFile = open(octstr_get_cstr(psoFileName), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(0 > iFile) { if(errno != EEXIST) { iRetVal = 7; goto done; } } psoMIMEOStr = mime_entity_body(p_psoMIME); octstr_base64_to_binary(psoMIMEOStr); if(octstr_len(psoMIMEOStr) != write(iFile, octstr_get_cstr(psoMIMEOStr), octstr_len(psoMIMEOStr))) { iRetVal = 8; goto done; } done: if(psoHdrName) { octstr_destroy(psoHdrName); } if(psoFileName) { octstr_destroy(psoFileName); } if(0 < iFile) { close(iFile); } return iRetVal; }
/* * This routine is used for mime_[http|octstr]_to_entity() in order to * reduce code duplication. Basically the only difference is how the headers * are parsed or passed to the resulting MIMEEntity representation. */ static MIMEEntity *mime_something_to_entity(Octstr *mime, List *headers) { MIMEEntity *e; ParseContext *context; Octstr *value, *boundary, *start; int len = 0; debug("mime.parse",0,"mime_something_to_entity"); octstr_dump(mime,0); gw_assert(mime != NULL); value = boundary = start = NULL; context = parse_context_create(mime); e = mime_entity_create(); /* parse the headers up to the body. If we have headers already passed * from our caller, then duplicate them and continue */ if (headers != NULL) { /* we have some headers to duplicate, first ensure we destroy * the list from the previous creation inside mime_entity_create() */ http_destroy_headers(e->headers); e->headers = http_header_duplicate(headers); } else { /* parse the headers out of the mime block */ if ((read_mime_headers(context, e->headers) != 0) || e->headers == NULL) { debug("mime.parse",0,"Failed to read MIME headers in Octstr block:"); octstr_dump(mime, 0); mime_entity_destroy(e); parse_context_destroy(context); return NULL; } } /* * Now check if the body is a multipart. This is indicated by an 'boundary' * parameter in the 'Content-Type' value. If yes, call ourself for the * multipart entities after parsing them. */ value = http_header_value(e->headers, octstr_imm("Content-Type")); debug("mime.parse",0,"value: %s", octstr_get_cstr(value)); boundary = http_get_header_parameter(value, octstr_imm("boundary")); debug("mime.parse",0,"boundary: %s", octstr_get_cstr(boundary)); start = get_start_param(value); /* Beware that we need *unquoted* strings to compare against in the * following parsing sections. */ if (boundary && (len = octstr_len(boundary)) > 0 && octstr_get_char(boundary, 0) == '"' && octstr_get_char(boundary, len-1) == '"') { octstr_delete(boundary, 0, 1); octstr_delete(boundary, len-2, 1); } debug("mime.parse",0, "Boundrary is %s", octstr_get_cstr(boundary)); if (boundary != NULL) { /* we have a multipart block as body, parse the boundary blocks */ Octstr *entity, *seperator, *os; /* loop by all boundary blocks we have in the body */ seperator = octstr_create("--"); octstr_append(seperator, boundary); while ((entity = parse_get_seperated_block(context, seperator)) != NULL) { MIMEEntity *m; int del2 = 0; /* we have still linefeeds at the beginning and end that we * need to remove, these are from the separator. * We check if it is LF only or CRLF! */ del2 = (octstr_get_char(entity, 0) == '\r'); if (del2) octstr_delete(entity, 0, 2); else octstr_delete(entity, 0, 1); /* we assume the same mechanism applies to beginning and end -- * seems reasonable! */ if (del2) octstr_delete(entity, octstr_len(entity) - 2, 2); else octstr_delete(entity, octstr_len(entity) - 1, 1); debug("mime.parse",0,"MIME multipart: Parsing entity:"); octstr_dump(entity, 0); /* call ourself for this MIME entity and inject to list */ if ((m = mime_octstr_to_entity(entity))) { gwlist_append(e->multiparts, m); /* check if this entity is our start entity (in terms of related) * and set our start pointer to it */ if (cid_matches(m->headers, start)) { /* set only if none has been set before */ e->start = (e->start == NULL) ? m : e->start; } } octstr_destroy(entity); } /* ok, we parsed all blocks, we expect to see now the end boundary */ octstr_append_cstr(seperator, "--"); os = parse_get_line(context); if (os != NULL && octstr_compare(os, seperator) != 0) { debug("mime.parse",0,"Failed to see end boundary, parsed line is '%s'.", octstr_get_cstr(os)); } octstr_destroy(seperator); octstr_destroy(os); } else { /* we don't have boundaries, so this is no multipart block, * pass the body to the MIME entity. */ e->body = parse_get_rest(context); } parse_context_destroy(context); octstr_destroy(value); octstr_destroy(boundary); octstr_destroy(start); return e; }
Octstr *boxc_status(int status_type) { Octstr *tmp; char *lb, *ws; int i, boxes, para = 0; time_t orig, t; Boxc *bi; orig = time(NULL); /* * XXX: this will cause segmentation fault if this is called * between 'destroy_list and setting list to NULL calls. * Ok, this has to be fixed, but now I am too tired. */ if ((lb = bb_status_linebreak(status_type))==NULL) return octstr_create("Un-supported format"); if (status_type == BBSTATUS_HTML) ws = " "; else if (status_type == BBSTATUS_TEXT) ws = " "; else ws = ""; if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML) para = 1; if (status_type == BBSTATUS_XML) { tmp = octstr_create (""); octstr_append_cstr(tmp, "<boxes>\n\t"); } else tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb); boxes = 0; if (wapbox_list) { gwlist_lock(wapbox_list); for(i=0; i < gwlist_len(wapbox_list); i++) { bi = gwlist_get(wapbox_list, i); if (bi->alive == 0) continue; t = orig - bi->connect_time; if (status_type == BBSTATUS_XML) octstr_format_append(tmp, "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n" "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n" "\t\t<ssl>%s</ssl>\n\t</box>\n", octstr_get_cstr(bi->client_ip), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "yes" : "no" #else "not installed" #endif ); else octstr_format_append(tmp, "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s", ws, octstr_get_cstr(bi->client_ip), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "using SSL" : "", #else "", #endif lb); boxes++; } gwlist_unlock(wapbox_list); } if (smsbox_list) { gw_rwlock_rdlock(smsbox_list_rwlock); for(i=0; i < gwlist_len(smsbox_list); i++) { bi = gwlist_get(smsbox_list, i); if (bi->alive == 0) continue; t = orig - bi->connect_time; if (status_type == BBSTATUS_XML) octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n" "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n" "\t\t<queue>%ld</queue>\n" "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n" "\t\t<ssl>%s</ssl>\n\t</box>", (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""), octstr_get_cstr(bi->client_ip), gwlist_len(bi->incoming) + dict_key_count(bi->sent), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "yes" : "no" #else "not installed" #endif ); else octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s", ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"), octstr_get_cstr(bi->client_ip), gwlist_len(bi->incoming) + dict_key_count(bi->sent), t/3600/24, t/3600%24, t/60%60, t%60, #ifdef HAVE_LIBSSL conn_get_ssl(bi->conn) != NULL ? "using SSL" : "", #else "", #endif lb); boxes++; } gw_rwlock_unlock(smsbox_list_rwlock); } if (boxes == 0 && status_type != BBSTATUS_XML) { octstr_destroy(tmp); tmp = octstr_format("%sNo boxes connected", para ? "<p>" : ""); } if (para) octstr_append_cstr(tmp, "</p>"); if (status_type == BBSTATUS_XML) octstr_append_cstr(tmp, "</boxes>\n"); else octstr_append_cstr(tmp, "\n\n"); return tmp; }
static void do_mm1_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *msg) { List *pheaders; static unsigned char ct; /* Transaction counter -- do we need it? */ Octstr *to = NULL; Octstr *pduhdr = octstr_create(""); Octstr *s = NULL; if (!rcpt_to) { mms_error(0, "MM1", NULL, "mobilesender: Queue entry %s has no recipient address!", e->xqfname); goto done; } else to = octstr_duplicate(rcpt_to); ct++; octstr_append_char(pduhdr, ct); /* Pushd id */ octstr_append_char(pduhdr, 0x06); /* PUSH */ #if 1 octstr_append_char(pduhdr, 1 + 1 + 1); octstr_append_char(pduhdr, 0xbe); /* content type. */ #else octstr_append_char(pduhdr, 1 + 1 + strlen("application/vnd.wap.mms-message") + 1); /*header length. */ octstr_append_cstr(pduhdr, "application/vnd.wap.mms-message"); octstr_append_char(pduhdr, 0x0); /* string terminator. */ #endif octstr_append_char(pduhdr, 0xaf); /* push application ID header and value follows. */ octstr_append_char(pduhdr, 0x84); /* ... */ s = mms_tobinary(msg); if (isphonenum) { Octstr *url = octstr_format("%S&text=%E%E&to=%E&udh=%%06%%05%%04%%0B%%84%%23%%F0", settings->sendsms_url, pduhdr, s, to); int status; List *rph = NULL; Octstr *rbody = NULL; MmsEnvelopeTo *xto = gwlist_get(e->to, 0); pheaders = http_create_empty_headers(); http_header_add(pheaders, "Connection", "close"); http_header_add(pheaders, "User-Agent", MM_NAME "/" MMSC_VERSION); if ((status = mms_url_fetch_content(HTTP_METHOD_GET, url, pheaders, NULL, &rph, &rbody)) < 0 || http_status_class(status) != HTTP_STATUS_SUCCESSFUL) { mms_error(0, "MM1", NULL, " Push[%s] from %s, to %s, failed, HTTP code => %d", e->xqfname, octstr_get_cstr(e->from), octstr_get_cstr(to), status); e = update_env(e,xto,0); } else { /* Successful push. */ mms_log2("Notify", octstr_imm("system"), to, -1, e ? e->msgId : NULL, NULL, NULL, "MM1", NULL,NULL); e = update_env(e, xto, 1); } http_destroy_headers(pheaders); http_destroy_headers(rph); octstr_destroy(rbody); octstr_destroy(url); } else { /* An IP Address: Send packet, forget. */ Octstr *addr = udp_create_address(to, WAPPUSH_PORT); int sock = udp_client_socket(); MmsEnvelopeTo *xto = gwlist_get(e->to,0); if (sock > 0) { octstr_append(pduhdr, s); #if 0 octstr_dump(pduhdr, 0); #endif udp_sendto(sock, pduhdr, addr); close(sock); /* ?? */ mms_log2("Notify", octstr_imm("system"), to, -1, e ? e->msgId : NULL, NULL, NULL, "MM1", NULL,NULL); e = update_env(e, xto, 1); } else { e = update_env(e, xto, 0); mms_error(0, "MM1", NULL, "push to %s:%d failed: %s", octstr_get_cstr(to), WAPPUSH_PORT, strerror(errno)); } octstr_destroy(addr); } done: octstr_destroy(to); octstr_destroy(pduhdr); octstr_destroy(s); if (e) settings->qfs->mms_queue_free_env(e); }
static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg *msg) { List *pheaders; static unsigned char ct; /* Transaction counter -- do we need it? */ Octstr *to = NULL; Octstr *pduhdr = octstr_create(""); Octstr *s = NULL; info(0, "mms2mobile.startpush: notification to %s\n", octstr_get_cstr(rcpt_to)); if (!rcpt_to) { error(0, "mobilesender: Queue entry %s has no recipient address!", e->xqfname); goto done; } else to = octstr_duplicate(rcpt_to); ct++; octstr_append_char(pduhdr, ct); /* Pushd id */ octstr_append_char(pduhdr, 0x06); /* PUSH */ #if 1 octstr_append_char(pduhdr, 1 + 1 + 1); octstr_append_char(pduhdr, 0xbe); /* content type. */ #else octstr_append_char(pduhdr, 1 + 1 + sizeof "application/vnd.wap.mms-message"); /*header length. */ octstr_append_cstr(pduhdr, "application/vnd.wap.mms-message"); octstr_append_char(pduhdr, 0x0); /* string terminator. */ #endif octstr_append_char(pduhdr, 0xaf); /* push application ID header and value follows. */ octstr_append_char(pduhdr, 0x84); /* ... */ s = mms_tobinary(msg); if (isphonenum) { Octstr *url; octstr_url_encode(to); octstr_url_encode(s); #if 0 octstr_dump(pduhdr, 0); #endif octstr_url_encode(pduhdr); url = octstr_format("%S&text=%S%S&to=%S&udh=%%06%%05%%04%%0B%%84%%23%%F0", settings->sendsms_url, pduhdr, s, to); pheaders = http_create_empty_headers(); http_header_add(pheaders, "Connection", "close"); http_header_add(pheaders, "User-Agent", MM_NAME "/" MMSC_VERSION); http_start_request(httpcaller, HTTP_METHOD_GET, url, pheaders, NULL, 0, e, NULL); http_destroy_headers(pheaders); octstr_destroy(url); } else { /* An IP Address: Send packet, forget. */ Octstr *addr = udp_create_address(to, WAPPUSH_PORT); int sock = udp_client_socket(); if (sock > 0) { MmsEnvelopeTo *xto = gwlist_get(e->to,0); octstr_append(pduhdr, s); #if 0 octstr_dump(pduhdr, 0); #endif udp_sendto(sock, pduhdr, addr); close(sock); /* ?? */ mms_log2("Notify", octstr_imm("system"), to, -1, e ? e->msgId : NULL, NULL, NULL, "MM1", NULL,NULL); e = update_env_success(e, xto); } else { e = update_env_failed(e); error(0, "push to %s:%d failed: %s", octstr_get_cstr(to), WAPPUSH_PORT, strerror(errno)); } octstr_destroy(addr); if (e) settings->qfs->mms_queue_free_env(e); } done: octstr_destroy(to); octstr_destroy(pduhdr); octstr_destroy(s); }
Octstr *urltrans_fill_escape_codes(Octstr *pattern, Msg *request) { Octstr *enc; Octstr *meta_group, *meta_param; int nextarg, j; struct tm tm; int num_words; List *word_list; Octstr *result; long pattern_len; long pos; int c; long i, k; Octstr *temp; result = octstr_create(""); if (request->sms.msgdata) { word_list = octstr_split_words(request->sms.msgdata); num_words = gwlist_len(word_list); } else { word_list = gwlist_create(); num_words = 0; } pattern_len = octstr_len(pattern); nextarg = 1; pos = 0; for (;;) { while (pos < pattern_len) { c = octstr_get_char(pattern, pos); if (c == '%' && pos + 1 < pattern_len) break; octstr_append_char(result, c); ++pos; } if (pos == pattern_len) break; switch (octstr_get_char(pattern, pos + 1)) { case 'a': for (j = 0; j < num_words; ++j) { enc = octstr_duplicate(gwlist_get(word_list, j)); octstr_url_encode(enc); if (j > 0) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; case 'A': if (request->sms.msgdata) { enc = octstr_duplicate(request->sms.msgdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'b': enc = octstr_duplicate(request->sms.msgdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'B': /* billing identifier/information */ if (octstr_len(request->sms.binfo)) { enc = octstr_duplicate(request->sms.binfo); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'c': octstr_append_decimal(result, request->sms.coding); break; case 'C': if (octstr_len(request->sms.charset)) { octstr_append(result, request->sms.charset); } else { switch (request->sms.coding) { case DC_UNDEF: case DC_7BIT: octstr_append(result, octstr_imm("UTF-8")); break; case DC_8BIT: octstr_append(result, octstr_imm("8-BIT")); break; case DC_UCS2: octstr_append(result, octstr_imm("UTF-16BE")); break; } } break; case 'd': enc = octstr_create(""); octstr_append_decimal(enc, request->sms.dlr_mask); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'D': /* meta_data */ if (octstr_len(request->sms.meta_data)) { enc = octstr_duplicate(request->sms.meta_data); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'f': /* smsc number*/ if (octstr_len(request->sms.smsc_number)) { enc = octstr_duplicate(request->sms.smsc_number); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'F': if (request->sms.foreign_id == NULL) break; enc = octstr_duplicate(request->sms.foreign_id); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'i': if (request->sms.smsc_id == NULL) break; enc = octstr_duplicate(request->sms.smsc_id); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'I': if (!uuid_is_null(request->sms.id)) { char id[UUID_STR_LEN + 1]; uuid_unparse(request->sms.id, id); octstr_append_cstr(result, id); } break; case 'k': if (num_words <= 0) break; enc = octstr_duplicate(gwlist_get(word_list, 0)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'm': /* mclass - message class */ enc = octstr_create(""); octstr_append_decimal(enc, request->sms.mclass); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'M': /* mwi - message waiting indicator */ enc = octstr_create(""); octstr_append_decimal(enc, request->sms.mwi); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'n': if (request->sms.service == NULL) break; enc = octstr_duplicate(request->sms.service); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'o': /* account information (may be operator id for aggregators */ if (octstr_len(request->sms.account)) { enc = octstr_duplicate(request->sms.account); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'O': /* DCS */ { int dcs; dcs = fields_to_dcs(request, request->sms.alt_dcs); octstr_format_append(result, "%02d", dcs); break; } /* NOTE: the sender and receiver is already switched in * message, so that's why we must use 'sender' when * we want original receiver and vice versa */ case 'P': enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'p': enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'q': if (strncmp(octstr_get_cstr(request->sms.receiver),"00",2)==0) { enc = octstr_copy(request->sms.receiver, 2, octstr_len(request->sms.receiver)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'Q': if (strncmp(octstr_get_cstr(request->sms.sender), "00", 2) == 0) { enc = octstr_copy(request->sms.sender, 2, octstr_len(request->sms.sender)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'r': for (j = nextarg; j < num_words; ++j) { enc = octstr_duplicate(gwlist_get(word_list, j)); octstr_url_encode(enc); if (j != nextarg) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; case 'R': /* dlr_url */ if (octstr_len(request->sms.dlr_url)) { enc = octstr_duplicate(request->sms.dlr_url); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 's': if (nextarg >= num_words) break; enc = octstr_duplicate(gwlist_get(word_list, nextarg)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); ++nextarg; break; case 'S': if (nextarg >= num_words) break; temp = gwlist_get(word_list, nextarg); for (i = 0; i < octstr_len(temp); ++i) { if (octstr_get_char(temp, i) == '*') octstr_append_char(result, '~'); else octstr_append_char(result, octstr_get_char(temp, i)); } ++nextarg; break; case 't': tm = gw_gmtime(request->sms.time); octstr_format_append(result, "%04d-%02d-%02d+%02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); break; case 'T': if (request->sms.time == MSG_PARAM_UNDEFINED) break; octstr_format_append(result, "%ld", request->sms.time); break; case 'u': if(octstr_len(request->sms.udhdata)) { enc = octstr_duplicate(request->sms.udhdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'v': if (request->sms.validity != MSG_PARAM_UNDEFINED) { octstr_format_append(result, "%ld", (request->sms.validity - time(NULL)) / 60); } break; case 'V': if (request->sms.deferred != MSG_PARAM_UNDEFINED) { octstr_format_append(result, "%ld", (request->sms.deferred - time(NULL)) / 60); } break; /* * This allows to pass meta-data individual parameters into urls. * The syntax is as follows: %#group#parameter# * For example: %#smpp#my_param# would be replaced with the value * 'my_param' from the group 'smpp' coming inside the meta_data field. */ case '#': /* ASCII 0x23 == '#' */ k = octstr_search_char(pattern, 0x23, pos + 2); if (k >= 0) { pos += 2; meta_group = octstr_copy(pattern, pos, (k-pos)); pos = k + 1; k = octstr_search_char(pattern, 0x23, pos); if (k >= 0) { meta_param = octstr_copy(pattern, pos, (k-pos)); pos = k - 1; if (request->sms.meta_data != NULL) { enc = meta_data_get_value(request->sms.meta_data, octstr_get_cstr(meta_group), meta_param); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } octstr_destroy(meta_param); } else { pos++; } octstr_destroy(meta_group); } break; /* XXX sms.parameters not present in here: * * pid - will we receive this ? * * alt-dcs - shouldn't be required unless we want to inform * which alt-dcs external server should use back * * compress - if we use compression, probably kannel would * decompress and reset this to 0. not required * * rpi - we don't receive these from smsc * * username, password, dlr-url, account - nonsense to send */ case '%': octstr_format_append(result, "%%"); break; default: octstr_format_append(result, "%%%c", octstr_get_char(pattern, pos + 1)); break; } pos += 2; } gwlist_destroy(word_list, octstr_destroy_item); return result; }
static Cookie *parse_cookie(Octstr *cookiestr) { char *v = NULL; char *p = NULL; int delta = 0; Cookie *c = NULL; Octstr **f = NULL; if (cookiestr == NULL) { error(0, "parse_cookie: NULL argument"); return NULL; } v = gw_strdup(octstr_get_cstr (cookiestr)); p = strtok(v, ";"); c = cookie_create(); /* Never returns NULL */ while (p != NULL) { while (isspace((int)*p)) p++; /* Skip leading whitespace */ if (strncasecmp("version", p, 7) == 0) f = &c -> version; else if (strncasecmp("path", p, 4) == 0) f = &c -> path; else if (strncasecmp("domain", p, 6) == 0) f = &c -> domain; /* XXX DAVI: Shouldn't we check if domain is similar * to real domain, and to set domain to * real domain if not set by header ??? */ else if (strncasecmp("max-age", p, 7) == 0) { c -> max_age = atol(strrchr (p, '=') + 1); p = strtok(NULL, ";"); continue; } else if (strncasecmp("expires", p, 7) == 0) { delta = parse_http_date(p); if (delta != -1) c->max_age = delta; p = strtok(NULL, ";"); continue; } else if (strncasecmp("comment", p, 7) == 0 ) { /* Ignore comments */ p = strtok(NULL, ";"); continue; } else if (strncasecmp("secure", p, 6) == 0 ) { /* XXX DAVI: this should processed */ p = strtok(NULL, ";"); continue; } else { /* Name value pair - this should be first */ char *equals = NULL; if ((equals = strchr(p, '=')) != NULL) { *equals = '\0'; c->name = octstr_create(p); c->value = octstr_create(equals + 1); } else { error(0, "parse_cookie: Bad name=value cookie component (%s)", p); cookie_destroy(c); return NULL; } p = strtok(NULL, ";"); continue; } if (*f != NULL) { /* Undefined behaviour - 4.2.2 */ error(0, "parse_cookie: Duplicate cookie field (%s), discarding", p); p = strtok(NULL, ";"); continue; } *f = octstr_create("$"); octstr_append_cstr(*f, p); p = strtok(NULL, ";"); } /* Process version - 4.3.4 * XXX DAVI: Altough it seems to be "MUST" in RFC, no one sends a Version * tag when it's value is "0" if (c->version == NULL) { c->version = octstr_create(""); octstr_append_cstr(c->version, "$Version=\"0\";"); } */ gw_free (v); return c; }
static void httpd_serve(HTTPClient *client, Octstr *ourl, List *headers, Octstr *body, List *cgivars) { Octstr *reply, *final_reply, *url; char *content_type; char *header, *footer; int status_type; int i; long pos; reply = final_reply = NULL; /* for compiler please */ url = octstr_duplicate(ourl); /* Set default reply format according to client * Accept: header */ if (http_type_accepted(headers, "text/vnd.wap.wml")) { status_type = BBSTATUS_WML; content_type = "text/vnd.wap.wml"; } else if (http_type_accepted(headers, "text/html")) { status_type = BBSTATUS_HTML; content_type = "text/html"; } else if (http_type_accepted(headers, "text/xml")) { status_type = BBSTATUS_XML; content_type = "text/xml"; } else { status_type = BBSTATUS_TEXT; content_type = "text/plain"; } /* kill '/cgi-bin' prefix */ pos = octstr_search(url, octstr_imm("/cgi-bin/"), 0); if (pos != -1) octstr_delete(url, pos, 9); else if (octstr_get_char(url, 0) == '/') octstr_delete(url, 0, 1); /* look for type and kill it */ pos = octstr_search_char(url, '.', 0); if (pos != -1) { Octstr *tmp = octstr_copy(url, pos+1, octstr_len(url) - pos - 1); octstr_delete(url, pos, octstr_len(url) - pos); if (octstr_str_compare(tmp, "txt") == 0) status_type = BBSTATUS_TEXT; else if (octstr_str_compare(tmp, "html") == 0) status_type = BBSTATUS_HTML; else if (octstr_str_compare(tmp, "xml") == 0) status_type = BBSTATUS_XML; else if (octstr_str_compare(tmp, "wml") == 0) status_type = BBSTATUS_WML; octstr_destroy(tmp); } for (i=0; httpd_commands[i].command != NULL; i++) { if (octstr_str_compare(url, httpd_commands[i].command) == 0) { reply = httpd_commands[i].function(cgivars, status_type); break; } } /* check if command found */ if (httpd_commands[i].command == NULL) { char *lb = bb_status_linebreak(status_type); reply = octstr_format("Unknown command `%S'.%sPossible commands are:%s", ourl, lb, lb); for (i=0; httpd_commands[i].command != NULL; i++) octstr_format_append(reply, "%s%s", httpd_commands[i].command, lb); } gw_assert(reply != NULL); if (status_type == BBSTATUS_HTML) { header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" "<html>\n<title>" GW_NAME "</title>\n<body>\n<p>"; footer = "</p>\n</body></html>\n"; content_type = "text/html"; } else if (status_type == BBSTATUS_WML) { header = "<?xml version=\"1.0\"?>\n" "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" " "\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n" "\n<wml>\n <card>\n <p>"; footer = " </p>\n </card>\n</wml>\n"; content_type = "text/vnd.wap.wml"; } else if (status_type == BBSTATUS_XML) { header = "<?xml version=\"1.0\"?>\n" "<gateway>\n"; footer = "</gateway>\n"; } else { header = ""; footer = ""; content_type = "text/plain"; } final_reply = octstr_create(header); octstr_append(final_reply, reply); octstr_append_cstr(final_reply, footer); /* debug("bb.http", 0, "Result: '%s'", octstr_get_cstr(final_reply)); */ http_destroy_headers(headers); headers = list_create(); http_header_add(headers, "Content-Type", content_type); http_send_reply(client, HTTP_OK, headers, final_reply); octstr_destroy(url); octstr_destroy(ourl); octstr_destroy(body); octstr_destroy(reply); octstr_destroy(final_reply); http_destroy_headers(headers); http_destroy_cgiargs(cgivars); }
Octstr *bb_print_status(int status_type) { char *s, *lb; char *frmt, *footer; Octstr *ret, *str, *version; time_t t; if ((lb = bb_status_linebreak(status_type)) == NULL) return octstr_create("Un-supported format"); t = time(NULL) - start_time; if (bb_status == BB_RUNNING) s = "running"; else if (bb_status == BB_ISOLATED) s = "isolated"; else if (bb_status == BB_SUSPENDED) s = "suspended"; else if (bb_status == BB_FULL) s = "filled"; else s = "going down"; version = version_report_string("bearerbox"); if (status_type == BBSTATUS_HTML) { frmt = "%s</p>\n\n" " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n" " <p>WDP: received %ld (%ld queued), sent %ld " "(%ld queued)</p>\n\n" " <p>SMS: received %ld (%ld queued), sent %ld " "(%ld queued), store size %ld<br>\n" " SMS: inbound (%.2f,%.2f,%.2f) msg/sec, " "outbound (%.2f,%.2f,%.2f) msg/sec</p>\n\n" " <p>DLR: received %ld, sent %ld<br>\n" " DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec<br>\n" " DLR: %ld queued, using %s storage</p>\n\n"; footer = "<p>"; } else if (status_type == BBSTATUS_WML) { frmt = "%s</p>\n\n" " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n" " <p>WDP: received %ld (%ld queued)<br/>\n" " WDP: sent %ld (%ld queued)</p>\n\n" " <p>SMS: received %ld (%ld queued)<br/>\n" " SMS: sent %ld (%ld queued)<br/>\n" " SMS: store size %ld<br/>\n" " SMS: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n" " SMS: outbound (%.2f,%.2f,%.2f) msg/sec</p>\n" " <p>DLR: received %ld<br/>\n" " DLR: sent %ld<br/>\n" " DLR: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n" " DLR: outbound (%.2f,%.2f,%.2f) msg/sec<br/>\n" " DLR: %ld queued<br/>\n" " DLR: using %s storage</p>\n\n"; footer = "<p>"; } else if (status_type == BBSTATUS_XML) { frmt = "<version>%s</version>\n" "<status>%s, uptime %ldd %ldh %ldm %lds</status>\n" "\t<wdp>\n\t\t<received><total>%ld</total><queued>%ld</queued>" "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>" "</sent>\n\t</wdp>\n" "\t<sms>\n\t\t<received><total>%ld</total><queued>%ld</queued>" "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>" "</sent>\n\t\t<storesize>%ld</storesize>\n\t\t" "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t" "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t" "</sms>\n" "\t<dlr>\n\t\t<received><total>%ld</total></received>\n\t\t" "<sent><total>%ld</total></sent>\n\t\t" "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t" "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t" "<queued>%ld</queued>\n\t\t<storage>%s</storage>\n\t</dlr>\n"; footer = ""; } else { frmt = "%s\n\nStatus: %s, uptime %ldd %ldh %ldm %lds\n\n" "WDP: received %ld (%ld queued), sent %ld (%ld queued)\n\n" "SMS: received %ld (%ld queued), sent %ld (%ld queued), store size %ld\n" "SMS: inbound (%.2f,%.2f,%.2f) msg/sec, " "outbound (%.2f,%.2f,%.2f) msg/sec\n\n" "DLR: received %ld, sent %ld\n" "DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec\n" "DLR: %ld queued, using %s storage\n\n"; footer = ""; } ret = octstr_format(frmt, octstr_get_cstr(version), s, t/3600/24, t/3600%24, t/60%60, t%60, counter_value(incoming_wdp_counter), gwlist_len(incoming_wdp) + boxc_incoming_wdp_queue(), counter_value(outgoing_wdp_counter), gwlist_len(outgoing_wdp) + udp_outgoing_queue(), counter_value(incoming_sms_counter), gwlist_len(incoming_sms), counter_value(outgoing_sms_counter), gwlist_len(outgoing_sms), store_messages(), load_get(incoming_sms_load,0), load_get(incoming_sms_load,1), load_get(incoming_sms_load,2), load_get(outgoing_sms_load,0), load_get(outgoing_sms_load,1), load_get(outgoing_sms_load,2), counter_value(incoming_dlr_counter), counter_value(outgoing_dlr_counter), load_get(incoming_dlr_load,0), load_get(incoming_dlr_load,1), load_get(incoming_dlr_load,2), load_get(outgoing_dlr_load,0), load_get(outgoing_dlr_load,1), load_get(outgoing_dlr_load,2), dlr_messages(), dlr_type()); octstr_destroy(version); append_status(ret, str, boxc_status, status_type); append_status(ret, str, smsc2_status, status_type); octstr_append_cstr(ret, footer); return ret; }
static Octstr *store_file_status(int status_type) { char *frmt; Octstr *ret, *key; unsigned long l; struct tm tm; Msg *msg; List *keys; char id[UUID_STR_LEN + 1]; ret = octstr_create(""); /* set the type based header */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret, "<table border=1>\n" "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>" "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>" "</tr>\n"); } else if (status_type == BBSTATUS_TEXT) { octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n"); } /* if there is no store-file, then don't loop in sms_store */ if (filename == NULL) goto finish; keys = dict_keys(sms_dict); for (l = 0; l < gwlist_len(keys); l++) { key = gwlist_get(keys, l); msg = dict_get(sms_dict, key); if (msg == NULL) continue; if (msg_type(msg) == sms) { if (status_type == BBSTATUS_HTML) { frmt = "<tr><td>%s</td><td>%s</td>" "<td>%04d-%02d-%02d %02d:%02d:%02d</td>" "<td>%s</td><td>%s</td><td>%s</td>" "<td>%s</td><td>%s</td><td>%s</td></tr>\n"; } else if (status_type == BBSTATUS_XML) { frmt = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t" "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t" "<sender>%s</sender>\n\t" "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t" "<box-id>%s</box-id>\n\t" "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t" "</message>\n"; } else { frmt = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n"; } /* transform the time value */ #if LOG_TIMESTAMP_LOCALTIME tm = gw_localtime(msg->sms.time); #else tm = gw_gmtime(msg->sms.time); #endif if (msg->sms.udhdata) octstr_binary_to_hex(msg->sms.udhdata, 1); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_binary_to_hex(msg->sms.msgdata, 1); uuid_unparse(msg->sms.id, id); octstr_format_append(ret, frmt, id, (msg->sms.sms_type == mo ? "MO" : msg->sms.sms_type == mt_push ? "MT-PUSH" : msg->sms.sms_type == mt_reply ? "MT-REPLY" : msg->sms.sms_type == report_mo ? "DLR-MO" : msg->sms.sms_type == report_mt ? "DLR-MT" : ""), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""), (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""), (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""), (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""), (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""), (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : "")); if (msg->sms.udhdata) octstr_hex_to_binary(msg->sms.udhdata); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_hex_to_binary(msg->sms.msgdata); } } gwlist_destroy(keys, octstr_destroy_item); finish: /* set the type based footer */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret,"</table>"); } return ret; }
int cfg_read(Cfg *cfg) { CfgLoc *loc; CfgLoc *loc_inc; List *lines; List *expand; List *stack; Octstr *name; Octstr *value; Octstr *filename; CfgGroup *grp; long equals; long lineno; long error_lineno; loc = loc_inc = NULL; /* * expand initial main config file and add it to the recursion * stack to protect against cycling */ if ((lines = expand_file(cfg->filename, 1)) == NULL) { panic(0, "Failed to load main configuration file `%s'. Aborting!", octstr_get_cstr(cfg->filename)); } stack = gwlist_create(); gwlist_insert(stack, 0, octstr_duplicate(cfg->filename)); grp = NULL; lineno = 0; error_lineno = 0; while (error_lineno == 0 && (loc = gwlist_extract_first(lines)) != NULL) { octstr_strip_blanks(loc->line); if (octstr_len(loc->line) == 0) { if (grp != NULL && add_group(cfg, grp) == -1) { error_lineno = loc->line_no; destroy_group(grp); } grp = NULL; } else if (octstr_get_char(loc->line, 0) != '#') { equals = octstr_search_char(loc->line, '=', 0); if (equals == -1) { error(0, "An equals sign ('=') is missing on line %ld of file %s.", loc->line_no, octstr_get_cstr(loc->filename)); error_lineno = loc->line_no; } else /* * check for special config directives, like include or conditional * directives here */ if (octstr_search(loc->line, octstr_imm("include"), 0) != -1) { filename = octstr_copy(loc->line, equals + 1, octstr_len(loc->line)); parse_value(filename); /* check if we are cycling */ if (gwlist_search(stack, filename, octstr_item_match) != NULL) { panic(0, "Recursive include for config file `%s' detected " "(on line %ld of file %s).", octstr_get_cstr(filename), loc->line_no, octstr_get_cstr(loc->filename)); } else { List *files = gwlist_create(); Octstr *file; struct stat filestat; /* check if included file is a directory */ if (lstat(octstr_get_cstr(filename), &filestat) != 0) { error(errno, "lstat failed: couldn't stat `%s'", octstr_get_cstr(filename)); panic(0, "Failed to include `%s' " "(on line %ld of file %s). Aborting!", octstr_get_cstr(filename), loc->line_no, octstr_get_cstr(loc->filename)); } /* * is a directory, create a list with files of * this directory and load all as part of the * whole configuration. */ if (S_ISDIR(filestat.st_mode)) { DIR *dh; struct dirent *diritem; debug("gwlib.cfg", 0, "Loading include dir `%s' " "(on line %ld of file %s).", octstr_get_cstr(filename), loc->line_no, octstr_get_cstr(loc->filename)); dh = opendir(octstr_get_cstr(filename)); while ((diritem = readdir(dh))) { Octstr *fileitem; fileitem = octstr_duplicate(filename); octstr_append_cstr(fileitem, "/"); octstr_append_cstr(fileitem, diritem->d_name); lstat(octstr_get_cstr(fileitem), &filestat); if (!S_ISDIR(filestat.st_mode)) { gwlist_insert(files, 0, fileitem); } else { octstr_destroy(fileitem); } } closedir(dh); } /* is a file, create a list with it */ else { gwlist_insert(files, 0, octstr_duplicate(filename)); } /* include files */ while ((file = gwlist_extract_first(files)) != NULL) { gwlist_insert(stack, 0, octstr_duplicate(file)); debug("gwlib.cfg", 0, "Loading include file `%s' (on line %ld of file %s).", octstr_get_cstr(file), loc->line_no, octstr_get_cstr(loc->filename)); /* * expand the given include file and add it to the current * processed main while loop */ if ((expand = expand_file(file, 0)) != NULL) { while ((loc_inc = gwlist_extract_first(expand)) != NULL) gwlist_insert(lines, 0, loc_inc); } else { panic(0, "Failed to load whole configuration. Aborting!"); } gwlist_destroy(expand, NULL); cfgloc_destroy(loc_inc); octstr_destroy(file); } gwlist_destroy(files, octstr_destroy_item); } octstr_destroy(filename); } /* * this is a "normal" line, so process it accodingly */ else { name = octstr_copy(loc->line, 0, equals); octstr_strip_blanks(name); value = octstr_copy(loc->line, equals + 1, octstr_len(loc->line)); parse_value(value); if (grp == NULL) grp = create_group(); if (grp->configfile != NULL) { octstr_destroy(grp->configfile); grp->configfile = NULL; } grp->configfile = octstr_duplicate(cfg->filename); cfg_set(grp, name, value); octstr_destroy(name); octstr_destroy(value); } } cfgloc_destroy(loc); } if (grp != NULL && add_group(cfg, grp) == -1) { error_lineno = 1; destroy_group(grp); } gwlist_destroy(lines, NULL); gwlist_destroy(stack, octstr_destroy_item); if (error_lineno != 0) { error(0, "Error found on line %ld of file `%s'.", error_lineno, octstr_get_cstr(cfg->filename)); return -1; } return 0; }
/* * Create one URLTranslation. Return NULL for failure, pointer to it for OK. */ static URLTranslation *create_onetrans(CfgGroup *grp) { URLTranslation *ot; Octstr *url, *post_url, *post_xml, *text, *file, *exec; Octstr *accepted_smsc, *accepted_account, *forced_smsc, *default_smsc; Octstr *grpname; int is_sms_service, regex_flag = REG_EXTENDED; Octstr *accepted_smsc_regex; Octstr *accepted_account_regex; Octstr *allowed_prefix_regex; Octstr *denied_prefix_regex; Octstr *allowed_receiver_prefix_regex; Octstr *denied_receiver_prefix_regex; Octstr *white_list_regex; Octstr *black_list_regex; Octstr *keyword_regex; Octstr *os, *tmp; grpname = cfg_get_group_name(grp); if (grpname == NULL) return NULL; if (octstr_str_compare(grpname, "sms-service") == 0) is_sms_service = 1; else if (octstr_str_compare(grpname, "sendsms-user") == 0) is_sms_service = 0; else { octstr_destroy(grpname); return NULL; } octstr_destroy(grpname); ot = gw_malloc(sizeof(URLTranslation)); memset(ot, 0, sizeof(*ot)); if (is_sms_service) { cfg_get_bool(&ot->catch_all, grp, octstr_imm("catch-all")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); if (cfg_get_integer(&ot->dlr_mask, grp, octstr_imm("dlr-mask")) == -1) ot->dlr_mask = DLR_UNDEFINED; ot->alt_charset = cfg_get(grp, octstr_imm("alt-charset")); url = cfg_get(grp, octstr_imm("get-url")); if (url == NULL) url = cfg_get(grp, octstr_imm("url")); post_url = cfg_get(grp, octstr_imm("post-url")); post_xml = cfg_get(grp, octstr_imm("post-xml")); file = cfg_get(grp, octstr_imm("file")); text = cfg_get(grp, octstr_imm("text")); exec = cfg_get(grp, octstr_imm("exec")); if (url != NULL) { ot->type = TRANSTYPE_GET_URL; ot->pattern = octstr_duplicate(url); } else if (post_url != NULL) { ot->type = TRANSTYPE_POST_URL; ot->pattern = octstr_duplicate(post_url); ot->catch_all = 1; } else if (post_xml != NULL) { ot->type = TRANSTYPE_POST_XML; ot->pattern = octstr_duplicate(post_xml); ot->catch_all = 1; } else if (file != NULL) { ot->type = TRANSTYPE_FILE; ot->pattern = octstr_duplicate(file); } else if (text != NULL) { ot->type = TRANSTYPE_TEXT; ot->pattern = octstr_duplicate(text); } else if (exec != NULL) { ot->type = TRANSTYPE_EXECUTE; ot->pattern = octstr_duplicate(exec); } else { octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); error(0, "Configuration group `sms-service' " "did not specify get-url, post-url, post-xml, file or text."); goto error; } octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); tmp = cfg_get(grp, octstr_imm("keyword")); keyword_regex = cfg_get(grp, octstr_imm("keyword-regex")); if (tmp == NULL && keyword_regex == NULL) { error(0, "Group 'sms-service' must include either 'keyword' or 'keyword-regex'."); goto error; } if (tmp != NULL && keyword_regex != NULL) { error(0, "Group 'sms-service' may inlcude either 'keyword' or 'keyword-regex'."); octstr_destroy(tmp); octstr_destroy(keyword_regex); goto error; } if (tmp != NULL && octstr_str_compare(tmp, "default") == 0) { /* default sms-service */ ot->keyword_regex = NULL; octstr_destroy(tmp); } else if (tmp != NULL) { Octstr *aliases; /* convert to regex */ regex_flag |= REG_ICASE; keyword_regex = octstr_format("^[ ]*(%S", tmp); octstr_destroy(tmp); aliases = cfg_get(grp, octstr_imm("aliases")); if (aliases != NULL) { long i; List *l; l = octstr_split(aliases, octstr_imm(";")); octstr_destroy(aliases); for (i = 0; i < gwlist_len(l); ++i) { os = gwlist_get(l, i); octstr_format_append(keyword_regex, "|%S", os); } gwlist_destroy(l, octstr_destroy_item); } octstr_append_cstr(keyword_regex, ")[ ]*"); } if (keyword_regex != NULL && (ot->keyword_regex = gw_regex_comp(keyword_regex, regex_flag)) == NULL) { error(0, "Could not compile pattern '%s'", octstr_get_cstr(keyword_regex)); octstr_destroy(keyword_regex); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = keyword_regex ? octstr_duplicate(keyword_regex) : octstr_create("default"); octstr_destroy(keyword_regex); accepted_smsc = cfg_get(grp, octstr_imm("accepted-smsc")); if (accepted_smsc != NULL) { ot->accepted_smsc = octstr_split(accepted_smsc, octstr_imm(";")); octstr_destroy(accepted_smsc); } accepted_account = cfg_get(grp, octstr_imm("accepted-account")); if (accepted_account != NULL) { ot->accepted_account = octstr_split(accepted_account, octstr_imm(";")); octstr_destroy(accepted_account); } accepted_smsc_regex = cfg_get(grp, octstr_imm("accepted-smsc-regex")); if (accepted_smsc_regex != NULL) { if ( (ot->accepted_smsc_regex = gw_regex_comp(accepted_smsc_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_smsc_regex)); octstr_destroy(accepted_smsc_regex); } accepted_account_regex = cfg_get(grp, octstr_imm("accepted-account-regex")); if (accepted_account_regex != NULL) { if ( (ot->accepted_account_regex = gw_regex_comp(accepted_account_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_account_regex)); octstr_destroy(accepted_account_regex); } cfg_get_bool(&ot->assume_plain_text, grp, octstr_imm("assume-plain-text")); cfg_get_bool(&ot->accept_x_kannel_headers, grp, octstr_imm("accept-x-kannel-headers")); cfg_get_bool(&ot->strip_keyword, grp, octstr_imm("strip-keyword")); cfg_get_bool(&ot->send_sender, grp, octstr_imm("send-sender")); ot->prefix = cfg_get(grp, octstr_imm("prefix")); ot->suffix = cfg_get(grp, octstr_imm("suffix")); ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); allowed_receiver_prefix_regex = cfg_get(grp, octstr_imm("allowed-receiver-prefix-regex")); if (allowed_receiver_prefix_regex != NULL) { if ((ot->allowed_receiver_prefix_regex = gw_regex_comp(allowed_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_receiver_prefix_regex)); octstr_destroy(allowed_receiver_prefix_regex); } ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); ot->denied_recv_prefix = cfg_get(grp, octstr_imm("denied-receiver-prefix")); denied_receiver_prefix_regex = cfg_get(grp, octstr_imm("denied-receiver-prefix-regex")); if (denied_receiver_prefix_regex != NULL) { if ((ot->denied_receiver_prefix_regex = gw_regex_comp(denied_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'",octstr_get_cstr(denied_receiver_prefix_regex)); octstr_destroy(denied_receiver_prefix_regex); } ot->args = count_occurences(ot->pattern, octstr_imm("%s")); ot->args += count_occurences(ot->pattern, octstr_imm("%S")); ot->has_catchall_arg = (count_occurences(ot->pattern, octstr_imm("%r")) > 0) || (count_occurences(ot->pattern, octstr_imm("%a")) > 0); } else { ot->type = TRANSTYPE_SENDSMS; ot->pattern = octstr_create(""); ot->args = 0; ot->has_catchall_arg = 0; ot->catch_all = 1; ot->username = cfg_get(grp, octstr_imm("username")); ot->password = cfg_get(grp, octstr_imm("password")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); grp_dump(grp); if (ot->password == NULL) { error(0, "Password required for send-sms user"); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = octstr_duplicate(ot->username); forced_smsc = cfg_get(grp, octstr_imm("forced-smsc")); default_smsc = cfg_get(grp, octstr_imm("default-smsc")); if (forced_smsc != NULL) { if (default_smsc != NULL) { info(0, "Redundant default-smsc for send-sms user %s", octstr_get_cstr(ot->username)); } ot->forced_smsc = forced_smsc; octstr_destroy(default_smsc); } else if (default_smsc != NULL) ot->default_smsc = default_smsc; ot->deny_ip = cfg_get(grp, octstr_imm("user-deny-ip")); ot->allow_ip = cfg_get(grp, octstr_imm("user-allow-ip")); ot->default_sender = cfg_get(grp, octstr_imm("default-sender")); } ot->allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix")); allowed_prefix_regex = cfg_get(grp, octstr_imm("allowed-prefix-regex")); if (allowed_prefix_regex != NULL) { if ((ot->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex)); octstr_destroy(allowed_prefix_regex); } ot->denied_prefix = cfg_get(grp, octstr_imm("denied-prefix")); denied_prefix_regex = cfg_get(grp, octstr_imm("denied-prefix-regex")); if (denied_prefix_regex != NULL) { if ((ot->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex)); octstr_destroy(denied_prefix_regex); } os = cfg_get(grp, octstr_imm("white-list")); if (os != NULL) { ot->white_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } white_list_regex = cfg_get(grp, octstr_imm("white-list-regex")); if (white_list_regex != NULL) { if ((ot->white_list_regex = gw_regex_comp(white_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(white_list_regex)); octstr_destroy(white_list_regex); } os = cfg_get(grp, octstr_imm("black-list")); if (os != NULL) { ot->black_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } black_list_regex = cfg_get(grp, octstr_imm("black-list-regex")); if (black_list_regex != NULL) { if ((ot->black_list_regex = gw_regex_comp(black_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(black_list_regex)); octstr_destroy(black_list_regex); } if (cfg_get_integer(&ot->max_messages, grp, octstr_imm("max-messages")) == -1) ot->max_messages = 1; cfg_get_bool(&ot->concatenation, grp, octstr_imm("concatenation")); cfg_get_bool(&ot->omit_empty, grp, octstr_imm("omit-empty")); ot->header = cfg_get(grp, octstr_imm("header")); ot->footer = cfg_get(grp, octstr_imm("footer")); ot->faked_sender = cfg_get(grp, octstr_imm("faked-sender")); ot->split_chars = cfg_get(grp, octstr_imm("split-chars")); ot->split_suffix = cfg_get(grp, octstr_imm("split-suffix")); if ( (ot->prefix == NULL && ot->suffix != NULL) || (ot->prefix != NULL && ot->suffix == NULL) ) { warning(0, "Service : suffix and prefix are only used" " if both are set."); } if ((ot->prefix != NULL || ot->suffix != NULL) && ot->type != TRANSTYPE_GET_URL) { warning(0, "Service : suffix and prefix are only used" " if type is 'get-url'."); } return ot; error: error(0, "Couldn't create a URLTranslation."); destroy_onetrans(ot); return NULL; }
static int kannel_send_sms(SMSCConn *conn, Msg *sms) { ConnData *conndata = conn->data; Octstr *url; List *headers; if (!conndata->no_sep) { url = octstr_format("%S?" "username=%E&password=%E&to=%E&text=%E", conndata->send_url, conndata->username, conndata->password, sms->sms.receiver, sms->sms.msgdata); } else { Octstr *msgdata = octstr_duplicate(sms->sms.msgdata); octstr_binary_to_hex(msgdata, HEX_NOT_UPPERCASE); url = octstr_format("%S?" "username=%E&password=%E&to=%E&text=%S", conndata->send_url, conndata->username, conndata->password, sms->sms.receiver, msgdata); octstr_destroy(msgdata); } if (octstr_len(sms->sms.udhdata)) { if (!conndata->no_sep) { octstr_format_append(url, "&udh=%E", sms->sms.udhdata); } else { Octstr *udhdata = octstr_duplicate(sms->sms.udhdata); octstr_binary_to_hex(udhdata, HEX_NOT_UPPERCASE); octstr_format_append(url, "&udh=%S", udhdata); octstr_destroy(udhdata); } } if (!conndata->no_sender) octstr_format_append(url, "&from=%E", sms->sms.sender); if (sms->sms.mclass != MC_UNDEF) octstr_format_append(url, "&mclass=%d", sms->sms.mclass); if (!conndata->no_coding && sms->sms.coding != DC_UNDEF) octstr_format_append(url, "&coding=%d", sms->sms.coding); /* Obey that smsbox's sendsms HTTP interface is still expecting * WINDOWS-1252 as default charset, while all other internal parts * use UTF-8 as internal encoding. This means, when we pass a SMS * into a next Kannel instance, we need to let the smsbox know which * charset we have in use. * XXX TODO: change smsbox interface to use UTF-8 as default * in next major release. */ if (sms->sms.coding == DC_7BIT) octstr_append_cstr(url, "&charset=UTF-8"); else if (sms->sms.coding == DC_UCS2) octstr_append_cstr(url, "&charset=UTF-16BE"); if (sms->sms.mwi != MWI_UNDEF) octstr_format_append(url, "&mwi=%d", sms->sms.mwi); if (sms->sms.account) /* prepend account with local username */ octstr_format_append(url, "&account=%E:%E", sms->sms.service, sms->sms.account); if (sms->sms.binfo) /* prepend billing info */ octstr_format_append(url, "&binfo=%S", sms->sms.binfo); if (sms->sms.smsc_id) /* proxy the smsc-id to the next instance */ octstr_format_append(url, "&smsc=%S", sms->sms.smsc_id); if (conndata->dlr_url) { char id[UUID_STR_LEN + 1]; Octstr *mid; /* create Octstr from UUID */ uuid_unparse(sms->sms.id, id); mid = octstr_create(id); octstr_format_append(url, "&dlr-url=%E", conndata->dlr_url); /* encapsulate the original DLR-URL, escape code for DLR mask * and message id */ octstr_format_append(url, "%E%E%E%E%E", octstr_imm("&dlr-url="), sms->sms.dlr_url != NULL ? sms->sms.dlr_url : octstr_imm(""), octstr_imm("&dlr-mask=%d"), octstr_imm("&dlr-mid="), mid); octstr_destroy(mid); } else if (sms->sms.dlr_url != NULL) octstr_format_append(url, "&dlr-url=%E", sms->sms.dlr_url); if (sms->sms.dlr_mask != DLR_UNDEFINED && sms->sms.dlr_mask != DLR_NOTHING) octstr_format_append(url, "&dlr-mask=%d", sms->sms.dlr_mask); if (sms->sms.validity != SMS_PARAM_UNDEFINED) octstr_format_append(url, "&validity=%ld", (sms->sms.validity - time(NULL)) / 60); if (sms->sms.deferred != SMS_PARAM_UNDEFINED) octstr_format_append(url, "&deferred=%ld", (sms->sms.deferred - time(NULL)) / 60); headers = gwlist_create(); debug("smsc.http.kannel", 0, "HTTP[%s]: Start request", octstr_get_cstr(conn->id)); http_start_request(conndata->http_ref, HTTP_METHOD_GET, url, headers, NULL, 0, sms, NULL); octstr_destroy(url); http_destroy_headers(headers); return 0; }
int create_web_data(char *p_pszFileName, char *p_pszMMSDir, const char *p_pszWebDir) { int iRetVal = 0; MmsEnvelope *psoEnv; MmsMsg *psoMsg = NULL; List *psoHdrList = NULL; Octstr *psoHdrs = NULL, *psoHdrName = NULL, *psoHdrValue = NULL, *psoWebDir = NULL; MIMEEntity *psoMIME, *psoMIMETmp; int iMIMENum, iMIMEInd; int iFile = -1; gwlib_init(); mms_strings_init(); /* формируем имя директрии для вывода результатов */ psoWebDir = octstr_create(p_pszWebDir); if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) { octstr_append_char(psoWebDir, '/'); } octstr_append_cstr(psoWebDir, p_pszFileName); /* создаем директорию */ if(mkdir(octstr_get_cstr(psoWebDir), 0777)) { if(errno != EEXIST) { iRetVal = 2; } goto done; } psoEnv = default_qfuncs.mms_queue_readenvelope(p_pszFileName, p_pszMMSDir, 0); if(psoEnv) { psoMsg = default_qfuncs.mms_queue_getdata(psoEnv); default_qfuncs.mms_queue_free_env(psoEnv); } else { iRetVal = 3; goto done; } if(!psoMsg) { iRetVal = 4; goto done; } psoHdrs = octstr_create(""); /* выбираем необходимые заголовки */ psoHdrList = mms_message_headers(psoMsg); /* From */ psoHdrName = octstr_create("From"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* To */ octstr_append_cstr(psoHdrName, "To"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S\r\n", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /* Date */ octstr_append_cstr(psoHdrName, "Date"); psoHdrValue = http_header_value(psoHdrList, psoHdrName); octstr_format_append(psoHdrs, "%S/%S", psoHdrName, psoHdrValue); octstr_truncate(psoHdrName, 0); /**/ psoMIME = mms_tomime(psoMsg, 1); iMIMENum = mime_entity_num_parts(psoMIME); if(psoMIME) { for(iMIMEInd = 0; iMIMEInd < iMIMENum; ++iMIMEInd) { psoMIMETmp = mime_entity_get_part(psoMIME, iMIMEInd); operate_single_mime(psoHdrs, psoMIMETmp, octstr_get_cstr(psoWebDir)); } } /* формируем имя файла для вывода результатов, используем ту же переменную, что и для директории */ if('/' != octstr_get_char(psoWebDir, octstr_len(psoWebDir) - 1)) { octstr_append_char(psoWebDir, '/'); } octstr_append_cstr(psoWebDir, "common"); /* создаем файл */ iFile = open(octstr_get_cstr(psoWebDir), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(0 < iFile) { if(octstr_len(psoHdrs) != write(iFile, octstr_get_cstr(psoHdrs), octstr_len(psoHdrs))) { iRetVal = 5; } close(iFile); } else { if(errno != EEXIST) { iRetVal = 6; } } done: if(psoHdrs) { octstr_destroy(psoHdrs); } if(psoHdrName) { octstr_destroy(psoHdrName); } if(psoWebDir) { octstr_destroy(psoWebDir); } mms_strings_shutdown(); gwlib_shutdown(); return iRetVal; }
static Octstr *get_pattern(SMSCConn *conn, Msg *msg, const char *message) { int nextarg, j; struct tm tm; int num_words; List *word_list; Octstr *result; const char *pattern; Octstr *temp, *text, *udh; size_t n; long i; text = msg->sms.msgdata ? octstr_duplicate(msg->sms.msgdata) : octstr_create(""); udh = msg->sms.udhdata ? octstr_duplicate(msg->sms.udhdata) : octstr_create(""); if ((msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2)) octstr_binary_to_hex(text, 1); else octstr_convert_printable(text); octstr_binary_to_hex(udh, 1); if (octstr_len(text)) { word_list = octstr_split_words(text); num_words = gwlist_len(word_list); } else { word_list = gwlist_create(); num_words = 0; } result = octstr_create(""); pattern = octstr_get_cstr(custom_log_format); nextarg = 1; while(*pattern != '\0') { n = strcspn(pattern, "%"); octstr_append_data(result, pattern, n); pattern += n; gw_assert(*pattern == '%' || *pattern == '\0'); if (*pattern == '\0') break; pattern++; switch (*pattern) { case 'k': if (num_words <= 0) break; octstr_append(result, gwlist_get(word_list, 0)); break; case 's': if (nextarg >= num_words) break; octstr_append(result, gwlist_get(word_list, nextarg)); ++nextarg; break; case 'S': if (nextarg >= num_words) break; temp = gwlist_get(word_list, nextarg); for (i = 0; i < octstr_len(temp); ++i) { if (octstr_get_char(temp, i) == '*') octstr_append_char(result, '~'); else octstr_append_char(result, octstr_get_char(temp, i)); } ++nextarg; break; case 'r': for (j = nextarg; j < num_words; ++j) { if (j != nextarg) octstr_append_char(result, '+'); octstr_append(result, gwlist_get(word_list, j)); } break; case 'l': if (message) octstr_append_cstr(result, message); break; case 'P': if (msg->sms.receiver) octstr_append(result, msg->sms.receiver); break; case 'p': if (msg->sms.sender) octstr_append(result, msg->sms.sender); break; case 'a': for (j = 0; j < num_words; ++j) { if (j > 0) octstr_append_char(result, ' '); octstr_append(result, gwlist_get(word_list, j)); } break; case 'b': if (text) octstr_append(result, text); break; case 'L': octstr_append_decimal(result, octstr_len(msg->sms.msgdata)); break; case 't': tm = gw_gmtime(msg->sms.time); octstr_format_append(result, "%04d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); break; case 'T': if (msg->sms.time != MSG_PARAM_UNDEFINED) octstr_format_append(result, "%ld", msg->sms.time); break; case 'i': if (conn && smscconn_id(conn)) octstr_append(result, smscconn_id(conn)); else if (conn && smscconn_name(conn)) octstr_append(result, smscconn_name(conn)); else if (msg->sms.smsc_id) octstr_append(result, msg->sms.smsc_id); break; case 'I': if (!uuid_is_null(msg->sms.id)) { char id[UUID_STR_LEN + 1]; uuid_unparse(msg->sms.id, id); octstr_append_cstr(result, id); } break; case 'n': if (msg->sms.service != NULL) octstr_append(result, msg->sms.service); break; case 'd': octstr_append_decimal(result, msg->sms.dlr_mask); break; case 'c': octstr_append_decimal(result, msg->sms.coding); break; case 'm': octstr_append_decimal(result, msg->sms.mclass); break; case 'C': octstr_append_decimal(result, msg->sms.compress); break; case 'M': octstr_append_decimal(result, msg->sms.mwi); break; case 'u': if (octstr_len(udh)) { octstr_append(result, udh); } break; case 'U': octstr_append_decimal(result, octstr_len(msg->sms.udhdata)); break; case 'B': /* billing identifier/information */ if (octstr_len(msg->sms.binfo)) { octstr_append(result, msg->sms.binfo); } break; case 'A': /* account */ if (octstr_len(msg->sms.account)) { octstr_append(result, msg->sms.account); } break; /* XXX add more here if needed */ case '%': octstr_format_append(result, "%%"); break; default: warning(0, "Unknown escape code (%%%c) within custom-log-format, skipping!", *pattern); octstr_format_append(result, "%%%c", *pattern); break; } /* switch(...) */ pattern++; } /* for ... */ gwlist_destroy(word_list, octstr_destroy_item); return result; }
/* * Trans being NULL means that we are servicing ppg (doing dlr, but this does not * concern us here). */ Octstr *urltrans_get_pattern(URLTranslation *t, Msg *request) { Octstr *enc; int nextarg, j; struct tm tm; int num_words; List *word_list; Octstr *result, *pattern; long pattern_len; long pos; int c; long i; Octstr *temp; Octstr *url, *reply; /* For and If delivery report */ url = reply = NULL; if (request->sms.sms_type != report_mo && t->type == TRANSTYPE_SENDSMS) return octstr_create(""); if (request->sms.msgdata) { word_list = octstr_split_words(request->sms.msgdata); num_words = list_len(word_list); } else { word_list = list_create(); num_words = 0; } result = octstr_create(""); /* check if this is a delivery report message or not */ if (request->sms.sms_type != report_mo) { pattern = t->pattern; } else { /* this is a DLR message */ reply = octstr_duplicate(request->sms.msgdata); url = octstr_duplicate(request->sms.dlr_url); pattern = url; if (octstr_len(pattern) == 0) { if (t && octstr_len(t->dlr_url)) { pattern = t->dlr_url; } else { list_destroy(word_list, octstr_destroy_item); return octstr_create(""); } } } pattern_len = octstr_len(pattern); nextarg = 1; pos = 0; for (;;) { while (pos < pattern_len) { c = octstr_get_char(pattern, pos); if (c == '%' && pos + 1 < pattern_len) break; octstr_append_char(result, c); ++pos; } if (pos == pattern_len) break; switch (octstr_get_char(pattern, pos + 1)) { case 'k': if (num_words <= 0) break; enc = octstr_duplicate(list_get(word_list, 0)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 's': if (nextarg >= num_words) break; enc = octstr_duplicate(list_get(word_list, nextarg)); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); ++nextarg; break; case 'S': if (nextarg >= num_words) break; temp = list_get(word_list, nextarg); for (i = 0; i < octstr_len(temp); ++i) { if (octstr_get_char(temp, i) == '*') octstr_append_char(result, '~'); else octstr_append_char(result, octstr_get_char(temp, i)); } ++nextarg; break; case 'r': for (j = nextarg; j < num_words; ++j) { enc = octstr_duplicate(list_get(word_list, j)); octstr_url_encode(enc); if (j != nextarg) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; /* NOTE: the sender and receiver is already switched in * message, so that's why we must use 'sender' when * we want original receiver and vice versa */ case 'P': enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'p': enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'Q': if (strncmp(octstr_get_cstr(request->sms.sender), "00", 2) == 0) { enc = octstr_copy(request->sms.sender, 2, octstr_len(request->sms.sender)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.sender); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'q': if (strncmp(octstr_get_cstr(request->sms.receiver),"00",2)==0) { enc = octstr_copy(request->sms.receiver, 2, octstr_len(request->sms.receiver)); octstr_url_encode(enc); octstr_format_append(result, "%%2B%S", enc); octstr_destroy(enc); } else { enc = octstr_duplicate(request->sms.receiver); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'a': for (j = 0; j < num_words; ++j) { enc = octstr_duplicate(list_get(word_list, j)); octstr_url_encode(enc); if (j > 0) octstr_append_char(result, '+'); octstr_append(result, enc); octstr_destroy(enc); } break; case 'b': enc = octstr_duplicate(request->sms.msgdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 't': tm = gw_gmtime(request->sms.time); octstr_format_append(result, "%04d-%02d-%02d+%02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); break; case 'T': if (request->sms.time == MSG_PARAM_UNDEFINED) break; octstr_format_append(result, "%ld", request->sms.time); break; case 'i': if (request->sms.smsc_id == NULL) break; enc = octstr_duplicate(request->sms.smsc_id); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'I': if (!uuid_is_null(request->sms.id)) { char id[UUID_STR_LEN + 1]; uuid_unparse(request->sms.id, id); octstr_append_cstr(result, id); } break; case 'n': if (request->sms.service == NULL) break; enc = octstr_duplicate(request->sms.service); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'd': enc = octstr_create(""); octstr_append_decimal(enc, request->sms.dlr_mask); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); break; case 'A': if (reply) { enc = octstr_duplicate(reply); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'c': octstr_append_decimal(result, request->sms.coding); break; case 'C': if(octstr_len(request->sms.charset)) { octstr_append(result, request->sms.charset); } else { switch (request->sms.coding) { case DC_UNDEF: case DC_7BIT: octstr_append(result, octstr_imm("ISO-8859-1")); break; case DC_8BIT: octstr_append(result, octstr_imm("8-BIT")); break; case DC_UCS2: octstr_append(result, octstr_imm("UTF16-BE")); break; } } break; case 'u': if(octstr_len(request->sms.udhdata)) { enc = octstr_duplicate(request->sms.udhdata); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'B': /* billing identifier/information */ if (octstr_len(request->sms.binfo)) { enc = octstr_duplicate(request->sms.binfo); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; case 'o': /* account information (may be operator id for aggregators */ if (octstr_len(request->sms.account)) { enc = octstr_duplicate(request->sms.account); octstr_url_encode(enc); octstr_append(result, enc); octstr_destroy(enc); } break; /* XXX sms.parameters not present in here: * * pid - will we receive this ? * * mwi,mclass - will we receive these bits from smsc ? * * alt-dcs - shouldn't be required unless we want to inform * which alt-dcs external server should use back * * compress - if we use compression, probably kannel would * decompress and reset this to 0. not required * * validity, deferred, rpi - we don't receive these from smsc * * username, password, dlr-url, account - nonsense to send */ case '%': octstr_format_append(result, "%%"); break; default: octstr_format_append(result, "%%%c", octstr_get_char(pattern, pos + 1)); break; } pos += 2; } /* * this SHOULD be done in smsbox, not here, but well, * much easier to do here */ if (t && (t->type == TRANSTYPE_POST_URL || t->type == TRANSTYPE_POST_XML) && t->strip_keyword) strip_keyword(request); octstr_destroy(url); octstr_destroy(reply); list_destroy(word_list, octstr_destroy_item); return result; }