📄 smsbox.c
字号:
octstr_destroy(pattern); *result = octstr_read_pipe(f); pclose(f); alog("SMS request sender:%s request: '%s' file answer: '%s'", octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(msg->sms.msgdata), octstr_get_cstr(*result)); } else { error(0, "popen failed for '%s': %d: %s", octstr_get_cstr(pattern), errno, strerror(errno)); *result = NULL; octstr_destroy(pattern); return -1; } break; /* * No Kannel headers when we are sending dlrs to wap push */ case TRANSTYPE_GET_URL: request_headers = http_create_empty_headers(); http_header_add(request_headers, "User-Agent", GW_NAME "/" GW_VERSION); if (trans != 0) { if (urltrans_send_sender(trans)) { http_header_add(request_headers, "X-Kannel-From", octstr_get_cstr(msg->sms.receiver)); } } id = remember_receiver(msg, trans, HTTP_METHOD_GET, pattern, request_headers, NULL, 0); http_start_request(caller, HTTP_METHOD_GET, pattern, request_headers, NULL, 1, id, NULL); octstr_destroy(pattern); http_destroy_headers(request_headers); *result = NULL; return 0; case TRANSTYPE_POST_URL: request_headers = http_create_empty_headers(); http_header_add(request_headers, "User-Agent", GW_NAME "/" GW_VERSION); if (msg->sms.coding == DC_8BIT) http_header_add(request_headers, "Content-Type", "application/octet-stream"); else if(msg->sms.coding == DC_UCS2) http_header_add(request_headers, "Content-Type", "text/plain; charset=\"UTF-16BE\""); else { Octstr *header; header = octstr_create("text/plain"); if(msg->sms.charset) { octstr_append(header, octstr_imm("; charset=\"")); octstr_append(header, msg->sms.charset); octstr_append(header, octstr_imm("\"")); } http_header_add(request_headers, "Content-Type", octstr_get_cstr(header)); O_DESTROY(header); } if (urltrans_send_sender(trans)) http_header_add(request_headers, "X-Kannel-From", octstr_get_cstr(msg->sms.receiver)); http_header_add(request_headers, "X-Kannel-To", octstr_get_cstr(msg->sms.sender)); tm = gw_gmtime(msg->sms.time); sprintf(p, "%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); http_header_add(request_headers, "X-Kannel-Time", p); tm = gw_gmtime(time(NULL)); sprintf(p, "%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); http_header_add(request_headers, "Date", p); /* HTTP RFC 14.18 */ if (octstr_len(msg->sms.udhdata)) { Octstr *os; os = octstr_duplicate(msg->sms.udhdata); octstr_url_encode(os); http_header_add(request_headers, "X-Kannel-UDH", octstr_get_cstr(os)); octstr_destroy(os); } if (octstr_len(msg->sms.smsc_id)) { Octstr *os; os = octstr_duplicate(msg->sms.smsc_id); http_header_add(request_headers, "X-Kannel-SMSC", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.mclass != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.mclass); http_header_add(request_headers, "X-Kannel-MClass", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.pid != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.pid); http_header_add(request_headers, "X-Kannel-PID", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.rpi != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.rpi); http_header_add(request_headers, "X-Kannel-RPI", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.alt_dcs != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.alt_dcs); http_header_add(request_headers, "X-Kannel-Alt-DCS", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.mwi != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.mwi); http_header_add(request_headers, "X-Kannel-MWI", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.coding != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.coding); http_header_add(request_headers, "X-Kannel-Coding", octstr_get_cstr(os)); octstr_destroy(os); } if(msg->sms.compress != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.compress); http_header_add(request_headers, "X-Kannel-Compress", octstr_get_cstr(os)); octstr_destroy(os); } if (msg->sms.validity != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.validity); http_header_add(request_headers, "X-Kannel-Validity", octstr_get_cstr(os)); octstr_destroy(os); } if (msg->sms.deferred != SMS_PARAM_UNDEFINED) { Octstr *os; os = octstr_format("%d",msg->sms.deferred); http_header_add(request_headers, "X-Kannel-Deferred", octstr_get_cstr(os)); octstr_destroy(os); } if (octstr_len(msg->sms.service)) { Octstr *os; os = octstr_duplicate(msg->sms.service); http_header_add(request_headers, "X-Kannel-Service", octstr_get_cstr(os)); octstr_destroy(os); } if (octstr_len(msg->sms.binfo)) { Octstr *os; os = octstr_duplicate(msg->sms.binfo); http_header_add(request_headers, "X-Kannel-BInfo", octstr_get_cstr(os)); octstr_destroy(os); } id = remember_receiver(msg, trans, HTTP_METHOD_POST, pattern, request_headers, msg->sms.msgdata, 0); http_start_request(caller, HTTP_METHOD_POST, pattern, request_headers, msg->sms.msgdata, 1, id, NULL); octstr_destroy(pattern); http_destroy_headers(request_headers); *result = NULL; return 0; case TRANSTYPE_POST_XML:/* XXX The first two chars are beeing eaten somewhere and * only sometimes - something must be ungry */#define OCTSTR_APPEND_XML(xml, tag, text) \ octstr_format_append(xml, " \t\t<" tag ">%s</" tag ">\n", \ (text?octstr_get_cstr(text):""));#define OCTSTR_APPEND_XML_NUMBER(xml, tag, value) \ octstr_format_append(xml, " \t\t<" tag ">%ld</" tag ">\n", (long) value); request_headers = http_create_empty_headers(); http_header_add(request_headers, "User-Agent", GW_NAME "/" GW_VERSION); if(msg->sms.coding == DC_UCS2) { http_header_add(request_headers, "Content-Type", "text/xml; charset=\"ISO-8859-1\""); /* for account and other strings */ } else { Octstr *header; header = octstr_create("text/xml"); if(msg->sms.charset) { octstr_append(header, octstr_imm("; charset=\"")); octstr_append(header, msg->sms.charset); octstr_append(header, octstr_imm("\"")); } http_header_add(request_headers, "Content-Type", octstr_get_cstr(header)); O_DESTROY(header); } tm = gw_gmtime(time(NULL)); sprintf(p, "%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); http_header_add(request_headers, "Date", p); /* HTTP RFC 14.18 */ xml = octstr_create(""); octstr_append(xml, octstr_imm("<?xml version=\"1.0\" encoding=\"")); if(msg->sms.coding == DC_UCS2 || msg->sms.charset == NULL) octstr_append(xml, octstr_imm("ISO-8859-1")); else octstr_append(xml, msg->sms.charset); octstr_append(xml, octstr_imm("\"?>\n")); /* * XXX damn windows that breaks with this : * octstr_append(xml, octstr_imm("<!DOCTYPE message SYSTEM \"SMSmessage.dtd\">\n")); */ octstr_append(xml, octstr_imm("<message cid=\"1\">\n")); octstr_append(xml, octstr_imm("\t<submit>\n")); /* oa */ if(urltrans_send_sender(trans)) { tmp = octstr_create(""); OCTSTR_APPEND_XML(tmp, "number", msg->sms.receiver); OCTSTR_APPEND_XML(xml, "oa", tmp); octstr_destroy(tmp); } /* da */ tmp = octstr_create(""); OCTSTR_APPEND_XML(tmp, "number", msg->sms.sender); OCTSTR_APPEND_XML(xml, "da", tmp); octstr_destroy(tmp); /* udh */ if(octstr_len(msg->sms.udhdata)) { Octstr *t; t = octstr_duplicate(msg->sms.udhdata); octstr_url_encode(t); OCTSTR_APPEND_XML(xml, "udh", t); octstr_destroy(t); } /* ud */ if(octstr_len(msg->sms.msgdata)) { octstr_url_encode(msg->sms.msgdata); OCTSTR_APPEND_XML(xml, "ud", msg->sms.msgdata); } /* pid */ if(msg->sms.pid != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(xml, "pid", msg->sms.pid); /* rpi */ if(msg->sms.rpi != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(xml, "rpi", msg->sms.rpi); /* dcs */ tmp = octstr_create(""); if(msg->sms.coding != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "coding", msg->sms.coding); if(msg->sms.mclass != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "mclass", msg->sms.mclass); if(msg->sms.alt_dcs != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "alt-dcs", msg->sms.alt_dcs); if(msg->sms.mwi != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "mwi", msg->sms.mwi); if(msg->sms.compress != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "compress", msg->sms.compress); if(octstr_len(tmp)) OCTSTR_APPEND_XML(xml, "dcs", tmp) octstr_destroy(tmp); /* deferred (timing/delay) */ tmp = octstr_create(""); if(msg->sms.deferred != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "delay", msg->sms.deferred); if(octstr_len(tmp)) OCTSTR_APPEND_XML(xml, "timing", tmp) octstr_destroy(tmp); /* validity (vp/delay) */ tmp = octstr_create(""); if(msg->sms.validity != SMS_PARAM_UNDEFINED) OCTSTR_APPEND_XML_NUMBER(tmp, "delay", msg->sms.validity); if(octstr_len(tmp)) OCTSTR_APPEND_XML(xml, "vp", tmp) octstr_destroy(tmp); /* time (at) */ tm = gw_gmtime(msg->sms.time); tmp = octstr_format("<year>%04d</year><month>%02d</month>" "<day>%02d</day><hour>%02d</hour><minute>%02d</minute>" "<second>%02d</second><timezone>0</timezone>", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); OCTSTR_APPEND_XML(xml, "at", tmp); octstr_destroy(tmp); /* smsc */ if (octstr_len(msg->sms.smsc_id)) { tmp = octstr_create(""); if(octstr_len(msg->sms.smsc_id)) OCTSTR_APPEND_XML(tmp, "account", msg->sms.smsc_id); if(octstr_len(tmp)) OCTSTR_APPEND_XML(xml, "from", tmp); O_DESTROY(tmp); } /* service = to/service */ if(octstr_len(msg->sms.service)) { tmp = octstr_create(""); OCTSTR_APPEND_XML(tmp, "service", msg->sms.service); if(octstr_len(tmp)) OCTSTR_APPEND_XML(xml, "to", tmp); O_DESTROY(tmp); } /* End XML */ octstr_append(xml, octstr_imm("\t</submit>\n")); octstr_append(xml, octstr_imm("</message>\n")); if(msg->sms.msgdata != NULL) octstr_destroy(msg->sms.msgdata); msg->sms.msgdata = xml; debug("sms", 0, "XMLBuild: XML: <%s>", octstr_get_cstr(msg->sms.msgdata)); id = remember_receiver(msg, trans, HTTP_METHOD_POST, pattern, request_headers, msg->sms.msgdata, 0); http_start_request(caller, HTTP_METHOD_POST, pattern, request_headers, msg->sms.msgdata, 1, id, NULL); octstr_destroy(pattern); http_destroy_headers(request_headers); *result = NULL; return 0; case TRANSTYPE_SENDSMS: error(0, "Got URL translation type SENDSMS for incoming message."); alog("SMS request sender:%s request: '%s' FAILED bad translation", octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(msg->sms.msgdata)); octstr_destroy(pattern); return -1; default: error(0, "Unknown URL translation type %d", urltrans_type(trans)); alog("SMS request sender:%s request: '%s' FAILED unknown translation", octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(msg->sms.msgdata)); octstr_destroy(pattern); return -1; } return 1;}static void obey_request_thread(void *arg){ Msg *msg, *mack, *reply_msg; Octstr *tmp, *reply; URLTranslation *trans; Octstr *p; int ret, dreport=0; while ((msg = list_consume(smsbox_requests)) != NULL) { if (msg->sms.sms_type == report_mo) dreport = 1; else dreport = 0; /* Recode to iso-8859-1 the MO message if possible */ if (mo_recode && msg->sms.coding == DC_UCS2) { int converted = 0; Octstr *text; text = octstr_duplicate(msg->sms.msgdata); if(0 == octstr_recode (octstr_imm("iso-8859-1"), octstr_imm("UTF-16BE"), text)) { if(octstr_search(text, octstr_imm("&#"), 0) == -1) { /* XXX I'm trying to search for &#xxxx; text, which indicates that the * text couldn't be recoded. * We should use other function to do the recode or detect it using * other method */ info(0, "MO message converted from UCS2 to ISO-8859-1"); octstr_destroy(msg->sms.msgdata); msg->sms.msgdata = octstr_duplicate(text); msg->sms.charset = octstr_create("ISO-8859-1"); msg->sms.coding = DC_7BIT; converted=1; } else { octstr_destroy(text); text = octstr_duplicate(msg->sms.msgdata); } } if(!converted && 0 == octstr_recode (octstr_imm("UTF-8"), octstr_imm("UTF-16BE"), text)) { if(octstr_search(text, octstr_imm("&#"), 0) == -1) { /* XXX I'm trying to search for &#xxxx; text, which indicates that the * text couldn't be recoded. * We should use other function to do the recode or detect it using * other method */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -