RE: timestamps, scripts and nokia 7110

"Malmström, Dennis" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Oops, I forgot to eclose the changes.


/Dennis


-----Original Message-----
From:	Malmström, Dennis
Sent:	Thu 2002-02-07 14:01
To:	[email protected]
Cc:	
Subject:	timestamps, scripts and nokia 7110

Hello

  I've been using kannel (version 1.0.3) to implement a prototype sms gateway. This has required some changes to the source code. I case any of them are of
  value to the kannel project I hereby submit them.

  Be aware that I have not gained overall understanding of the code. The purpose of the changes have been to solve my particular problems as quickly as
  possible. This should be taken into account when considering the changes (no guarantees).



  The changes I made are:

  1) Added three escape codes:
          %z, skips a word.
          %A, same as %a but without url encoding.
          %R, same as %r but without url encoding.

  2) Added the possibility of executing a command line instead of fetching an url.
     Configuration file example:
          group = sms-service
          keyword = default
          execute = <command line>

  3) Added modemtype nokia7110.
     I started out using the modemtype premicell (which I somehow gathered was nokia related).
     Getting it to work required a few changes to the GSM modem handling code (gw/smsc_at.c).
     I created a new modemtype so I wouldn't change the definition of an existing one.

  4) Fixed broken timestamp parser.
     I am not sure wether this is a general issue or specific to nokia 7110.
     Anyway, the existing code produced nonsense values for the data sent from a nokia 7110.



  The following source code files where changed:

  file                    change
  ----                    ------
  gwlib/octstr.h
  gwlib/octstr.c          Added function for reading Octstr from FILE*. Used by gw/smsbox_req.c.

  gw/smsbox_req.c         (2)

  gw/smsc_at.c            (3)
                          (4)

  gw/urltrans.c           (1)
                          (2)


          /Dennis

  Dennis Malmström
  Erda Technology AB
  S:t Larsgatan 12, 582 24 Linköping, Sweden
  http://www.erda.se
  mail: [email protected]
  phone: +46 (0)13 377218
  gsm: +46 (0)706483090
octstr.c.diff (application/octet-stream, 1.2 KB)
--- octstr.c	Wed Feb  6 09:54:12 2002
+++ ../../org/gateway-1.0.3/gwlib/octstr.c	Mon Feb  5 11:26:21 2001
@@ -1202,12 +1202,22 @@
 }
 
 
-Octstr *octstr_read(FILE *f)
+
+Octstr *octstr_read_file(const char *filename)
 {
+    FILE *f;
     Octstr *os;
     char buf[128*1024];
     long n;
 
+    gw_assert(filename != NULL);
+
+    f = fopen(filename, "r");
+    if (f == NULL) {
+        error(errno, "fopen failed: couldn't open `%s'", filename);
+        return NULL;
+    }
+
     os = octstr_create("");
     if (os == NULL)
         goto error;
@@ -1215,34 +1225,16 @@
     while ((n = fread(buf, 1, sizeof(buf), f)) > 0)
         octstr_insert_data(os, octstr_len(os), buf, n);
 
+    (void) fclose(f);
     return os;
 
 error:
+    (void) fclose(f);
     octstr_destroy(os);
     return NULL;
 }
 
 
-Octstr *octstr_read_file(const char *filename)
-{
-    FILE *f;
-    Octstr *ret;
-
-    gw_assert(filename != NULL);
-
-    f = fopen(filename, "r");
-    if (f == NULL) {
-        error(errno, "fopen failed: couldn't open `%s'", filename);
-        return NULL;
-    }
-
-    ret = octstr_read( f );
-
-    (void) fclose(f);
-
-    return ret;
-}
-
 
 List *octstr_split_words(Octstr *ostr)
 {
octstr.h.diff (application/octet-stream, 366 B)
--- octstr.h	Wed Feb  6 09:52:57 2002
+++ ../../org/gateway-1.0.3/gwlib/octstr.h	Thu Oct  5 18:01:22 2000
@@ -399,13 +399,6 @@
 
 
 /*
- * Read the contents of a file to an octet string. Return pointer to
- * octet string.
- */
-Octstr *octstr_read(FILE* f);
-
-
-/*
  * Read the contents of a named file to an octet string. Return pointer to
  * octet string.
  */
smsbox_req.c.diff (application/octet-stream, 1 KB)
--- smsbox_req.c	Wed Feb  6 10:00:42 2002
+++ ../../org/gateway-1.0.3/gw/smsbox_req.c	Fri Oct  6 12:59:27 2000
@@ -87,7 +87,6 @@
 		*temp, *replytext;
 	List *request_headers, *reply_headers;
 	int status;
-  FILE *f;
 
 	gw_assert(msg != NULL);
 	gw_assert(msg_type(msg) == smart_sms);
@@ -116,28 +115,6 @@
 		     ret);
 		break;
 
