[PATCH]Indonesia Esia

sangprabv <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <1217288060.30846.2.camel@zilda>
Attached is added feature for Indonesia Esia HTTP SMSC.

--- gateway-1.4.1/gw/smsc/smsc_http.c 
+++ smsc_http.c 
@@ -142,6 +142,7 @@
     int no_coding;      /* this, too */
     int no_sep;         /* not to mention this */
     Octstr *proxy;      /* proxy a constant string */
+    Octstr *my_number;
 
     /* callback functions set by HTTP-SMSC type */
     void (*send_sms) (SMSCConn *conn, Msg *msg);
@@ -164,6 +165,7 @@
     octstr_destroy(conndata->password);
     octstr_destroy(conndata->proxy);
     octstr_destroy(conndata->system_id);
+    octstr_destroy(conndata->my_number);
 
     gw_free(conndata);
 }
@@ -1290,6 +1292,200 @@
     }
 }
 
+/*----------------------------------------------------------------
+ * Indonesia Esia
+ * Indirect Scheme
+ * Willy Mularto <[email protected]>
+ */
+
+/* Esia MT */
+static void esia_send_sms(SMSCConn *conn, Msg *sms)
+{
+    ConnData *conndata = conn->data;
+    Octstr *url;
+    List *headers;
+    
+    url = octstr_format("%S/?",
+        conndata->send_url);
+        
+     /* Get usr */
+    if (octstr_search(url, octstr_create("usr="), 0) == -1) {
+        octstr_format_append(url, "usr=%S", conndata->username);
+    }
+    /* Get pwd */
+    if (octstr_search(url, octstr_create("pwd="), 0) == -1) {
+        octstr_format_append(url, "&pwd=%S", conndata->password);
+    }
+    /* Get dn */
+    if (octstr_search(url, octstr_create("dn="), 0) == -1) {
+        octstr_format_append(url, "&dn=%S", sms->sms.receiver);
+    }
+    /* Get from */
+    if (octstr_search(url, octstr_create("from="), 0) == -1) {
+        octstr_format_append(url, "&from=%S", sms->sms.sender);
+    }
+    /* Get moid */
+    if (octstr_search(url, octstr_create("moid="), 0) == -1) {
+        octstr_format_append(url, "&moid=%S", sms->sms.binfo);
+    }
+    /* Get mtcode */
+    if (octstr_search(url, octstr_create("mtcode="), 0) == -1) {
+        octstr_format_append(url, "&mtcode=%d", sms->sms.account);
+    }
+    /* Get msg */
+    if (octstr_search(url, octstr_create("msg="), 0) == -1) {
+        octstr_format_append(url, "&msg=%E", sms->sms.msgdata);
+    }	
+    
+    sms->sms.dlr_mask = 31;
+    headers = gwlist_create();
+    debug("smsc.http.esia", 0, "HTTP[%s]: Start request",
+          octstr_get_cstr(conn->id));
+    http_start_request(conndata->http_ref, HTTP_METHOD_GET, url,
headers, 
+                       NULL, 0, sms, NULL);
+
+    octstr_destroy(url);
+    http_destroy_headers(headers);
+}
+
+/* Esia Parse HTTP DLR Response */
+static void esia_parse_reply(SMSCConn *conn, Msg *msg, int status,
+			       List *headers, Octstr *body)
+{
+	 Octstr *tid, *dest, *code, *desc;
+	 int dlrstat, ret, httpstatus = HTTP_UNAUTHORIZED;
+	 Msg *dlrmsg;
+	 List *reply_headers;
+	 
+	 tid = octstr_duplicate(msg->sms.binfo);
+    dest = octstr_duplicate(msg->sms.receiver);
+    if (DLR_IS_ENABLED_DEVICE(msg->sms.dlr_mask))
+                dlr_add(conn->id, tid, msg);
+                
+
+    /*SUCCESS*/
+      if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=0000"), 0) ==
0)) {    
+        dlrstat = 1;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*Server Error Try Again*/
+      else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=4444"), 0) ==
0)) {
+        dlrstat = 4;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*Not User Push SMS*/
+      else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=2222"), 0) ==
0)) {
+        dlrstat = 2;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*Wrong Username, Password and or Not Allowed IP*/
+      else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=1111"), 0) ==
0)) {
+        dlrstat = 16;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*MOID Empty*/
+      else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=1000"), 0) ==
0)) {
+        dlrstat = 16;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*MTCODE Empty*/
+      else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=2000"), 0) ==
0)) {
+        dlrstat = 16;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*MOID Wrong Format*/
+     else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=3000"), 0) ==
0)) {
+        dlrstat = 16;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+    /*MTCODE Wrong Format*/
+     else if ((status == HTTP_OK || status == HTTP_ACCEPTED)
+        && (octstr_case_search(body, octstr_imm("ERROR=4000"), 0) ==
0)) {
+        dlrstat = 16;
+        bb_smscconn_sent(conn, msg, NULL);
+    }
+      else {
+        bb_smscconn_send_failed(conn, msg,
+	            SMSCCONN_FAILED_MALFORMED, octstr_duplicate(body));
+    } 	 
+    	 dlrmsg = dlr_find(conn->id,
+            	tid, 
+            	dest , 
+            	dlrstat);
+            	
+        	if (dlrmsg != NULL) {
+         	
+           	dlrmsg->sms.sms_type = report_mo;
+
+	    		if (tid) {
+
+					dlrmsg->sms.binfo = octstr_duplicate(tid);
+	    		}
+	    		ret = bb_smscconn_receive(conn, dlrmsg);
+            httpstatus = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);
+         }          
+     octstr_destroy(tid);  
+}
+
+/* Esia MO */ 
+static void esia_receive_sms(SMSCConn *conn, HTTPClient *client,
+                               List *headers, Octstr *body, List
*cgivars)
+{
+    ConnData *conndata = conn->data;
+    Octstr *id, *dn, *to, *motext, *retmsg;
+    List *reply_headers;
+    int ret, httpstatus = HTTP_UNAUTHORIZED;
+
+
+
+    id = http_cgi_variable(cgivars, "id");
+    dn = http_cgi_variable(cgivars, "dn");
+    to = http_cgi_variable(cgivars, "to");
+    motext = http_cgi_variable(cgivars, "msg");
+
+    debug("smsc.http.esia", 0, "HTTP[%s]: Received a request",
+          octstr_get_cstr(conn->id));
+    
+    if (dn == NULL || motext == NULL) {
+        error(0, "HTTP[%s]: Insufficient args.",
+              octstr_get_cstr(conn->id));
+        retmsg = octstr_create("Insufficient arguments, rejected.");
+    }
+    else {
+        Msg *msg;
+        msg = msg_create(sms);
+        
+        debug("smsc.http.esia", 0, "HTTP[%s]: Incoming MO from[%s]to[%
s]text[%s]",
+            octstr_get_cstr(conn->id), octstr_get_cstr(dn),
octstr_get_cstr(to), octstr_get_cstr(motext));
+	
+        msg->sms.sender = octstr_duplicate(dn);
+        msg->sms.receiver = octstr_duplicate(to);
+        msg->sms.msgdata = octstr_duplicate(motext);
+        msg->sms.smsc_id = octstr_duplicate(conn->id);
+        msg->sms.time = time(NULL); 
+        msg->sms.binfo = octstr_duplicate(id);;
+
+        ret = bb_smscconn_receive(conn, msg);
+        httpstatus = (ret == 0 ? HTTP_OK : HTTP_FORBIDDEN);     
+    }
+    
+    reply_headers = gwlist_create();
+    
+    http_header_add(reply_headers, "Content-Type", "text/plain");
+    debug("smsc.http.esia", 0, "HTTP[%s]: Sending reply with HTTP
status <%d>.",
+          octstr_get_cstr(conn->id), httpstatus);
+
+    http_send_reply(client, httpstatus, reply_headers, NULL);
+    http_destroy_headers(reply_headers);
+}
+
 /*
  * static void wapme_smsproxy_receive_sms(SMSCConn *conn, HTTPClient
*client,
  *                                List *headers, Octstr *body, List
*cgivars)
@@ -1379,6 +1575,7 @@
     cfg_get_bool(&conndata->no_coding, cfg, octstr_imm("no-coding"));
     cfg_get_bool(&conndata->no_sep, cfg, octstr_imm("no-sep"));
     conndata->proxy = cfg_get(cfg, octstr_imm("system-id"));
+    conndata->my_number = cfg_get(cfg, octstr_imm("my-number"));
 
     if (conndata->send_url == NULL)
         panic(0, "HTTP[%s]: Sending not allowed. No 'send-url'
specified.",
@@ -1434,6 +1631,16 @@
 	conndata->send_sms = clickatell_send_sms;
 	conndata->parse_reply = clickatell_parse_reply;
     }
+    else if (octstr_case_compare(type, octstr_imm("esia")) == 0) {
+        if (conndata->username == NULL || conndata->password == NULL) {
+            error(0, "HTTP[%s]: 'username' and 'password' required for
Esia http smsc",
+                  octstr_get_cstr(conn->id));
+            goto error;
+        }
+        conndata->receive_sms = esia_receive_sms;
+        conndata->send_sms = esia_send_sms;
+        conndata->parse_reply = esia_parse_reply;
+    }
     /*
      * ADD NEW HTTP SMSC TYPES HERE
      */

Let me know for any bugs. TIA


Willy
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.