[PATCH] allow setting of sms priority
Alexander Malysh <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi List, attahced you can find patch that allow setting of sms priority flag in smsbox and smpp module. Also fixes wrong priority setting in smpp module and documents 'priority' flag and some missing params in userguide. Comments/votes please! -- Thanks, Alex
priority-flag.diff
(text/x-diff, 15.1 KB)
Index: gw/msg-decl.h
===================================================================
RCS file: /home/cvs/gateway/gw/msg-decl.h,v
retrieving revision 1.28
diff -a -u -p -r1.28 msg-decl.h
--- gw/msg-decl.h 28 Aug 2004 18:09:19 -0000 1.28
+++ gw/msg-decl.h 30 Aug 2004 11:42:41 -0000
@@ -105,6 +105,7 @@ MSG(sms,
OCTSTR(binfo);
INTEGER(msg_left);
VOID(split_parts);
+ INTEGER(priority);
})
MSG(ack,
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.251
diff -a -u -p -r1.251 smsbox.c
--- gw/smsbox.c 28 Aug 2004 18:09:19 -0000 1.251
+++ gw/smsbox.c 30 Aug 2004 11:42:42 -0000
@@ -440,7 +440,7 @@ static void get_x_kannel_from_headers(Li
int *validity, int *deferred,
int *dlr_mask, Octstr **dlr_url,
Octstr **account, int *pid, int *alt_dcs,
- int *rpi, Octstr **binfo)
+ int *rpi, Octstr **binfo, int *priority)
{
Octstr *name, *val;
long l;
@@ -527,6 +527,9 @@ static void get_x_kannel_from_headers(Li
else if (octstr_case_compare(name, octstr_imm("X-Kannel-RPI")) == 0) {
sscanf(octstr_get_cstr(val),"%d", rpi);
}
+ else if (octstr_case_compare(name, octstr_imm("X-Kannel-Priority")) == 0) {
+ sscanf(octstr_get_cstr(val),"%d", priority);
+ }
octstr_destroy(name);
octstr_destroy(val);
}
@@ -583,7 +586,7 @@ static void get_x_kannel_from_xml(int re
int *dlr_mask, Octstr **dlr_url,
Octstr **account, int *pid, int *alt_dcs,
int *rpi, List **tolist, Octstr **charset,
- Octstr **binfo)
+ Octstr **binfo, int *priority)
{
Octstr *text, *tmp, *tmp2;
@@ -750,6 +753,14 @@ static void get_x_kannel_from_xml(int re
O_DESTROY(tmp);
}
+ /* priority */
+ get_tag(*body, octstr_imm("priority"), &tmp, 0, 0);
+ if(tmp) {
+ if(octstr_parse_long(&tmplong, tmp, 0, 10) != -1)
+ *priority = tmplong;
+ O_DESTROY(tmp);
+ }
+
/* charset from <?xml...encoding=?> */
tmp = find_charset_encoding(*body);
O_DESTROY(*charset);
@@ -789,7 +800,7 @@ static void fill_message(Msg *msg, URLTr
int validity, int deferred,
Octstr *dlr_url, int dlr_mask, int pid, int alt_dcs,
int rpi, Octstr *smsc, Octstr *account,
- Octstr *charset, Octstr *binfo)
+ Octstr *charset, Octstr *binfo, int priority)
{
msg->sms.msgdata = replytext;
msg->sms.time = time(NULL);
@@ -941,6 +952,12 @@ static void fill_message(Msg *msg, URLTr
}
}
+ if (priority != SMS_PARAM_UNDEFINED) {
+ if (urltrans_accept_x_kannel_headers(trans))
+ msg->sms.priority = priority;
+ else
+ warning(0, "Tried to change priority to '%d', denied.", priority);
+ }
}
@@ -1018,7 +1035,7 @@ static void url_result_thread(void *arg)
Octstr *reply_body, *charset;
Octstr *udh, *from, *to, *dlr_url, *account, *smsc, *binfo;
int dlr_mask, mclass, mwi, coding, compress, pid, alt_dcs, rpi;
- int validity, deferred;
+ int validity, deferred, priority;
text_html = octstr_imm("text/html");
text_wml = octstr_imm("text/vnd.wap.wml");
@@ -1034,9 +1051,9 @@ static void url_result_thread(void *arg)
break;
octets = 0;
- from = to = udh = smsc = dlr_url = account = binfo = charset = NULL;
- mclass = mwi = coding = compress = pid = alt_dcs = rpi = dlr_mask
- = validity = deferred = -1;
+ from = to = udh = smsc = dlr_url = account = binfo = charset = NULL;
+ mclass = mwi = coding = compress = pid = alt_dcs = rpi = dlr_mask
+ = validity = deferred = priority = SMS_PARAM_UNDEFINED;
get_receiver(id, &msg, &trans, &method, &req_url, &req_headers, &req_body, &retries);
@@ -1054,7 +1071,7 @@ static void url_result_thread(void *arg)
&coding, &compress, &validity,
&deferred, &dlr_mask, &dlr_url,
&account, &pid, &alt_dcs, &rpi,
- &binfo);
+ &binfo, &priority);
} else if (octstr_case_compare(type, text_plain) == 0) {
replytext = octstr_duplicate(reply_body);
octstr_destroy(reply_body);
@@ -1064,7 +1081,7 @@ static void url_result_thread(void *arg)
&coding, &compress, &validity,
&deferred, &dlr_mask, &dlr_url,
&account, &pid, &alt_dcs, &rpi,
- &binfo);
+ &binfo, &priority);
} else if (octstr_case_compare(type, text_xml) == 0) {
replytext = octstr_duplicate(reply_body);
octstr_destroy(reply_body);
@@ -1073,7 +1090,7 @@ static void url_result_thread(void *arg)
&from, &to, &udh, NULL, NULL, &smsc, &mclass, &mwi,
&coding, &compress, &validity, &deferred, &dlr_mask,
&dlr_url, &account, &pid, &alt_dcs, &rpi, NULL, &charset,
- &binfo);
+ &binfo, &priority);
} else if (octstr_case_compare(type, octet_stream) == 0) {
replytext = octstr_duplicate(reply_body);
octstr_destroy(reply_body);
@@ -1084,7 +1101,7 @@ static void url_result_thread(void *arg)
&coding, &compress, &validity,
&deferred, &dlr_mask, &dlr_url,
&account, &pid, &alt_dcs, &rpi,
- &binfo);
+ &binfo, &priority);
} else {
replytext = octstr_duplicate(reply_couldnotrepresent);
}
@@ -1104,7 +1121,7 @@ static void url_result_thread(void *arg)
fill_message(msg, trans, replytext, octets, from, to, udh, mclass,
mwi, coding, compress, validity, deferred, dlr_url,
dlr_mask, pid, alt_dcs, rpi, smsc, account, charset,
- binfo);
+ binfo, priority);
if (final_url == NULL)
final_url = octstr_imm("");
@@ -1866,7 +1883,7 @@ static Octstr *smsbox_req_handle(URLTran
int validity, int deferred,
int *status, int dlr_mask, Octstr *dlr_url,
Octstr *account, int pid, int alt_dcs, int rpi,
- List *receiver, Octstr *binfo)
+ List *receiver, Octstr *binfo, int priority)
{
Msg *msg = NULL;
Octstr *newfrom, *returnerror, *receiv;
@@ -2154,6 +2171,13 @@ static Octstr *smsbox_req_handle(URLTran
goto fielderror;
}
msg->sms.deferred = deferred;
+
+ if (priority != SMS_PARAM_UNDEFINED && (priority < 0 || priority > 3)) {
+ returnerror = octstr_create("Priority field misformed, rejected");
+ goto fielderror;
+ }
+ msg->sms.priority = priority;
+
/* new smsc-id argument - we should check this one, if able,
but that's advanced logics -- Kalle */
@@ -2362,11 +2386,11 @@ static Octstr *smsbox_req_sendsms(List *
Octstr *from, *to, *charset, *text, *udh, *smsc, *dlr_url, *account;
Octstr *binfo;
int dlr_mask, mclass, mwi, coding, compress, validity, deferred, pid;
- int alt_dcs, rpi;
+ int alt_dcs, rpi, priority;
from = to = udh = text = smsc = account = dlr_url = charset = binfo = NULL;
mclass = mwi = coding = compress = validity = deferred = dlr_mask =
- pid = alt_dcs = rpi = -1;
+ pid = alt_dcs = rpi = priority = SMS_PARAM_UNDEFINED;
/* check the username and password */
t = authorise_user(args, client_ip);
@@ -2434,6 +2458,10 @@ static Octstr *smsbox_req_sendsms(List *
if(tmp_string != NULL)
sscanf(octstr_get_cstr(tmp_string),"%d", &deferred);
+ tmp_string = http_cgi_variable(args, "priority");
+ if(tmp_string != NULL)
+ sscanf(octstr_get_cstr(tmp_string),"%d", &priority);
+
/*
* we required "to" to be defined
*/
@@ -2452,7 +2480,7 @@ static Octstr *smsbox_req_sendsms(List *
return smsbox_req_handle(t, client_ip, from, to, text, charset, udh,
smsc, mclass, mwi, coding, compress, validity,
deferred, status, dlr_mask, dlr_url, account,
- pid, alt_dcs, rpi, NULL, binfo);
+ pid, alt_dcs, rpi, NULL, binfo, priority);
}
@@ -2471,7 +2499,7 @@ static Octstr *smsbox_sendsms_post(List
Octstr *text;
Octstr *from, *to, *udh, *smsc, *charset, *dlr_url, *account, *binfo;
int dlr_mask, mclass, mwi, coding, compress, validity, deferred;
- int pid, alt_dcs, rpi;
+ int pid, alt_dcs, rpi, priority;
text_html = octstr_imm("text/html");
text_wml = octstr_imm("text/vnd.wap.wml");
@@ -2483,7 +2511,7 @@ static Octstr *smsbox_sendsms_post(List
tolist = NULL;
from = to = udh = smsc = account = dlr_url = charset = binfo = NULL;
mclass = mwi = coding = compress = validity = deferred = dlr_mask =
- pid = alt_dcs = rpi = -1;
+ pid = alt_dcs = rpi = priority = SMS_PARAM_UNDEFINED;
http_header_get_content_type(headers, &type, &charset);
if (octstr_case_compare(type, text_html) == 0 ||
@@ -2497,7 +2525,7 @@ static Octstr *smsbox_sendsms_post(List
&coding, &compress, &validity,
&deferred, &dlr_mask, &dlr_url,
&account, &pid, &alt_dcs, &rpi,
- &binfo);
+ &binfo, &priority);
} else if (octstr_case_compare(type, text_plain) == 0 ||
octstr_case_compare(type, octet_stream) == 0) {
get_x_kannel_from_headers(headers, &from, &to, &udh,
@@ -2505,13 +2533,13 @@ static Octstr *smsbox_sendsms_post(List
&coding, &compress, &validity,
&deferred, &dlr_mask, &dlr_url,
&account, &pid, &alt_dcs, &rpi,
- &binfo);
+ &binfo, &priority);
} else if (octstr_case_compare(type, text_xml) == 0) {
get_x_kannel_from_xml(mt_push, &type, &body, headers,
&from, &to, &udh, &user, &pass, &smsc, &mclass,
&mwi, &coding, &compress, &validity, &deferred,
&dlr_mask, &dlr_url, &account, &pid, &alt_dcs,
- &rpi, &tolist, &charset, &binfo);
+ &rpi, &tolist, &charset, &binfo, &priority);
} else {
*status = HTTP_BAD_REQUEST;
ret = octstr_create("Invalid content-type");
@@ -2562,7 +2590,7 @@ static Octstr *smsbox_sendsms_post(List
udh, smsc, mclass, mwi, coding, compress,
validity, deferred, status, dlr_mask,
dlr_url, account, pid, alt_dcs, rpi, tolist,
- binfo);
+ binfo, priority);
}
error2:
Index: doc/userguide/userguide.xml
===================================================================
RCS file: /home/cvs/gateway/doc/userguide/userguide.xml,v
retrieving revision 1.282
diff -a -u -p -r1.282 userguide.xml
--- doc/userguide/userguide.xml 30 Aug 2004 10:31:51 -0000 1.282
+++ doc/userguide/userguide.xml 30 Aug 2004 11:42:47 -0000
@@ -5871,6 +5871,9 @@ text = "No action specified"
<row><entry><literal>mwi</literal></entry>
<entry><literal>X-Kannel-MWI</literal></entry></row>
+ <row><entry><literal>compress</literal></entry>
+ <entry><literal>X-Kannel-Compress</literal></entry></row>
+
<row><entry><literal>coding</literal></entry>
<entry><literal>X-Kannel-Coding</literal>. If unset, defaults to 1
(7 bits) if <literal>Content-Type</literal> is <literal>text/plain
@@ -5901,6 +5904,15 @@ text = "No action specified"
<row><entry><literal>alt-dcs</literal></entry>
<entry><literal>X-Kannel-Alt-DCS</literal></entry></row>
+ <row><entry><literal>binfo</literal></entry>
+ <entry><literal>X-Kannel-BInfo</literal></entry></row>
+
+ <row><entry><literal>rpi</literal></entry>
+ <entry><literal>X-Kannel-RPI</literal></entry></row>
+
+ <row><entry><literal>priority</literal></entry>
+ <entry><literal>X-Kannel-Priority</literal></entry></row>
+
</tbody>
</tgroup>
</table>
@@ -6747,6 +6759,12 @@ the Kannel configuration, or 'Authorizat
plus 0xC0 if <literal>text</literal> field is not empty.</para> </footnote>
</entry></row>
+ <row><entry><literal>compress</literal></entry>
+ <entry><literal>number</literal></entry>
+ <entry valign="bottom">
+ Optional. Sets the Compression bit in DCS Field.
+ </entry></row>
+
<row><entry><literal>coding</literal></entry>
<entry><literal>number</literal></entry>
<entry valign="bottom">
@@ -6825,7 +6843,7 @@ the Kannel configuration, or 'Authorizat
Optional. Sets the Return Path Indicator (RPI) value. (See ETSI Documentation).
</entry></row>
- <row><entry><literal>account</literal></entry>
+ <row><entry><literal>account</literal></entry>
<entry>string</entry>
<entry valign="bottom">
Optional. Account name or number to carry forward for billing purposes.
@@ -6834,16 +6852,22 @@ the Kannel configuration, or 'Authorizat
but wants to distinguish them in the log. In the case of a HTTP SMSC
type the account name is prepended with the service-name (username) and a colon (:)
and forwarded to the next instance of Kannel. This allows hierarchical accounting.
- </entry></row>
+ </entry></row>
- <row><entry><literal>binfo</literal></entry>
+ <row><entry><literal>binfo</literal></entry>
<entry>string</entry>
<entry valign="bottom">
Optional. Billing identifier/information proxy field used to pass arbitrary
billing transaction IDs or information to the specific SMSC modules. For EMI2 this
is encapsulated into the XSer 0c field, for SMPP this is encapsulated into the
service_type of the submit_sm PDU.
- </entry></row>
+ </entry></row>
+
+ <row><entry><literal>priority</literal></entry>
+ <entry>number</literal></entry>
+ <entry valign="bottom">
+ Optional. Sets the Priority value (range 0-3 is allowed).
+ </entry></row>
</tbody>
</tgroup>
Index: gw/smsc/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_smpp.c,v
retrieving revision 1.72
diff -a -u -p -r1.72 smsc_smpp.c
--- gw/smsc/smsc_smpp.c 30 Aug 2004 10:33:58 -0000 1.72
+++ gw/smsc/smsc_smpp.c 30 Aug 2004 11:42:48 -0000
@@ -505,6 +505,9 @@ static Msg *pdu_to_msg(SMPP *smpp, SMPP_
}
msg->sms.pid = pdu->u.deliver_sm.protocol_id;
+ /* set priority flag */
+ msg->sms.priority = pdu->u.deliver_sm.priority_flag;
+
return msg;
error:
@@ -727,12 +730,10 @@ static SMPP_PDU *msg_to_pdu(SMPP *smpp,
octstr_destroy(relation_UTC_time);
/* set priority */
- if (smpp->priority >= 0 && smpp->priority <= 5) {
+ if (msg->sms.priority >= 0 && msg->sms.priority <= 3)
+ pdu->u.submit_sm.priority_flag = msg->sms.priority;
+ else
pdu->u.submit_sm.priority_flag = smpp->priority;
- } else {
- /* default priority is 0 */
- pdu->u.submit_sm.priority_flag = 0;
- }
/* set more messages to send */
if (smpp->version > 0x33 && msg->sms.msg_left > 0)
@@ -1842,6 +1843,8 @@ int smsc_smpp_create(SMSCConn *conn, Cfg
/* check for any specified priority value in range [0-5] */
if (cfg_get_integer(&priority, grp, octstr_imm("priority")) == -1)
priority = SMPP_DEFAULT_PRIORITY;
+ else if (priority < 0 || priority > 3)
+ panic(0, "SMPP: Invalid value for priority directive in configuraton (allowed range 0-3).");
/* set the msg_id type variable for this SMSC */
if (cfg_get_integer(&smpp_msg_id_type, grp, octstr_imm("msg-id-type")) == -1) {