-	case TRANSTYPE_EXECUTE:
-		alog("SMS request sender:%s request: '%s' processed by '%s'",
-		     octstr_get_cstr(msg->smart_sms.receiver),
-		     octstr_get_cstr(msg->smart_sms.msgdata),
-		     pattern);
-
-		info(0, "executing %s", pattern);
-
-    f = popen(pattern, "r");
-		gw_free(pattern);
-
-    if (f == 0) {
-        info(0, "popen failed %d %s", errno, strerror(errno));
-        ret = octstr_create("");
-    } else {
-        replytext = octstr_read(f);
-        ret = gw_strdup(octstr_get_cstr(replytext));
-        octstr_destroy(replytext);
-        pclose(f);
-    }
-		break;
-
 	case TRANSTYPE_URL:
 		url = octstr_create(pattern);
 		request_headers = list_create();
smsc_at.c.diff (application/octet-stream, 3 KB)
--- ../gateway-1.0.3/gw/smsc_at.c	Wed Feb  6 13:39:18 2002
+++ ../org/gateway-1.0.3/gw/smsc_at.c	Tue Mar 27 15:40:38 2001
@@ -62,7 +62,6 @@
 #define WAVECOM		"wavecom"
 #define PREMICELL	"premicell"
 #define SIEMENS		"siemens"
-#define NOKIA7110	"nokia7110"
 
 /******************************************************************************
  * Open the connection
@@ -82,10 +81,7 @@
 	}
 
 	tcgetattr(fd, &tios);
-	if ( strcmp( smsc->at_modemtype, SIEMENS ) == 0 ) {
-		cfsetospeed(&tios, B19200);  /* check radio pad parameter*/
-		cfsetispeed(&tios, B19200);
-	} else if ( strcmp( smsc->at_modemtype, NOKIA7110 ) == 0 ) {
+	if(strcmp(smsc->at_modemtype, SIEMENS) == 0) {
 		cfsetospeed(&tios, B19200);  /* check radio pad parameter*/
 		cfsetispeed(&tios, B19200);
 	} else {
@@ -140,14 +136,12 @@
 	if (smsc->at_fd < 0)
 		goto error;
 
-  if ( strcmp( smsc->at_modemtype, NOKIA7110 ) == 0 ) sleep( 1 ); // wait for the modem
-
 	/* Turn Echo off on the modem: we don't need it */
 	if(send_modem_command(smsc->at_fd, "ATE0", 0) == -1)
 		goto error;
 	/* Check does the modem require a PIN and, if so, send it
 	 * This is not supported by the Nokia Premicell */
-	if ( ( strcmp( smsc->at_modemtype, SIEMENS ) == 0 ) || ( strcmp( smsc->at_modemtype, WAVECOM ) == 0 ) ) {
+	if(strcmp(smsc->at_modemtype, PREMICELL) != 0) {
 		ret = send_modem_command(smsc->at_fd, "AT+CPIN?", 0); 
 		if(ret == -1)
 			goto error;
@@ -482,8 +476,7 @@
 	
 	/* skip the SMSC address on the Wavecom (don't know about other modems -
 	 * Premicell doesn't need it) */
-	if(strcmp(smsc->at_modemtype, NOKIA7110) == 0 
-	    || strcmp(smsc->at_modemtype, WAVECOM) == 0 
+	if(strcmp(smsc->at_modemtype, WAVECOM) == 0 
 	    || strcmp(smsc->at_modemtype, SIEMENS) == 0) {
 		tmp = hexchar(octstr_get_char(buffer, pos))*16
 		    + hexchar(octstr_get_char(buffer, pos+1));
@@ -589,15 +582,14 @@
 	pos++;
 	
 	/* get the timestamp */
-	mtime.tm_year = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ) + 100; pos++;
-	mtime.tm_mon  = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ) - 1; pos++;
-	mtime.tm_mday = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ); pos++;
-	mtime.tm_hour = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ); pos++;
-	mtime.tm_min  = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ); pos++;
-	mtime.tm_sec  = ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ); pos++;
-
+	mtime.tm_year = octstr_get_char(pdu, pos) + 100; pos++;
+	mtime.tm_mon  = octstr_get_char(pdu, pos); pos++;
+	mtime.tm_mday = octstr_get_char(pdu, pos); pos++;
+	mtime.tm_hour = octstr_get_char(pdu, pos); pos++;
+	mtime.tm_min  = octstr_get_char(pdu, pos); pos++;
+	mtime.tm_sec = octstr_get_char(pdu, pos); pos++;
 	/* time zone: */
