[PATCH] SMPP command_status as meta-data
Alejandro Guerrieri <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <CAG8-fB=CxRogtx0=0sn=U3w31yxE2_xBwp50QW-weJDY981pOg@mail.gmail.com> |
Hi, Attached is a patch that allows passing the command_status on SMPP as meta-data, on the smpp_error_code parameter, so on the logs (and dlr-url) you'd get something like: *[META:?smpp?smpp_error_code=72&]* * * This would be command status value (which is 0 for accepted messages and a positive integer for any other outcome). This is based on some code Donald Jackson wrote for us time ago, and while this might prove useful for some people, after speaking with Stipe he mentioned that we can achieve similar results by parsing the %A parameter on the dlr-url. In that case, the possible outcomes right now are: *ACK/* *NACK/0xXXXXXXXX/Error text* In this case, for an accepted message, no numeric code is given. For a rejected message, 0xXXXXXXXX contains the hex value of the command_status After discussing for a little bit, Stipe pretty much talked us out of the idea of our patch because it's non-generic (only works for SMPP). However, %A is far from perfect as well: 1. It's inconsistent. No numeric value is provided on ACK's. 2. You cannot tell the protocol, so if you're load-balancing binds with different protocols you'd get different error codes with no way to correlate them by protocol. 3. It's not documented either. After a very healthy debate, we thought of the following approach, keeping the %A method: *ACK/SMPP:0x00000000/OK* *NACK/SMPP:0x00000048/Invalid Source address TON* This slightly breaks compatibility if you were already parsing the error code on the NACK's or doing an exact match on "ACK/" but imho is not a big deal. Thoughts? Ideas? Is it something other people would be interested into? Regards, Alex
kannel-command-status.patch
(application/octet-stream, 3.7 KB)
Index: gw/bb_smscconn.c
===================================================================
--- gw/bb_smscconn.c (revision 5010)
+++ gw/bb_smscconn.c (working copy)
@@ -93,6 +93,7 @@
#include "smscconn_p.h" /* to access counters */
#include "smsc/smpp_pdu.h" /* access smpp_pdu_init/smpp_pdu_shutdown */
+#include "meta_data.h"
/* passed from bearerbox core */
@@ -270,6 +271,7 @@
void bb_smscconn_sent(SMSCConn *conn, Msg *sms, Octstr *reply)
{
+ Dict *smpp_tlvs;
if (sms->sms.split_parts != NULL) {
handle_split(conn, sms, SMSCCONN_SUCCESS);
octstr_destroy(reply);
@@ -308,6 +310,16 @@
dlrmsg = create_dlr_from_msg((conn->id?conn->id:conn->name), sms,
reply, DLR_SMSC_SUCCESS);
if (dlrmsg != NULL) {
+ if(sms->sms.meta_data != NULL) {
+ smpp_tlvs = meta_data_get_values(sms->sms.meta_data, "smpp");
+ if(smpp_tlvs != NULL) {
+ if(dlrmsg->sms.meta_data == NULL) {
+ dlrmsg->sms.meta_data = octstr_create("");
+ }
+ meta_data_set_values(dlrmsg->sms.meta_data, smpp_tlvs, "smpp", 0);
+ }
+ dict_destroy(smpp_tlvs);
+ }
bb_smscconn_receive(conn, dlrmsg);
}
}
@@ -319,6 +331,7 @@
void bb_smscconn_send_failed(SMSCConn *conn, Msg *sms, int reason, Octstr *reply)
{
+ Dict *smpp_tlvs;
if (sms->sms.split_parts != NULL) {
handle_split(conn, sms, reason);
octstr_destroy(reply);
@@ -381,6 +394,16 @@
dlrmsg = create_dlr_from_msg((conn ? (conn->id?conn->id:conn->name) : NULL), sms,
reply, DLR_SMSC_FAIL);
if (dlrmsg != NULL) {
+ if(sms->sms.meta_data != NULL) {
+ smpp_tlvs = meta_data_get_values(sms->sms.meta_data, "smpp");
+ if(smpp_tlvs != NULL) {
+ if(dlrmsg->sms.meta_data == NULL) {
+ dlrmsg->sms.meta_data = octstr_create("");
+ }
+ meta_data_set_values(dlrmsg->sms.meta_data, smpp_tlvs, "smpp", 0);
+ }
+ dict_destroy(smpp_tlvs);
+ }
bb_smscconn_receive(conn, dlrmsg);
}
}
Index: gw/smsc/smpp_pdu.h
===================================================================
--- gw/smsc/smpp_pdu.h (revision 5010)
+++ gw/smsc/smpp_pdu.h (working copy)
@@ -226,6 +226,8 @@
SMPP_ESME_RINVBCASTCHANIND = 0x00000112,
};
+#define SMPP_ERROR_CODE "smpp_error_code"
+
/* initialize SMPP PDU */
int smpp_pdu_init(Cfg *cfg);
/* shutdown SMPP PDU */
Index: gw/smsc/smsc_smpp.c
===================================================================
@@ -1532,7 +1540,7 @@
long *pending_submits)
{
SMPP_PDU *resp = NULL;
- Octstr *os;
+ Octstr *os, *smpp_error_code;
Msg *msg = NULL, *dlrmsg=NULL;
struct smpp_msg *smpp_msg = NULL;
long reason, cmd_stat;
@@ -1680,6 +1688,15 @@
}
msg = smpp_msg->msg;
smpp_msg_destroy(smpp_msg, 0);
+
+ if(msg->sms.meta_data != NULL) {
+ octstr_destroy(msg->sms.meta_data);
+ }
+ msg->sms.meta_data = octstr_create("");
+ smpp_error_code = octstr_format("%lu", pdu->u.submit_sm_resp.command_status);
+ meta_data_set_value(msg->sms.meta_data, "smpp", octstr_imm(SMPP_ERROR_CODE), smpp_error_code, 1);
+ octstr_destroy(smpp_error_code);
+
if (pdu->u.submit_sm_resp.command_status != 0) {
error(0, "SMPP[%s]: SMSC returned error code 0x%08lx (%s) "
"in response to submit_sm.",