"Fossies" - the Fresh Open Source Software Archive

Member "smslink-0.56b-3/pdu-tools/gsmts0338.c" (15 Nov 2005, 8738 Bytes) of package /linux/misc/old/smslink-0.56b-3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gsmts0338.c" see the Fossies "Dox" file reference documentation.

    1 /*==========================================================
    2  * Program : gsmts0338.c                   Project : smslink
    3  * Authors : Philippe Andersson.
    4  *           François Baligant <francois@euronet.be>.
    5  * Date    : 28/05/03
    6  * Version : 0.04b
    7  * Notice  : (c) Les Ateliers du Heron, 1998 for Scitex Europe, S.A.
    8  * Comment : PDU Manipulation tool. Encodes and decodes GSM TS
    9  *           03.38 alphabet.
   10  *
   11  * Modification History :
   12  * - 0.01a (18/10/01) : Initial release.
   13  * - 0.02a (23/01/02) : Added support for default GSM alphabet.
   14  * ++++ Switch to Beta ++++
   15  * - 0.03b (29/01/02) : Added CLI option to set the alphabet to
   16  *   use. Added warning on trailing '@' after decoding.
   17  * - 0.04b (28/05/03) : Added handling of new udl param to
   18  *   packed8toascii7().
   19  *========================================================*/
   20 #include <unistd.h>
   21 #include <stdio.h>                         /* for fprintf */
   22 #include <stdlib.h>                  /* for errno & stuff */
   23 #include <errno.h>
   24 #include <string.h>
   25 
   26 #include "sms_serv.h"
   27 #include "pdu.h"
   28 #include "gsmts0338.h"
   29 
   30 /*========================================================*/
   31 /**********             LOCAL DEFINES              ********/
   32 /*========================================================*/
   33 
   34 /*========================================================*/
   35 /**********           GLOBAL VARIABLES             ********/
   36 /*========================================================*/
   37 int debug = FALSE;
   38 char *progname = NULL;
   39 int default_alphabet = DEFAULT_ALPHABET;
   40 
   41 /*========================================================*/
   42 /**********           MAIN PROGRAM LOOP            ********/
   43 /*========================================================*/
   44 int main (int argc, char *argv[])
   45 {
   46   extern char *optarg;
   47   extern int optind, optopt;
   48   int c;                /* option char returned by getopt */
   49   int errflag = 0;       /* error in command line options */
   50   int task = 0;
   51   char *errptr;
   52   char *string;
   53   char *message;
   54   char *csname = NULL;
   55   int tpudl = TP_UDL_UNKNOWN;
   56 
   57   /*---------------------------------------Store own name */
   58   progname = (char *) malloc ((strlen (argv[0]) + 1) * sizeof (char));
   59   if (! progname) {
   60     syserr("main(): can't malloc()");
   61   }
   62   strcpy (progname, argv[0]);
   63   l_basename (progname);
   64   
   65   /*--------------------------------------Initialisations */
   66   string = (char *) malloc ((BIGBUFF + 1) * sizeof (char));
   67   if (!string) {
   68     syserr("main(): can't malloc() string");
   69   }
   70   string[0] = '\0';
   71   message = (char *) malloc ((BIGBUFF + 1) * sizeof (char));
   72   if (!message) {
   73     syserr("main(): can't malloc() message");
   74   }
   75   message[0] = '\0';
   76 
   77   /*-------------------------Command line processing loop */
   78   while ((c = getopt (argc, argv, ":ghvd:e:l:z:")) != -1) {
   79     switch (c) {
   80       case 'g':                               /* debug ON */
   81         debug = TRUE;
   82         break;
   83     
   84       case 'd':                                 /* decode */
   85         if (strlen (optarg) > BIGBUFF) {
   86       fprintf (stderr, "gsmts0338: -d parameter too long, max. is %d\n",
   87               BIGBUFF);
   88       errflag++;
   89     }
   90     else
   91       strcpy (string, optarg);
   92     task = GSMTS_DECODE;
   93         break;
   94 
   95       case 'e':                                 /* encode */
   96         if (strlen (optarg) > BIGBUFF) {
   97       fprintf (stderr, "gsmts0338: -e parameter too long, max. is %d\n",
   98               BIGBUFF);
   99       errflag++;
  100     }
  101     else
  102           strcpy (message, optarg);
  103     task = GSMTS_ENCODE;
  104         break;
  105 
  106       case 'l':
  107         if (optarg) {
  108           tpudl = strtol (optarg, &errptr, 10);
  109           if (*errptr != '\0') {
  110             fprintf (stderr, "Expected numeric value after -l (got: [%s])\n", optarg);
  111         exit (-1);
  112           }
  113         }
  114         break;
  115 
  116       case 'z':
  117         if (optarg) {
  118           if ((default_alphabet = getcharsetID (optarg)) == -1) {
  119             fprintf (stderr, "Requested charset %s not supported\n", optarg);
  120         exit (-1);
  121       }
  122         }
  123         break;
  124 
  125       case 'v':                           /* version info */
  126     printf ("gsmts0338 ver. %s (%s), SMSLink PDU Manipulation Tool.\n", 
  127             GSMTS_VERSION, GSMTS_DATE);
  128     printf ("(c) Les Ateliers du Heron, 1998-2001.\n");
  129         exit (0);
  130         break;
  131     
  132       case 'h':                             /* usage help */
  133     printf ("\ngsmts0338 ver. %s (%s), SMSLink PDU Manipulation Tool.\n", 
  134             GSMTS_VERSION, GSMTS_DATE);
  135     printf ("(c) Les Ateliers du Heron, 1998-2001.\n");
  136     printf ("\nUsage:\n");
  137     printf ("gsmts0338 [options] (-d string | -e msg)\n");
  138     printf ("\nWhere: string  = GSM TS 03.38 string to decode\n");
  139     printf ("       msg     = message to encode to GSM TS 03.38\n");
  140     printf ("Other options:\n");
  141         printf ("-l<n>     specify encoded string length [def. = guess]\n");
  142         printf ("-z<s>     sets character set for GSMTS processing\n");
  143     printf ("-g        sets debugging ON [def. = OFF]\n");
  144     printf ("-v        prints version information and exits\n");
  145     printf ("-h        prints this usage information and exits\n");
  146         printf ("\n");
  147         printf ("Supported character sets:\n");
  148     listsupportedcharsets ();
  149         printf ("    (* indicates compiled-in default).\n");
  150         printf ("\n");
  151         exit (0);
  152         break;
  153     
  154       case ':':             /* parameter without argument */
  155         fprintf (stderr, "gsmts0338: Option -%c requires an argument.\n",
  156                 optopt);
  157         errflag++;
  158         break;
  159 
  160       case '?':               /* unrecognized option char */
  161         fprintf (stderr, "gsmts0338: Unrecognized option: -%c.\n", optopt);
  162         errflag++;
  163         break;
  164 
  165       default:
  166         fprintf (stderr, "gsmts0338: getopt() returned char. code 0%o ??\n", c);
  167     }                                       /* switch (c) */
  168   }                                       /* while (c...) */
  169   /*----------------------Check for required parameter(s) */
  170   /* either -d or -e */
  171   if (!errflag) {
  172     if (task == 0) {
  173       fprintf (stderr, "gsmts0338: You must provide at least one of -d or -e.\n");
  174       errflag++;
  175     }
  176   }                                      /* if (!errflag) */
  177 
  178   /*-------------------Check for conflicting parameter(s) */
  179   /* -d with -e */
  180   if ((strlen (message) > 0) && (strlen (string) > 0)) {
  181       fprintf (stderr, "gsmts0338: Conflicting parameters -d and -e.\n");
  182       errflag++;
  183   }
  184   /*-----------------------On error, display usage & exit */
  185   if (errflag) {
  186     fprintf (stderr, "\n==> gsmts0338 -h for usage details.\n");
  187     exit (2);
  188   }
  189   /* DEBUG ...............................................*/
  190   if (debug) {
  191     fprintf (stderr, "Debugging mode is turned ON.\n");
  192     fprintf (stderr, "Those are the current parameters :\n");
  193     fprintf (stderr, "string   = [%s]\n", string);
  194     fprintf (stderr, "message  = [%s]\n", message);
  195     if (tpudl != TP_UDL_UNKNOWN) {
  196       fprintf (stderr, "<tpudl>  = [%d]\n", tpudl);
  197     }
  198     else {
  199       fprintf (stderr, "<tpudl>  = [guess] (default)\n");
  200     }
  201     fprintf (stderr, "charset  = [%d]\n", default_alphabet);
  202   }
  203 
  204   /* Log current charset */
  205   csname = getcharsetname (default_alphabet);
  206   if (default_alphabet == 0) {
  207     /* GSM default alphabet is not meant to be used on the server side */
  208     fprintf (stderr, "WARNING: charset set to GSM default alphabet.\n");
  209     fprintf (stderr, "         This may not have the intended result !\n");
  210   }
  211   else {
  212     printf ("Using charset %s\n", csname);
  213   }
  214   if (csname) {
  215     free (csname);
  216   }
  217   
  218   /*---------------------------Start real processing loop */
  219   switch (task) {
  220     case GSMTS_ENCODE :
  221       if (tpudl != TP_UDL_UNKNOWN) {
  222         printf ("Warning: setting <tpudl> when encoding is meaningless - ignored\n");
  223       }
  224       printf ("Original message: [%s] (%d char.)\n", message, strlen (message));
  225       ascii7topacked8 (message, string, default_alphabet);
  226       printf ("Encoded string: [%s] (%d char., <tpudl> = %d)\n", string, 
  227              strlen (string), strlen (message));
  228       break;
  229       
  230     case GSMTS_DECODE :
  231       printf ("Encoded string: [%s] (%d char.)\n", string, strlen (string));
  232       packed8toascii7 (string, message, tpudl, default_alphabet);
  233       printf ("Decoded message: [%s] (%d char.)\n", message, strlen (message));
  234       break;
  235 
  236     default :
  237       fprintf (stderr, "gsmts0338: Unsupported task #%d, internal error.\n", task);
  238       exit (1);
  239       break;
  240       
  241   }                                      /* switch (task) */
  242 
  243 
  244   /*------------------------------------------Conclusions */
  245   /* free what's need to be */
  246   free (string);
  247   free (message);
  248 
  249   /*------------------------------------------End program */
  250   exit (0);
  251 }
  252 
  253 /*==========================================================
  254  * EOF : gsmts0338.c
  255  *===================*/