-	mtime.tm_hour += ( ( octstr_get_char(pdu, pos) & 15 ) * 10 ) + ( octstr_get_char(pdu, pos) >> 4 ); pos++;
+	mtime.tm_hour += octstr_get_char(pdu, pos); pos++;
 	stime = mktime(&mtime);
 	
 	/* get data length */
urltrans.c.diff (application/octet-stream, 3.1 KB)
--- urltrans.c	Wed Feb  6 10:03:57 2002
+++ ../../org/gateway-1.0.3/gw/urltrans.c	Wed Oct 25 14:26:05 2000
@@ -208,14 +208,10 @@
 	len = strlen(pattern);
 	len += count_occurences(pattern, "%s") * maxword * ENCODED_LEN;
 	len += count_occurences(pattern, "%S") * maxword * ENCODED_LEN;
-	len += count_occurences(pattern, "%A") * 
-			(maxword + 1) * n * ENCODED_LEN;
 	len += count_occurences(pattern, "%a") * 
 			(maxword + 1) * n * ENCODED_LEN;
 	len += count_occurences(pattern, "%r") * 
 			(maxword + 1) * n * ENCODED_LEN;
-	len += count_occurences(pattern, "%R") * 
-			(maxword + 1) * n * ENCODED_LEN;
 	len += count_occurences(pattern, "%p") * 
 			octstr_len(request->smart_sms.receiver) * ENCODED_LEN;
 	len += count_occurences(pattern, "%P") * 
@@ -243,7 +239,6 @@
 		sprintf(s, "%.*s", (int) (p - pattern), pattern);
 		s = strchr(s, '\0');
 		switch (p[1]) {
-		case 'z': break; /* skip a word */
 		case 's':
 			encode_for_url(enc, words[nextarg]);
 			sprintf(s, "%s", enc);
@@ -267,15 +262,6 @@
 				s = strchr(s, '\0');
 			}
 			break;
-		case 'R': /* like %r but without url formatting */
-			for (j = nextarg; j < n; ++j) {
-				if (j == nextarg)
-					sprintf(s, "%s", words[j]);
-				else
-					sprintf(s, " %s", words[j]);
-				s = strchr(s, '\0');
-			}
-			break;
 
 			/* NOTE: the sender and receiver is already switched in
 			 *    message, so that's why we must use 'sender' when
@@ -320,15 +306,6 @@
 				s = strchr(s, '\0');
 			}
 			break;
-		case 'A': /* like %a but without url formatting */
-			for (j = 0; j < n; ++j) {
-				if (j > 0)
-					sprintf(s, " %s", words[j]);
-				else
-					sprintf(s, "%s", words[j]);
-				s = strchr(s, '\0');
-			}
-			break;
 		case 't':
 			tm = gw_gmtime(request->smart_sms.time);
 			sprintf(s, "%04d-%02d-%02d+%02d:%02d",
@@ -435,7 +412,7 @@
 static URLTranslation *create_onetrans(ConfigGroup *grp)
 {
     URLTranslation *ot;
-    char *keyword, *aliases, *url, *text, *file, *execute;
+    char *keyword, *aliases, *url, *text, *file;
     char *prefix, *suffix, *faked_sender, *max_msgs, *concatenation;
     char *split_chars, *split_suffix, *omit_empty;
     char *username, *password;
@@ -458,7 +435,6 @@
     aliases = config_get(grp, "aliases");
     url = config_get(grp, "url");
     text = config_get(grp, "text");
-    execute = config_get(grp, "execute");
     file = config_get(grp, "file");
     prefix = config_get(grp, "prefix");
     suffix = config_get(grp, "suffix");
@@ -489,9 +465,6 @@
     } else if (text) {
 	ot->type = TRANSTYPE_TEXT;
 	ot->pattern = gw_strdup(text);
-    } else if (execute) {
-	ot->type = TRANSTYPE_EXECUTE;
-	ot->pattern = gw_strdup(execute);
     } else if (username) {
 	ot->type = TRANSTYPE_SENDSMS;
 	ot->pattern = gw_strdup("");
@@ -545,9 +518,7 @@
 	ot->args = count_occurences(ot->pattern, "%s");
 	ot->args += count_occurences(ot->pattern, "%S");
 	ot->has_catchall_arg = (count_occurences(ot->pattern, "%r") > 0) ||
-	    (count_occurences(ot->pattern, "%a") > 0) ||
-	    (count_occurences(ot->pattern, "%A") > 0) ||
-	    (count_occurences(ot->pattern, "%R") > 0);
+	    (count_occurences(ot->pattern, "%a") > 0);
     }
     else { 		/* send-sms user */
 	ot->args = 0;
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.