[PATCH] sms centers
Harrie Hazewinkel <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <3687438.1028665848@localhost> |
HI, In order to align/modularize all the SMS center code I went through some of the smsc-code. Now to my suprise I see the following levels for the creation of SMS centers. top layer : smsconn.c smscconn_create wrapper : sms_wrapper.c smsc_wrapper_create (called fron within smscconn_create) smscenter : smsc.c smsc_open (called from within smsc_wrapper_create) smsc type : <smsctype>.c <smsctype> _open I was wondering why these three levels are created while I believe 2 would have been sufficient. Also I see that some of the specific SMS center types are hooked in at the highest level. Would it all not be better is the middle layers gets merged?? Maybe some one could shed some light on this. If no one objects, I would like to apply this patch and keep working on this. Harrie Internet Management Consulting mailto: [email protected] http://www.lisanza.net/ -------------------------------------------------------------------- Author of MOD-SNMP, enabling SNMP management the Apache HTTP server
smsc.patch
(application/octet-stream, 26.9 KB)
'pheasant' for login: exec 'cvs diff'
? sthVlPMp
? st5jSkkZ
Index: gw/smsc.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc.c,v
retrieving revision 1.57
diff -u -r1.57 smsc.c
--- gw/smsc.c 19 Sep 2001 15:59:37 -0000 1.57
+++ gw/smsc.c 6 Aug 2002 18:29:10 -0000
@@ -567,20 +567,14 @@
switch (typeno) {
case SMSC_TYPE_CIMD:
- if (host == NULL || port == 0 || username == NULL || password == NULL)
- error(0, "Required field missing for CIMD center.");
- else
- smsc = cimd_open(octstr_get_cstr(host),
+ smsc = cimd_open(host,
port,
- octstr_get_cstr(username),
- octstr_get_cstr(password));
+ username,
+ password);
break;
case SMSC_TYPE_CIMD2:
- if (host == NULL || port == 0 || username == NULL || password == NULL)
- error(0, "Required field missing for CIMD 2 center.");
- else
- smsc = cimd2_open(host,
+ smsc = cimd2_open(host,
port,
username,
password,
@@ -589,59 +583,42 @@
break;
case SMSC_TYPE_EMI:
- if (phone == NULL || device == NULL || username == NULL ||
- password == NULL)
- error(0, "Required field missing for EMI center.");
- else
- smsc = emi_open(octstr_get_cstr(phone),
- octstr_get_cstr(device),
- octstr_get_cstr(username),
- octstr_get_cstr(password));
+ smsc = emi_open(phone,
+ device,
+ username,
+ password);
break;
case SMSC_TYPE_EMI_IP:
- if (host == NULL || port == 0)
- error(0, "Required field missing for EMI IP center.");
- else
- smsc = emi_open_ip(octstr_get_cstr(host),
+ smsc = emi_open_ip(host,
port,
- username ? octstr_get_cstr(username) : 0,
- password ? octstr_get_cstr(password) : 0,
+ username,
+ password,
receive_port,
- allow_ip ? octstr_get_cstr(allow_ip) : 0,
+ allow_ip,
our_port);
break;
case SMSC_TYPE_SEMA_X28:
- if (device == NULL || sema_smscnua == NULL || sema_homenua == NULL)
- error(0, "Required field missing for SEMA center.");
- else
- smsc = sema_open(octstr_get_cstr(sema_smscnua),
- octstr_get_cstr(sema_homenua),
- octstr_get_cstr(device),
+ smsc = sema_open(sema_smscnua,
+ sema_homenua,
+ device,
iwaitreport);
break;
case SMSC_TYPE_OIS:
- if (host == NULL || port == 0 || receive_port == 0)
- error(0, "Required field missing for OIS center.");
- else
- smsc = ois_open(receive_port,
- octstr_get_cstr(host),
+ smsc = ois_open(receive_port,
+ host,
port,
ois_debug);
break;
case SMSC_TYPE_AT:
- if (device == NULL)
- error(0, "Required field missing for AT virtual center.");
- else
- smsc = at_open(octstr_get_cstr(device),
- at_modemtype ? octstr_get_cstr(at_modemtype) : 0,
- at_pin ? octstr_get_cstr(at_pin) : 0,
- at_validityperiod ?
- octstr_get_cstr(at_validityperiod) : 0,
- alt_dcs);
+ smsc = at_open(device,
+ at_modemtype,
+ at_pin,
+ at_validityperiod,
+ alt_dcs);
break;
/* add new SMSCes here */
Index: gw/smsc_at.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_at.c,v
retrieving revision 1.43
diff -u -r1.43 smsc_at.c
--- gw/smsc_at.c 17 Oct 2001 14:29:05 -0000 1.43
+++ gw/smsc_at.c 6 Aug 2002 18:29:12 -0000
@@ -140,36 +140,48 @@
/******************************************************************************
* Open the (Virtual) SMSCenter
*/
-SMSCenter *at_open(char *serialdevice, char *modemtype, char *pin,
- char *validityperiod, int alt_dcs)
+SMSCenter *at_open(Octstr *serialdevice, Octstr *modemtype, Octstr *pin,
+ Octstr *validityperiod, int alt_dcs)
{
SMSCenter *smsc;
char setpin[20];
int ret;
-
+
+ if (serialdevice == NULL) {
+ error(0, "at_open: Required field missing for AT virtual center.");
+ return NULL;
+ }
+
smsc = smscenter_construct();
- if(smsc == NULL)
- goto error;
+ if (smsc == NULL) {
+ error(0, "at_open: could not allocate sms center information.");
+ return NULL;
+ }
smsc->type = SMSC_TYPE_AT;
- smsc->at_serialdevice = gw_strdup(serialdevice);
+ smsc->at_serialdevice = octstr_duplicate(serialdevice);
if (validityperiod != NULL)
- smsc->at_validityperiod = gw_strdup(validityperiod);
- smsc->at_modemtype = gw_strdup(modemtype);
- if(pin)
- smsc->at_pin = gw_strdup(pin);
+ smsc->at_validityperiod = octstr_duplicate(validityperiod);
+ smsc->at_modemtype = octstr_duplicate(modemtype);
+ if (pin)
+ smsc->at_pin = octstr_duplicate(pin);
smsc->at_received = list_create();
smsc->at_inbuffer = octstr_create("");
smsc->at_alt_dcs = alt_dcs;
+ sprintf(smsc->name, "AT: %s", smsc->at_serialdevice);
smsc->at_fd = at_open_connection(smsc);
- if (smsc->at_fd < 0)
- goto error;
+ if (smsc->at_fd < 0) {
+ error(0, "cimd2_open: could not open connection!");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
/* Nokia 7110 and 6210 need some time between opening
* the connection and sending the first AT commands */
- if (strcmp(smsc->at_modemtype, NOKIAPHONE) == 0)
- sleep(1);
+ if (strcmp(smsc->at_modemtype, NOKIAPHONE) == 0) {
+ sleep(1);
+ }
/* lets initialize the modem to a safe state */
send_modem_command(smsc->at_fd, "AT", 0);
@@ -177,41 +189,44 @@
send_modem_command(smsc->at_fd, "AT", 0);
/* Turn Echo off on the modem: we don't need it */
- if(send_modem_command(smsc->at_fd, "ATE0", 0) == -1)
- {
- /* ok that was the first command we tried. */
- goto error;
+ if (send_modem_command(smsc->at_fd, "ATE0", 0) == -1) {
+ goto error;
}
/* Let's collect some information from modem */
- if(send_modem_command(smsc->at_fd, "ATI", 0) == -1)
+ if (send_modem_command(smsc->at_fd, "ATI", 0) == -1) {
goto error;
+ }
sleep(1);
- if(send_modem_command(smsc->at_fd, "ATI1", 0) == -1)
+ if (send_modem_command(smsc->at_fd, "ATI1", 0) == -1) {
goto error;
+ }
sleep(1);
- if(send_modem_command(smsc->at_fd, "ATI2", 0) == -1)
+ if (send_modem_command(smsc->at_fd, "ATI2", 0) == -1) {
goto error;
+ }
sleep(1);
- if(send_modem_command(smsc->at_fd, "ATI3", 0) == -1)
+ if (send_modem_command(smsc->at_fd, "ATI3", 0) == -1) {
goto error;
+ }
sleep(1);
- if(send_modem_command(smsc->at_fd, "ATI4", 0) == -1)
+ if (send_modem_command(smsc->at_fd, "ATI4", 0) == -1) {
goto error;
+ }
sleep(1);
/* 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, PREMICELL) != 0) {
- ret = send_modem_command(smsc->at_fd, "AT+CPIN?", 0);
- if(ret == -1)
- goto error;
- if(ret == -2) {
- if(smsc->at_pin == NULL)
- goto error;
- sprintf(setpin, "AT+CPIN=%s", smsc->at_pin);
- if(send_modem_command(smsc->at_fd, setpin, 0) == -1)
- goto error;
- }
+ if (strcmp(smsc->at_modemtype, PREMICELL) != 0) {
+ ret = send_modem_command(smsc->at_fd, "AT+CPIN?", 0);
+ if (ret == -1)
+ goto error;
+ if (ret == -2) {
+ if (smsc->at_pin == NULL)
+ goto error;
+ sprintf(setpin, "AT+CPIN=%s", smsc->at_pin);
+ if (send_modem_command(smsc->at_fd, setpin, 0) == -1)
+ goto error;
+ }
}
/* Set the modem to PDU mode and autodisplay of new messages */
@@ -222,22 +237,21 @@
/* The Ericsson GM12 modem requires different new message
* indication options from the other modems */
- if(strcmp(smsc->at_modemtype, ERICSSON) == 0) {
- if(send_modem_command(smsc->at_fd, "AT+CNMI=3,2,0,0", 0) == -1)
- goto error;
- }
- else if(strcmp(smsc->at_modemtype, SIEMENS_TC35) == 0) {
- if(send_modem_command(smsc->at_fd, "AT+CSMS=1", 0) == -1)
- goto error;
- if(send_modem_command(smsc->at_fd, "AT+CNMI=1,2,0,0,1",0)== -1)
- goto error;
+ if (strcmp(smsc->at_modemtype, ERICSSON) == 0) {
+ if (send_modem_command(smsc->at_fd, "AT+CNMI=3,2,0,0", 0) == -1)
+ goto error;
+ }
+ else if (strcmp(smsc->at_modemtype, SIEMENS_TC35) == 0) {
+ if (send_modem_command(smsc->at_fd, "AT+CSMS=1", 0) == -1)
+ goto error;
+ if (send_modem_command(smsc->at_fd, "AT+CNMI=1,2,0,0,1",0)== -1)
+ goto error;
}
else {
- if(send_modem_command(smsc->at_fd, "AT+CNMI=1,2,0,0,0", 0) == -1)
- goto error;
+ if (send_modem_command(smsc->at_fd, "AT+CNMI=1,2,0,0,0", 0) == -1)
+ goto error;
}
- sprintf(smsc->name, "AT: %s", smsc->at_serialdevice);
info(0, "AT SMSC successfully opened.");
Index: gw/smsc_cimd.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_cimd.c,v
retrieving revision 1.25
diff -u -r1.25 smsc_cimd.c
--- gw/smsc_cimd.c 8 Oct 2001 19:43:04 -0000 1.25
+++ gw/smsc_cimd.c 6 Aug 2002 18:29:14 -0000
@@ -24,7 +24,7 @@
*/
/* do the handshake baby */
-static int cimd_open_connection(SMSCenter *smsc);
+static int cimd_login(SMSCenter *smsc);
/* waits for an ACK message, returns the ACK command number or -1 for error */
static int expect_acknowledge(SMSCenter *smsc, int *cmd, int *err);
@@ -45,7 +45,7 @@
*
* return 0 if ok, -1 on failure
*/
-static int cimd_open_connection(SMSCenter *smsc)
+static int cimd_login(SMSCenter *smsc)
{
char *tmpbuff = NULL;
@@ -105,7 +105,7 @@
cimd_close(smsc);
error:
- error(0, "cimd_open: could not open/handshake");
+ error(0, "cimd_login: could not open/handshake");
gw_free(tmpbuff);
return -1;
}
@@ -115,34 +115,38 @@
/******************************************************************************
* Open the smscenter
*/
-SMSCenter *cimd_open(char *hostname, int port, char *username, char *password)
+SMSCenter *cimd_open(Octstr *hostname, int port, Octstr *username,
+Octstr *password)
{
SMSCenter *smsc = NULL;
- int ret = 0;
+ if (hostname == NULL || port == 0 || username == NULL || password == NULL) {
+ error(0, "cimd_open: required field missing for CIMD center.");
+ return NULL;
+ }
/* create a SMSCenter structure */
smsc = smscenter_construct();
- if (smsc == NULL) goto error;
+ if (smsc == NULL) {
+ error(0, "cimd_open: could not allocate sms center information");
+ return NULL;
+ }
+
smsc->type = SMSC_TYPE_CIMD;
- smsc->cimd_hostname = gw_strdup(hostname);
- smsc->hostname = gw_strdup(hostname); /* Needed by read_into_buffer() */
+ smsc->cimd_hostname = octstr_duplicate(hostname);
+ smsc->hostname = octstr_duplicate(hostname); /* Needed by read_into_buffer() */
smsc->cimd_port = port;
- smsc->cimd_username = gw_strdup(username);
- smsc->cimd_password = gw_strdup(password);
-
- ret = cimd_open_connection(smsc);
- if (ret < 0)
- goto error;
+ smsc->cimd_username = octstr_duplicate(username);
+ smsc->cimd_password = octstr_duplicate(password);
+ sprintf(smsc->name, "CIMD:%s:%d:%s", octstr_get_cstr(hostname), port, octstr_get_cstr(username));
+
+ if (cimd_login(smsc) < 0) {
+ error(0, "cimd_open: could not open connection!");
+ smscenter_destruct(smsc);
+ smsc = NULL;
+ }
- sprintf(smsc->name, "CIMD:%s:%d:%s", smsc->cimd_hostname,
- smsc->cimd_port, smsc->cimd_username);
return smsc;
-
-error:
- error(0, "cimd_open: could not open!");
- smscenter_destruct(smsc);
- return NULL;
}
@@ -156,7 +160,7 @@
cimd_close(smsc);
- if (cimd_open_connection(smsc) < 0) {
+ if (cimd_login(smsc) < 0) {
error(0, "Failed to re-open the connection!");
return -1;
}
Index: gw/smsc_cimd2.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_cimd2.c,v
retrieving revision 1.30
diff -u -r1.30 smsc_cimd2.c
--- gw/smsc_cimd2.c 26 Apr 2002 10:29:57 -0000 1.30
+++ gw/smsc_cimd2.c 6 Aug 2002 18:29:17 -0000
@@ -1713,8 +1713,16 @@
SMSCenter *smsc = NULL;
int maxlen;
+ if (hostname == NULL || port == 0 || username == NULL || password == NULL) {
+ error(0, "cimd2_open: required field missing for CIMD 2 center.");
+ return NULL;
+ }
+
smsc = smscenter_construct();
- gw_assert(smsc != NULL);
+ if (smsc == NULL) {
+ error(0, "cimd2_open: could not allocate sms center information");
+ return NULL;
+ }
smsc->type = SMSC_TYPE_CIMD2;
smsc->keepalive = keepalive;
@@ -1733,24 +1741,22 @@
maxlen = parm_maxlen(P_USER_IDENTITY);
if (octstr_len(smsc->cimd2_username) > maxlen) {
octstr_truncate(smsc->cimd2_username, maxlen);
- warning(0, "Truncating CIMD2 username to %d chars", maxlen);
+ warning(0, "cimd2_open: Truncating CIMD2 username to %d chars", maxlen);
}
maxlen = parm_maxlen(P_PASSWORD);
if (octstr_len(smsc->cimd2_password) > maxlen) {
octstr_truncate(smsc->cimd2_password, maxlen);
- warning(0, "Truncating CIMD2 password to %d chars", maxlen);
+ warning(0, "cimd2_open: Truncating CIMD2 password to %d chars", maxlen);
}
- if (cimd2_login(smsc) < 0)
- goto error;
+ if (cimd2_login(smsc) < 0) {
+ error(0, "cimd2_open: could not open connection!");
+ smscenter_destruct(smsc);
+ smsc = NULL;
+ }
return smsc;
-
-error:
- error(0, "cimd2_open failed");
- smscenter_destruct(smsc);
- return NULL;
}
int cimd2_reopen(SMSCenter *smsc)
Index: gw/smsc_emi.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_emi.c,v
retrieving revision 1.42
diff -u -r1.42 smsc_emi.c
--- gw/smsc_emi.c 13 Nov 2001 12:56:11 -0000 1.42
+++ gw/smsc_emi.c 6 Aug 2002 18:29:19 -0000
@@ -96,34 +96,36 @@
/* open EMI smscenter */
-SMSCenter *emi_open(char *phonenum, char *serialdevice, char *username, char *password)
+SMSCenter *emi_open(Octstr *phonenum, Octstr *serialdevice, Octstr *username, Octstr *password)
{
SMSCenter *smsc;
+ if (phonenum == NULL || serialdevice == NULL || username == NULL || password == NULL) {
+ error(0, "emi_open: Required field missing for EMI center.");
+ return NULL;
+ }
smsc = smscenter_construct();
- if (smsc == NULL)
- goto error;
+ if (smsc == NULL) {
+ error(0, "emi_open: Could not allocate sms center information");
+ return NULL;
+ }
smsc->type = SMSC_TYPE_EMI;
-
- smsc->emi_phonenum = gw_strdup(phonenum);
- smsc->emi_serialdevice = gw_strdup(serialdevice);
- smsc->emi_username = gw_strdup(username);
- smsc->emi_password = gw_strdup(password);
-
+ smsc->emi_phonenum = octstr_duplicate(phonenum);
+ smsc->emi_serialdevice = octstr_duplicate(serialdevice);
+ smsc->emi_username = octstr_duplicate(username);
+ smsc->emi_password = octstr_duplicate(password);
smsc->emi_current_msg_number = 0;
+ sprintf(smsc->name, "EMI:%s:%s", octstr_get_cstr(phonenum),
+ octstr_get_cstr(username));
- if (emi_open_connection(smsc) < 0)
- goto error;
+ if (emi_open_connection(smsc) < 0) {
+ error(0, "emi_open: could not open connection!");
+ smscenter_destruct(smsc);
+ smsc = NULL;
+ }
- sprintf(smsc->name, "EMI:%s:%s", smsc->emi_phonenum,
- smsc->emi_username);
return smsc;
-
-error:
- error(0, "emi_open failed");
- smscenter_destruct(smsc);
- return NULL;
}
int emi_reopen(SMSCenter *smsc)
@@ -240,54 +242,55 @@
/******************************************************************************
* Open the connection and log in
*/
-SMSCenter *emi_open_ip(char *hostname, int port, char *username,
- char *password, int receive_port, char *allow_ip,
+SMSCenter *emi_open_ip(Octstr *hostname, int port, Octstr *username,
+ Octstr *password, int receive_port, Octstr *allow_ip,
int our_port)
{
SMSCenter *smsc;
+ if (hostname == NULL || port == 0) {
+ error(0, "emi_open_ip: Required field missing for EMI IP center.");
+ return NULL;
+ }
+
smsc = smscenter_construct();
- if (smsc == NULL)
- goto error;
+ if (smsc == NULL) {
+ error(0, "emi_open_ip: could not allocate sms center information");
+ return NULL;
+ }
smsc->type = SMSC_TYPE_EMI_IP;
-
- smsc->emi_hostname = gw_strdup(hostname);
+ smsc->emi_hostname = octstr_duplicate(hostname);
smsc->emi_port = port;
- smsc->emi_username = username ? gw_strdup(username) : NULL;
- smsc->emi_password = password ? gw_strdup(password) : NULL;
+ smsc->emi_username = username ? octstr_duplicate(username) : NULL;
+ smsc->emi_password = password ? octstr_duplicate(password) : NULL;
smsc->emi_backup_port = receive_port;
- smsc->emi_backup_allow_ip = allow_ip ? gw_strdup(allow_ip) : NULL;
+ smsc->emi_backup_allow_ip = allow_ip ? octstr_duplicate(allow_ip) : NULL;
smsc->emi_our_port = our_port;
- if (receive_port > 0 && allow_ip == NULL)
- warning(0, "EMI IP: receive-port set but no IPs allowed to connect!");
-
smsc->emi_current_msg_number = 0;
-
- if (emi_open_connection_ip(smsc) < 0)
- goto error;
-
sprintf(smsc->name, "EMIIP:%s:%s", smsc->emi_hostname,
username ? smsc->emi_username : "n/a");
- /* if receive-port is defined, set it ready */
-
- if (receive_port > 0) {
- if ((smsc->emi_backup_fd = make_server_socket(receive_port, NULL)) <= 0)
- /* XXX add interface_name if required */
- goto error;
+ if (emi_open_connection_ip(smsc) < 0) {
+ error(0, "emi_open_ip: could not open connection!");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
+ /* if receive-port is defined, set it ready */
+ if (receive_port > 0 && allow_ip == NULL) {
+ warning(0, "EMI IP: receive-port set but no IPs allowed to connect!");
+ if ((smsc->emi_backup_fd = make_server_socket(receive_port, NULL)) <= 0) {
+ error(0, "emi_open_ip: could not open backup port");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
debug("bb.sms.emi", 0, "EMI IP backup port at %d opened", receive_port);
}
- return smsc;
-
-error:
- error(0, "emi_open_ip failed");
- smscenter_destruct(smsc);
- return NULL;
+ return smsc;
}
int emi_reopen_ip(SMSCenter *smsc)
Index: gw/smsc_ois.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_ois.c,v
retrieving revision 1.13
diff -u -r1.13 smsc_ois.c
--- gw/smsc_ois.c 10 Feb 2002 11:13:36 -0000 1.13
+++ gw/smsc_ois.c 6 Aug 2002 18:29:22 -0000
@@ -163,40 +163,39 @@
* Establish a connection to the SMSC.
*/
-SMSCenter *ois_open(int receiveport, const char *hostname, int port, int debug_level)
+SMSCenter *ois_open(int receiveport, Octstr *hostname, int port, int debug_level)
{
SMSCenter *smsc;
- int ret;
+
+ if (receiveport == 0 || hostname == NULL || port == 0) {
+ error(0, "ois_open: Required field missing for OIS center.");
+ return NULL;
+ }
ois_debug_level = debug_level & OIS_FLAG_DEBUG;
SAY(2, "ois_open");
/* create a SMSCenter structure */
-
smsc = smscenter_construct();
if (smsc == NULL) {
- goto error;
+ error(0, "ois_open: Could not allocate sms center information.");
+ return NULL;
}
smsc->type = SMSC_TYPE_OIS;
smsc->receive_port = receiveport;
- smsc->hostname = gw_strdup(hostname);
+ smsc->hostname = octstr_duplicate(hostname);
smsc->port = port;
smsc->ois_flags = ois_debug_level;
+ sprintf(smsc->name, "OIS:TCP/X.25-Translator:localhost:%d:TCP:%.512s:%d",
+ smsc->receive_port, octstr_get_cstr(hostname), smsc->port);
- ret = ois_open_listener(smsc);
- if (ret < 0) {
- goto error;
+ if (ois_open_listener(smsc) < 0) {
+ error(0, "ois_open: Could not open connection!.");
+ return NULL;
}
- sprintf(smsc->name, "OIS:TCP/X.25-Translator:localhost:%d:TCP:%.512s:%d",
- smsc->receive_port, smsc->hostname, smsc->port);
return smsc;
-
- error:
- error(0, "ois_open: could not open");
- smscenter_destruct(smsc);
- return NULL;
}
Index: gw/smsc_p.h
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_p.h,v
retrieving revision 1.32
diff -u -r1.32 smsc_p.h
--- gw/smsc_p.h 19 Sep 2001 15:59:37 -0000 1.32
+++ gw/smsc_p.h 6 Aug 2002 18:29:22 -0000
@@ -190,7 +190,7 @@
/*
* Interface to Nokia SMS centers using CIMD.
*/
-SMSCenter *cimd_open(char *hostname, int port, char *username, char *password);
+SMSCenter *cimd_open(Octstr *hostname, int port, Octstr *username, Octstr *password);
int cimd_reopen(SMSCenter *smsc);
int cimd_close(SMSCenter *smsc);
int cimd_pending_smsmessage(SMSCenter *smsc);
@@ -210,11 +210,11 @@
/*
* Interface to CMG SMS centers using EMI.
*/
-SMSCenter *emi_open(char *phonenum, char *serialdevice, char *username, char *password);
+SMSCenter *emi_open(Octstr *phonenum, Octstr *serialdevice, Octstr *username, Octstr *password);
int emi_reopen(SMSCenter *smsc);
int emi_close(SMSCenter *smsc);
-SMSCenter *emi_open_ip(char *hostname, int port, char *username,
- char *password, int receive_port, char *allow_ip, int our_port);
+SMSCenter *emi_open_ip(Octstr *hostname, int port, Octstr *username,
+ Octstr *password, int receive_port, Octstr *allow_ip, int our_port);
int emi_reopen_ip(SMSCenter *smsc);
int emi_close_ip(SMSCenter *smsc);
int emi_pending_smsmessage(SMSCenter *smsc);
@@ -224,7 +224,7 @@
/*
* Interface to Sema SMS centers using SM2000
*/
-SMSCenter *sema_open(char *smscnua, char *homenua, char* serialdevice,
+SMSCenter *sema_open(Octstr *smscnua, Octstr *homenua, Octstr* serialdevice,
int waitreport);
int sema_reopen(SMSCenter *smsc);
int sema_close(SMSCenter *smsc);
@@ -236,7 +236,7 @@
* Interface to Sema SMS centers using OIS 5.0.
* Interface to Sema SMS centers using SM2000
*/
-SMSCenter *ois_open(int receiveport, const char *hostname, int port,
+SMSCenter *ois_open(int receiveport, Octstr *hostname, int port,
int debug_level);
int ois_reopen(SMSCenter *smsc);
int ois_close(SMSCenter *smsc);
@@ -249,8 +249,8 @@
/*
* Interface to wireless modems using AT commands.
*/
-SMSCenter *at_open(char *serialdevice, char *modemtype, char *pin,
- char *validityperiod, int alt_dcs);
+SMSCenter *at_open(Octstr *serialdevice, Octstr *modemtype, Octstr *pin,
+ Octstr *validityperiod, int alt_dcs);
int at_reopen(SMSCenter *smsc);
int at_close(SMSCenter *smsc);
int at_pending_smsmessage(SMSCenter *smsc);
Index: gw/smsc_sema.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_sema.c,v
retrieving revision 1.17
diff -u -r1.17 smsc_sema.c
--- gw/smsc_sema.c 31 Oct 2001 10:52:46 -0000 1.17
+++ gw/smsc_sema.c 6 Aug 2002 18:29:25 -0000
@@ -54,52 +54,68 @@
static int sema_wait_report = 1;
static int x28_data_mode = X28_COMMAND_MODE;
-SMSCenter * sema_open(char* smscnua, char* homenua,
- char* serialdevice, int waitreport)
+SMSCenter * sema_open(Octstr *smscnua, Octstr *homenua,
+ Octstr *serialdevice, int waitreport)
{
SMSCenter *smsc;
- int nret = -1;
+
+ if (serialdevice == NULL || smscnua == NULL || homenua == NULL) {
+ error(0, "sema_open: Required field missing for SEMA center.");
+ return NULL;
+ }
smsc = smscenter_construct();
- if(smsc == NULL)
- goto error;
+ if (smsc == NULL) {
+ error(0, "sema_open: could not allocate smsm center information.");
+ return NULL;
+ }
sprintf(smsc->name, "SEMA:X28:");
-
smsc->type = SMSC_TYPE_SEMA_X28;
- smsc->sema_smscnua = gw_strdup(smscnua);
- smsc->sema_homenua = gw_strdup(homenua);
- smsc->sema_serialdevice = gw_strdup(serialdevice);
+ smsc->sema_smscnua = octstr_duplicate(smscnua);
+ smsc->sema_homenua = octstr_duplicate(homenua);
+ smsc->sema_serialdevice = octstr_duplicate(serialdevice);
sema_wait_report = waitreport;
smsc->sema_mt = sema_msglist_new();
- if(smsc->sema_mt == NULL) goto error;
+ if (smsc->sema_mt == NULL) {
+ error(0, "sema_open: could not create msglist.");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
smsc->sema_mo = sema_msglist_new();
- if(smsc->sema_mo == NULL) goto error;
+ if(smsc->sema_mo == NULL) {
+ error(0, "sema_open: could not create msglist.");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
/* Open the device properly. Remember to set the
access codes correctly. */
debug("smsc.sema", 0, "sema_open: open datalink");
smsc->sema_fd = X28_open_data_link(smsc->sema_serialdevice);
- if(smsc->sema_fd == -1) goto error;
+ if (smsc->sema_fd == -1) {
+ error(0, "sema_open: could not open data link.");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
+
/* test the outgoing callX28 to smsc center */
debug("smsc.sema", 0, "sema_open: test send link");
- nret = X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua);
- if(nret < 1){
- sleep(2);
- nret = X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua);
- if(nret < 1)
- goto error;
- }
+ if (X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua) < 1) {
+ /* to fast */
+ sleep(2);
+ if (X28_open_send_link(smsc->sema_fd, smsc->sema_smscnua) < 1) {
+ error(0, "sema_open: could not send data.");
+ smscenter_destruct(smsc);
+ return NULL;
+ }
+ }
X28_close_send_link(smsc->sema_fd);
- return smsc;
-error:
- error(0, "sema_open: could not open");
- smscenter_destruct(smsc);
- return NULL;
+ return smsc;
}