📄 smsc_smpp.c
字号:
octstr_delete(pdu->u.submit_sm.destination_addr, 0,1); pdu->u.submit_sm.dest_addr_ton = GSM_ADDR_TON_INTERNATIONAL; } /* * set the data coding scheme (DCS) field * check if we have a forced value for this from the smsc-group. */ pdu->u.submit_sm.data_coding = fields_to_dcs(msg, (msg->sms.alt_dcs ? 2 - msg->sms.alt_dcs : smpp->alt_dcs)); /* set protocoll id */ if(msg->sms.pid) pdu->u.submit_sm.protocol_id = msg->sms.pid; /* * set the esm_class field * default is store and forward, plus udh and rpi if requested */ pdu->u.submit_sm.esm_class = ESM_CLASS_SUBMIT_STORE_AND_FORWARD_MODE; if (octstr_len(msg->sms.udhdata)) pdu->u.submit_sm.esm_class = pdu->u.submit_sm.esm_class | ESM_CLASS_SUBMIT_UDH_INDICATOR; if (msg->sms.rpi) pdu->u.submit_sm.esm_class = pdu->u.submit_sm.esm_class | ESM_CLASS_SUBMIT_RPI; /* * set data segments */ if (octstr_len(msg->sms.udhdata)) { pdu->u.submit_sm.short_message = octstr_format("%S%S", msg->sms.udhdata, msg->sms.msgdata); } else { pdu->u.submit_sm.short_message = octstr_duplicate(msg->sms.msgdata); if (pdu->u.submit_sm.data_coding == 0 ) /* no reencoding for unicode! */ charset_latin1_to_gsm(pdu->u.submit_sm.short_message); } /* * check for validity and defered settings */ if (msg->sms.validity || msg->sms.deferred) { /* work out 1/4 hour difference between local time and UTC/GMT */ gmtime = gw_gmtime(time(NULL)); localtime = gw_localtime(time(NULL)); gwqdiff = ((localtime.tm_hour - gmtime.tm_hour) * 4) + ((localtime.tm_min - gmtime.tm_min) / 15); if (gwqdiff >= 0) { relation_UTC_time = octstr_create("+"); } else { relation_UTC_time = octstr_create("-"); gwqdiff *= -1; /* make absolute */ } if (msg->sms.validity) { tm = gw_localtime(time(NULL) + msg->sms.validity * 60); buffer = octstr_format("%02d%02d%02d%02d%02d%02d0%02d%1s", tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, gwqdiff, octstr_get_cstr(relation_UTC_time)); pdu->u.submit_sm.validity_period = octstr_copy(buffer,0,16); octstr_destroy(buffer); } if (msg->sms.deferred) { tm = gw_localtime(time(NULL) + msg->sms.deferred * 60); buffer = octstr_format("%02d%02d%02d%02d%02d%02d0%02d%1s", tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, gwqdiff, octstr_get_cstr(relation_UTC_time)); pdu->u.submit_sm.schedule_delivery_time = octstr_copy(buffer,0,16); octstr_destroy(buffer); } } /* ask for the delivery reports if needed */ if (msg->sms.dlr_mask & (DLR_SUCCESS|DLR_FAIL)) pdu->u.submit_sm.registered_delivery = 1; octstr_destroy(relation_UTC_time); /* set priority */ if (smpp->priority >= 0 && smpp->priority <= 5) { pdu->u.submit_sm.priority_flag = smpp->priority; } else { /* default priority is 0 */ pdu->u.submit_sm.priority_flag = 0; } return pdu; } static void send_enquire_link(SMPP *smpp, Connection *conn, long *last_sent) { SMPP_PDU *pdu; Octstr *os; if (date_universal_now() - *last_sent < smpp->enquire_link_interval) return; *last_sent = date_universal_now(); pdu = smpp_pdu_create(enquire_link, counter_increase(smpp->message_id_counter)); dump_pdu("Sending enquire link:", smpp->conn->id, pdu); os = smpp_pdu_pack(pdu); if (os) conn_write(conn, os); /* Write errors checked by caller. */ octstr_destroy(os); smpp_pdu_destroy(pdu); } static void send_unbind(SMPP *smpp, Connection *conn){ SMPP_PDU *pdu; Octstr *os; pdu = smpp_pdu_create(unbind, counter_increase(smpp->message_id_counter)); dump_pdu("Sending unbind:", smpp->conn->id, pdu); os = smpp_pdu_pack(pdu); conn_write(conn, os); octstr_destroy(os); smpp_pdu_destroy(pdu);}static int send_pdu(Connection *conn, Octstr *id, SMPP_PDU *pdu) { Octstr *os; int ret; dump_pdu("Sending PDU:", id, pdu); os = smpp_pdu_pack(pdu); if (os) ret = conn_write(conn, os); /* Caller checks for write errors later */ else ret = -1; octstr_destroy(os); return ret; } static void send_messages(SMPP *smpp, Connection *conn, long *pending_submits) { Msg *msg; SMPP_PDU *pdu; Octstr *os; if (*pending_submits == -1) return; while (*pending_submits < smpp->max_pending_submits) { /* Get next message, quit if none to be sent */ msg = list_extract_first(smpp->msgs_to_send); if (msg == NULL) break; /* Send PDU, record it as waiting for ack from SMS center */ pdu = msg_to_pdu(smpp, msg); os = octstr_format("%ld", pdu->u.submit_sm.sequence_number); dict_put(smpp->sent_msgs, os, msg); octstr_destroy(os); send_pdu(conn, smpp->conn->id, pdu); smpp_pdu_destroy(pdu); ++(*pending_submits); } } /* * Open transmission connection to SMS center. Return NULL for error, * open Connection for OK. Caller must set smpp->conn->status correctly * before calling this. */ static Connection *open_transmitter(SMPP *smpp) { SMPP_PDU *bind; Connection *conn; conn = conn_open_tcp(smpp->host, smpp->transmit_port, smpp->our_host ); if (conn == NULL) { error(0, "SMPP[%s]: Couldn't connect to server.", octstr_get_cstr(smpp->conn->id)); return NULL; } bind = smpp_pdu_create(bind_transmitter, counter_increase(smpp->message_id_counter)); bind->u.bind_transmitter.system_id = octstr_duplicate(smpp->username); bind->u.bind_transmitter.password = octstr_duplicate(smpp->password); if (smpp->system_type == NULL) bind->u.bind_transmitter.system_type = octstr_create("VMA"); else bind->u.bind_transmitter.system_type = octstr_duplicate(smpp->system_type); bind->u.bind_transmitter.interface_version = smpp->version; bind->u.bind_transmitter.address_range = octstr_duplicate(smpp->address_range); send_pdu(conn, smpp->conn->id, bind); smpp_pdu_destroy(bind); return conn; } /* * Open transceiver connection to SMS center. Return NULL for error, * open Connection for OK. Caller must set smpp->conn->status correctly * before calling this. */ static Connection *open_transceiver(SMPP *smpp) { SMPP_PDU *bind; Connection *conn; conn = conn_open_tcp(smpp->host, smpp->transmit_port, smpp->our_host ); if (conn == NULL) { error(0, "SMPP[%s]: Couldn't connect to server.", octstr_get_cstr(smpp->conn->id)); return NULL; } bind = smpp_pdu_create(bind_transceiver, counter_increase(smpp->message_id_counter)); bind->u.bind_transmitter.system_id = octstr_duplicate(smpp->username); bind->u.bind_transmitter.password = octstr_duplicate(smpp->password); if (smpp->system_type == NULL) bind->u.bind_transmitter.system_type = octstr_create("VMA"); else bind->u.bind_transmitter.system_type = octstr_duplicate(smpp->system_type); bind->u.bind_transmitter.interface_version = smpp->version; bind->u.bind_transmitter.address_range = octstr_duplicate(smpp->address_range); send_pdu(conn, smpp->conn->id, bind); smpp_pdu_destroy(bind); return conn; } /* * Open reception connection to SMS center. Return NULL for error, * open Connection for OK. Caller must set smpp->conn->status correctly * before calling this. */ static Connection *open_receiver(SMPP *smpp) { SMPP_PDU *bind; Connection *conn; conn = conn_open_tcp(smpp->host, smpp->receive_port, smpp->our_host ); if (conn == NULL) { error(0, "SMPP[%s]: Couldn't connect to server.", octstr_get_cstr(smpp->conn->id)); return NULL; } bind = smpp_pdu_create(bind_receiver, counter_increase(smpp->message_id_counter)); bind->u.bind_receiver.system_id = octstr_duplicate(smpp->username); bind->u.bind_receiver.password = octstr_duplicate(smpp->password); if (smpp->system_type == NULL) bind->u.bind_receiver.system_type = octstr_create("VMA"); else bind->u.bind_receiver.system_type = octstr_duplicate(smpp->system_type); bind->u.bind_receiver.interface_version = smpp->version; bind->u.bind_receiver.address_range = octstr_duplicate(smpp->address_range); send_pdu(conn, smpp->conn->id, bind); smpp_pdu_destroy(bind); return conn; } static void handle_pdu(SMPP *smpp, Connection *conn, SMPP_PDU *pdu, long *pending_submits) { SMPP_PDU *resp; Octstr *os; Msg *msg, *dlrmsg=NULL; long reason; resp = NULL; switch (pdu->type) { case deliver_sm: /* XXX UDH */ /* * bb_smscconn_receive can fail, but we ignore that since we * have no way to usefull tell the SMS center about this * (no suitable error code for the deliver_sm_resp is defined) */ /* got a deliver ack (DLR)? */ if ((pdu->u.deliver_sm.esm_class == 0x02 || pdu->u.deliver_sm.esm_class == 0x04)) { Octstr *respstr; Octstr *msgid = NULL; Octstr *stat = NULL; int dlrstat; long curr = 0, vpos = 0; debug("bb.sms.smpp",0,"SMPP[%s] handle_pdu, got DLR", octstr_get_cstr(smpp->conn->id)); respstr = pdu->u.deliver_sm.short_message; /* get server message id */ if ((curr = octstr_search(respstr, octstr_imm("id:"), 0)) != -1) { vpos = octstr_search_char(respstr, ' ', curr); if ((vpos-curr >0) && (vpos != -1)) msgid = octstr_copy(respstr, curr+3, vpos-curr-3); } else { msgid = NULL; } /* get err & status code */ if ((curr = octstr_search(respstr, octstr_imm("stat:"), 0)) != -1) { vpos = octstr_search_char(respstr, ' ', curr); if ((vpos-curr >0) && (vpos != -1)) stat = octstr_copy(respstr, curr+5, vpos-curr-5); } else { stat = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -