Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
smsc.h File Reference
#include <stddef.h>
#include <stdio.h>
#include <time.h>
#include "gwlib/gwlib.h"
#include "msg.h"

Go to the source code of this file.

Typedefs

typedef struct SMSCenter SMSCenter
 

Functions

SMSCentersmsc_open (CfgGroup *grp)
 
int smsc_reopen (SMSCenter *smsc)
 
char * smsc_name (SMSCenter *smsc)
 
int smsc_close (SMSCenter *smsc)
 

Typedef Documentation

typedef struct SMSCenter SMSCenter

Definition at line 81 of file smsc.h.

Function Documentation

int smsc_close ( SMSCenter smsc)

Definition at line 648 of file smsc.c.

References cimd_close(), emi_close(), ois_close(), sema_close(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, smscenter_lock(), and SMSCenter::type.

Referenced by smscwrapper_destroy().

649 {
650  int errors = 0;
651 
652  if (smsc == NULL)
653  return 0;
654 
655  smscenter_lock(smsc);
656 
657  switch (smsc->type) {
658  case SMSC_TYPE_CIMD:
659  if (cimd_close(smsc) == -1)
660  errors = 1;
661  break;
662 
663  case SMSC_TYPE_EMI_X25:
664  if (emi_close(smsc) == -1)
665  errors = 1;
666  break;
667 
668  case SMSC_TYPE_SEMA_X28:
669  if (sema_close(smsc) == -1)
670  errors = 1;
671  break;
672 
673  case SMSC_TYPE_OIS:
674  if (ois_close(smsc) == -1)
675  errors = 1;
676  break;
677 
678  /* add new SMSCes here */
679 
680  default: /* Unknown SMSC type */
681  break;
682  }
683  /*
684  smsc->type = SMSC_TYPE_DELETED;
685  smscenter_unlock(smsc);
686  */
687  if (errors)
688  return -1;
689 
690  return 0;
691 }
int ois_close(SMSCenter *smsc)
Definition: smsc_ois.c:263
int sema_close(SMSCenter *smsc)
Definition: smsc_sema.c:199
static void smscenter_lock(SMSCenter *smsc)
Definition: smsc.c:422
int emi_close(SMSCenter *smsc)
Definition: smsc_emi_x25.c:194
int cimd_close(SMSCenter *smsc)
Definition: smsc_cimd.c:228
int type
Definition: smsc_p.h:93
char* smsc_name ( SMSCenter smsc)

Definition at line 643 of file smsc.c.

References SMSCenter::name.

Referenced by smsc_wrapper_create().

644 {
645  return smsc->name;
646 }
char name[1024]
Definition: smsc_p.h:96
SMSCenter* smsc_open ( CfgGroup grp)

Definition at line 444 of file smsc.c.

References allow_ip, SMSCenter::allowed_prefix, SMSCenter::alt_charset, cfg_get, cfg_get_integer(), cimd_open(), SMSCenter::denied_prefix, emi_open(), error(), host, octstr_compare(), octstr_create, octstr_destroy(), octstr_get_cstr, octstr_imm(), octstr_parse_long(), ois_open(), our_port, password, port, SMSCenter::preferred_prefix, sema_open(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, type, and username.

Referenced by smsc_wrapper_create().

445 {
446  SMSCenter *smsc;
447  Octstr *type, *host, *username, *password, *phone, *device;
448  Octstr *preferred_prefix, *allowed_prefix, *denied_prefix;
449  Octstr *alt_chars, *allow_ip;
450  Octstr *sema_smscnua, *sema_homenua, *sema_report;
451  Octstr *sender_prefix;
452 
453  long iwaitreport;
454  long port, receive_port, our_port;
455  long keepalive;
456  long ois_debug;
457  long alt_dcs;
458  int typeno;
459 
460 
461  type = cfg_get(grp, octstr_imm("smsc"));
462  if (type == NULL) {
463  error(0, "Required field 'smsc' missing for smsc group.");
464  return NULL;
465  }
466  if (octstr_compare(type, octstr_imm("cimd")) == 0)
467  typeno = SMSC_TYPE_CIMD;
468  else if (octstr_compare(type, octstr_imm("emi_x25")) == 0)
469  typeno = SMSC_TYPE_EMI_X25;
470  else if (octstr_compare(type, octstr_imm("sema")) == 0)
471  typeno = SMSC_TYPE_SEMA_X28;
472  else if (octstr_compare(type, octstr_imm("ois")) == 0)
473  typeno = SMSC_TYPE_OIS;
474  else {
475  error(0, "Unknown SMSC type '%s'", octstr_get_cstr(type));
476  octstr_destroy(type);
477  return NULL;
478  }
479 
480  host = cfg_get(grp, octstr_imm("host"));
481  if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1)
482  port = 0;
483  if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1)
484  receive_port = 0;
485  if (cfg_get_integer(&our_port, grp, octstr_imm("our-port")) == -1)
486  our_port = 0;
487  username = cfg_get(grp, octstr_imm("smsc-username"));
488  password = cfg_get(grp, octstr_imm("smsc-password"));
489  phone = cfg_get(grp, octstr_imm("phone"));
490  device = cfg_get(grp, octstr_imm("device"));
491  preferred_prefix = cfg_get(grp, octstr_imm("preferred-prefix"));
492  allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix"));
493  denied_prefix = cfg_get(grp, octstr_imm("denied-prefix"));
494  alt_chars = cfg_get(grp, octstr_imm("alt-charset"));
495 
496  allow_ip = cfg_get(grp, octstr_imm("connect-allow-ip"));
497 
498  sema_smscnua = cfg_get(grp, octstr_imm("smsc_nua"));
499  sema_homenua = cfg_get(grp, octstr_imm("home_nua"));
500  sema_report = cfg_get(grp, octstr_imm("wait_report"));
501  if (sema_report == NULL)
502  iwaitreport = 1;
503  else
504  octstr_parse_long(&iwaitreport, sema_report, 0, 0);
505 
506  if (cfg_get_integer(&keepalive, grp, octstr_imm("keepalive")) == -1)
507  keepalive = 0;
508 
509  if (cfg_get_integer(&alt_dcs, grp, octstr_imm("alt-dcs")) == -1)
510  alt_dcs = 0;
511  if (alt_dcs > 1)
512  alt_dcs = 1;
513 
514  if (cfg_get_integer(&ois_debug, grp, octstr_imm("ois-debug-level")) == -1)
515  ois_debug = 0;
516 
517  sender_prefix = cfg_get(grp, octstr_imm("sender-prefix"));
518  if (sender_prefix == NULL)
519  sender_prefix = octstr_create("never");
520 
521  smsc = NULL;
522 
523  switch (typeno) {
524  case SMSC_TYPE_CIMD:
525  if (host == NULL || port == 0 || username == NULL || password == NULL)
526  error(0, "Required field missing for CIMD center.");
527  else
528  smsc = cimd_open(octstr_get_cstr(host),
529  port,
530  octstr_get_cstr(username),
531  octstr_get_cstr(password));
532  break;
533 
534  case SMSC_TYPE_EMI_X25:
535  if (phone == NULL || device == NULL || username == NULL ||
536  password == NULL)
537  error(0, "Required field missing for EMI_X25 center.");
538  else
539  smsc = emi_open(octstr_get_cstr(phone),
540  octstr_get_cstr(device),
541  octstr_get_cstr(username),
542  octstr_get_cstr(password));
543  break;
544 
545  case SMSC_TYPE_SEMA_X28:
546  if (device == NULL || sema_smscnua == NULL || sema_homenua == NULL)
547  error(0, "Required field missing for SEMA center.");
548  else
549  smsc = sema_open(octstr_get_cstr(sema_smscnua),
550  octstr_get_cstr(sema_homenua),
551  octstr_get_cstr(device),
552  iwaitreport);
553  break;
554 
555  case SMSC_TYPE_OIS:
556  if (host == NULL || port == 0 || receive_port == 0)
557  error(0, "Required field missing for OIS center.");
558  else
559  smsc = ois_open(receive_port,
560  octstr_get_cstr(host),
561  port,
562  ois_debug);
563  break;
564 
565  /* add new SMSCes here */
566 
567  default: /* Unknown SMSC type */
568  break;
569  }
570 
571  if (smsc != NULL) {
572  if (cfg_get_integer(&smsc->alt_charset, grp,
573  octstr_imm("alt-charset")) == -1)
574  smsc->alt_charset = 0;
575  if (preferred_prefix == NULL)
576  smsc->preferred_prefix = NULL;
577  else
578  smsc->preferred_prefix =
579  gw_strdup(octstr_get_cstr(preferred_prefix));
580  if (allowed_prefix == NULL)
581  smsc->allowed_prefix = NULL;
582  else
583  smsc->allowed_prefix = gw_strdup(octstr_get_cstr(allowed_prefix));
584  if (denied_prefix == NULL)
585  smsc->denied_prefix = NULL;
586  else
587  smsc->denied_prefix = gw_strdup(octstr_get_cstr(denied_prefix));
588  }
589 
590  octstr_destroy(type);
591  octstr_destroy(host);
592  octstr_destroy(username);
593  octstr_destroy(password);
594  octstr_destroy(phone);
595  octstr_destroy(device);
596  octstr_destroy(preferred_prefix);
597  octstr_destroy(denied_prefix);
598  octstr_destroy(allowed_prefix);
599  octstr_destroy(alt_chars);
600  octstr_destroy(allow_ip);
601  octstr_destroy(sema_smscnua);
602  octstr_destroy(sema_homenua);
603  octstr_destroy(sema_report);
604  octstr_destroy(sender_prefix);
605  return smsc;
606 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static long our_port
Definition: radius_acct.c:87
char * preferred_prefix
Definition: smsc_p.h:100
int type
Definition: smsc_cimd2.c:215
static Octstr * host
Definition: fakesmsc.c:121
#define cfg_get(grp, varname)
Definition: cfg.h:86
SMSCenter * sema_open(char *smscnua, char *homenua, char *serialdevice, int waitreport)
Definition: smsc_sema.c:113
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned char * username
Definition: test_cimd2.c:99
static int port
Definition: fakesmsc.c:120
unsigned char * password
Definition: test_cimd2.c:100
SMSCenter * emi_open(char *phonenum, char *serialdevice, char *username, char *password)
Definition: smsc_emi_x25.c:153
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
SMSCenter * cimd_open(char *hostname, int port, char *username, char *password)
Definition: smsc_cimd.c:174
char * allowed_prefix
Definition: smsc_p.h:101
SMSCenter * ois_open(int receiveport, const char *hostname, int port, int debug_level)
Definition: smsc_ois.c:222
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
char * denied_prefix
Definition: smsc_p.h:102
static Octstr * allow_ip
Definition: bb_udp.c:111
Definition: octstr.c:118
int cfg_get_integer(long *n, CfgGroup *grp, Octstr *varname)
Definition: cfg.c:739
long alt_charset
Definition: smsc_p.h:106
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:747
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
int smsc_reopen ( SMSCenter smsc)

Definition at line 610 of file smsc.c.

References cimd_reopen(), emi_reopen(), SMSCenter::killed, ois_reopen(), sema_reopen(), SMSC_TYPE_CIMD, SMSC_TYPE_EMI_X25, SMSC_TYPE_OIS, SMSC_TYPE_SEMA_X28, smscenter_lock(), smscenter_unlock(), and SMSCenter::type.

Referenced by reconnect().

611 {
612  int ret;
613 
614  if (smsc->killed)
615  return -2;
616 
617  smscenter_lock(smsc);
618 
619  switch (smsc->type) {
620  case SMSC_TYPE_CIMD:
621  ret = cimd_reopen(smsc);
622  break;
623  case SMSC_TYPE_EMI_X25:
624  ret = emi_reopen(smsc);
625  break;
626  case SMSC_TYPE_SEMA_X28:
627  ret = sema_reopen(smsc);
628  break;
629  case SMSC_TYPE_OIS:
630  ret = ois_reopen(smsc);
631  break;
632  /* add new SMSCes here */
633  default: /* Unknown SMSC type */
634  ret = -2; /* no use */
635  }
636 
637  smscenter_unlock(smsc);
638  return ret;
639 }
int sema_reopen(SMSCenter *smsc)
Definition: smsc_sema.c:162
volatile sig_atomic_t killed
Definition: smsc_p.h:112
int ois_reopen(SMSCenter *smsc)
Definition: smsc_ois.c:287
int cimd_reopen(SMSCenter *smsc)
Definition: smsc_cimd.c:210
static void smscenter_lock(SMSCenter *smsc)
Definition: smsc.c:422
int emi_reopen(SMSCenter *smsc)
Definition: smsc_emi_x25.c:183
int type
Definition: smsc_p.h:93
static void smscenter_unlock(SMSCenter *smsc)
Definition: smsc.c:433
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.