[patch] smsbox memory leaks and service header

"Angel Fradejas" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi all,

here's a patch for smsbox.c

1) a couple of memory leaks (msg->sms.udhdata and accepted_chars)
2) allow to change msg->sms.service via X-Kannel-Service header or xml tag

Cheers.

Angel Fradejas
Mediafusión España, S.A.
[email protected]
www.mediafusion.es
Tel. +34 91 252 32 00
Fax  +34 91 572 27 08
smsbox_service.patch (application/octet-stream, 6.2 KB)
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.199
diff -u -r1.199 smsbox.c
--- gw/smsbox.c	29 May 2002 12:27:21 -0000	1.199
+++ gw/smsbox.c	31 May 2002 16:06:23 -0000
@@ -291,7 +291,8 @@
 				      int *coding, int *compress, 
 				      int *validity, int *deferred, 
 				      int *dlr_mask, Octstr **dlr_url, 
-				      Octstr **account, int *pid, int *alt_dcs)
+				      Octstr **account, int *pid, int *alt_dcs, 
+				      Octstr **service)
 {
     Octstr *name, *val;
     long l;
@@ -376,6 +377,12 @@
 	else if (octstr_case_compare(name, octstr_imm("X-Kannel-DLR-Mask")) == 0) {
     	    sscanf(octstr_get_cstr(val),"%d", dlr_mask);
 	}
+	else if (octstr_case_compare(name, octstr_imm("X-Kannel-Service")) == 0) {
+	    if (service != NULL) {
+		*service = octstr_duplicate(val);
+		octstr_strip_blanks(*service);
+	    }
+	}
 	octstr_destroy(name);
 	octstr_destroy(val);
     }
@@ -431,6 +438,7 @@
                                   int *validity, int *deferred,
                                   int *dlr_mask, Octstr **dlr_url,
                                   Octstr **account, int *pid, int *alt_dcs,
+                                  Octstr **service,
                                   List **tolist)
 {                                    
 
@@ -460,6 +468,7 @@
  *       <user>...</user> ( or username)
  *       <pass>...</pass> ( or password)
  *       <account>...</account>
+ *       <service>...</service>
  *     </from>
  *     <to>smsc-id</to>
  *   </submit>
@@ -493,6 +502,8 @@
 
 	    /* account */
 	    get_tag(tmp, octstr_imm("account"), account, 0, 0);
+	    /* service */
+	    if (service) get_tag(tmp, octstr_imm("service"), service, 0, 0);
 	    O_DESTROY(tmp);
 	}
 
@@ -646,11 +657,22 @@
 			 int mclass, int mwi, int coding, int compress,
 			 int validity, int deferred,
 			 Octstr *dlr_url, int dlr_mask, int pid, int alt_dcs,
-			 Octstr *smsc)
+			 Octstr *smsc, Octstr *service)
 {    
     msg->sms.msgdata = replytext;
     msg->sms.time = time(NULL);
 
+    if (service != NULL) {
+	if (urltrans_accept_x_kannel_headers(trans)) {
+	    octstr_destroy(msg->sms.service);
+	    msg->sms.service = service;
+	} else {
+	    warning(0, "Tried to change service to '%s', denied.",
+		    octstr_get_cstr(service));
+	    octstr_destroy(service);
+	}
+    }
+
     if (dlr_url != NULL) {
 	if (urltrans_accept_x_kannel_headers(trans)) {
 	    octstr_destroy(msg->sms.dlr_url);
@@ -695,6 +717,7 @@
     }
     if (udh != NULL) {
 	if (urltrans_accept_x_kannel_headers(trans)) {
+	    octstr_destroy(msg->sms.udhdata);
 	    msg->sms.udhdata = udh;
 	} else {
 	    warning(0, "Tried to set UDH field, denied.");
@@ -787,6 +810,7 @@
     Octstr *dlr_url;
     Octstr *account;
     Octstr *smsc;
+    Octstr *service;
     int dlr_mask;
     int octets;
     int mclass, mwi, coding, compress, pid, alt_dcs;
@@ -808,7 +832,7 @@
     	
     	get_receiver(id, &msg, &trans);
 
-    	from = to = udh = smsc = NULL;
+    	from = to = udh = smsc = service = NULL;
 	octets = mclass = mwi = coding = compress = pid = alt_dcs = 0;
 	validity = deferred = 0;
 	account = NULL;
@@ -826,7 +850,7 @@
 					  NULL, NULL, &smsc, &mclass, &mwi, 
 					  &coding, &compress, &validity, 
 					  &deferred, &dlr_mask, &dlr_url, 
-					  &account, &pid, &alt_dcs);
+					  &account, &pid, &alt_dcs,&service);
 	    } else if (octstr_case_compare(type, text_plain) == 0) {
 		replytext = octstr_duplicate(reply_body);
                 octstr_destroy(reply_body);
@@ -836,7 +860,7 @@
 					  NULL, NULL, &smsc, &mclass, &mwi, 
 					  &coding, &compress, &validity, 
 					  &deferred, &dlr_mask, &dlr_url, 
-					  &account, &pid, &alt_dcs);
+					  &account, &pid, &alt_dcs,&service);
 	    } else if (octstr_case_compare(type, text_xml) == 0) {
 		replytext = octstr_duplicate(reply_body);
 		octstr_destroy(reply_body); 
@@ -844,7 +868,7 @@
 		get_x_kannel_from_xml(mt_reply, &type, &replytext, reply_headers, &from, &to, &udh,
 				NULL, NULL, &smsc, &mclass, &mwi, &coding,
 				&compress, &validity, &deferred,
-				&dlr_mask, &dlr_url, &account, &pid, &alt_dcs, NULL);
+				&dlr_mask, &dlr_url, &account, &pid, &alt_dcs, &service, NULL);
 	    } else if (octstr_case_compare(type, octet_stream) == 0) {
 		replytext = octstr_duplicate(reply_body);
                 octstr_destroy(reply_body);
@@ -854,7 +878,7 @@
 					  NULL, NULL, &smsc, &mclass, &mwi, 
 					  &coding, &compress, &validity, 
 					  &deferred, &dlr_mask, &dlr_url, 
-					  &account, &pid, &alt_dcs);
+					  &account, &pid, &alt_dcs, &service);
 	    } else {
 		replytext = octstr_duplicate(reply_couldnotrepresent); 
 	    }
@@ -869,7 +893,7 @@
 
 	fill_message(msg, trans, replytext, octets, from, to, udh, mclass,
 			mwi, coding, compress, validity, deferred, dlr_url, 
-			dlr_mask, pid, alt_dcs, smsc);
+			dlr_mask, pid, alt_dcs, smsc, service);
 
     	if (final_url == NULL)
 	    final_url = octstr_imm("");
@@ -2050,11 +2074,12 @@
     Octstr *type, *charset;
     Octstr *dlr_url;
     Octstr *account;
+    Octstr *service;
     List *tolist;
     int dlr_mask = 0;
     int mclass, mwi, coding, compress, validity, deferred, pid, alt_dcs;
  
-    from = to = user = pass = udh = smsc = dlr_url = account = NULL;
+    from = to = user = pass = udh = smsc = dlr_url = account = service = NULL;
     tolist = NULL;
    
     ret = NULL;
@@ -2066,12 +2091,12 @@
 	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, &tolist);
+			&account, &pid, &alt_dcs, &service, &tolist);
     } else {
 	get_x_kannel_from_headers(headers, &from, &to, &udh,
 			      &user, &pass, &smsc, &mclass, &mwi, &coding,
 			      &compress, &validity, &deferred, 
-			      &dlr_mask, &dlr_url, &account, &pid, &alt_dcs);
+			      &dlr_mask, &dlr_url, &account, &pid, &alt_dcs, &service);
     }
 
     /* check the username and password */
@@ -2922,6 +2947,7 @@
     counter_destroy(catenated_sms_counter);
     octstr_destroy(bb_host);
     octstr_destroy(global_sender);
+    octstr_destroy(accepted_chars);
     octstr_destroy(sendsms_url);
     octstr_destroy(sendota_url);
     octstr_destroy(xmlrpc_url);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.