Navigation


Changeset 16:013ce9851131 in freeDiameter for freeDiameter/main.c


Ignore:
Timestamp:
Oct 2, 2009, 6:57:06 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Started including TLS code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/main.c

    r14 r16  
    3838#include <signal.h>
    3939#include <getopt.h>
     40#include <locale.h>
     41
     42#ifdef GCRY_THREAD_OPTION_PTHREAD_IMPL
     43GCRY_THREAD_OPTION_PTHREAD_IMPL;
     44#endif /* GCRY_THREAD_OPTION_PTHREAD_IMPL */
     45
    4046
    4147/* forward declarations */
     
    6268        /* Initialize the library */
    6369        CHECK_FCT( fd_lib_init() );
     70        TRACE_DEBUG(INFO, "libfreeDiameter initialized.");
    6471       
    6572        /* Name this thread */
     
    7178        /* Parse the command-line */
    7279        CHECK_FCT(  main_cmdline(argc, argv)  );
     80       
     81        /* Initialize gnutls */
     82        CHECK_GNUTLS_DO( gnutls_global_init(), return EINVAL );
     83        if ( ! gnutls_check_version(GNUTLS_VERSION) ) {
     84                fprintf(stderr, "The GNUTLS library is too old; found '%s', need '" GNUTLS_VERSION "'\n", gnutls_check_version(NULL));
     85                return EINVAL;
     86        } else {
     87                TRACE_DEBUG(INFO, "GNUTLS library '%s' initialized.", gnutls_check_version(NULL));
     88        }
    7389       
    7490        /* Allow SIGINT and SIGTERM from this point */
     
    141157       
    142158        CHECK_FCT_DO( fd_thr_term(&sig_th), /* continue */ );
     159       
     160        gnutls_global_deinit();
    143161       
    144162        return ret;
     
    168186        int c;
    169187        int option_index = 0;
     188        char * locale;
    170189       
    171190        struct option long_options[] = {
    172                 { "help",       0, NULL, 'h' },
    173                 { "version",    0, NULL, 'V' },
    174                 { "config",     1, NULL, 'c' },
    175                 { "debug",      0, NULL, 'd' },
    176                 { "quiet",      0, NULL, 'q' },
    177                 { NULL, 0, NULL, 0 }
     191                { "help",       no_argument,            NULL, 'h' },
     192                { "version",    no_argument,            NULL, 'V' },
     193                { "config",     required_argument,      NULL, 'c' },
     194                { "debug",      no_argument,            NULL, 'd' },
     195                { "quiet",      no_argument,            NULL, 'q' },
     196                { "dbglocale",  optional_argument,      NULL, 'l' },
     197                { NULL,         0,                      NULL, 0 }
    178198        };
    179199       
     
    182202        /* Loop on arguments */
    183203        while (1) {
    184                 c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index);
     204                c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
    185205                if (c == -1)
    186206                        break;  /* Exit from the loop.  */
     
    200220                                break;
    201221
     222                        case 'l':       /* Change the locale.  */
     223                                locale = setlocale(LC_ALL, optarg?:"");
     224                                if (locale) {
     225                                        TRACE_DEBUG(INFO, "Locale set to: %s", optarg ?: locale);
     226                                } else {
     227                                        TRACE_DEBUG(INFO, "Unable to set locale (%s)", optarg);
     228                                        return EINVAL;
     229                                }
     230                                break;
     231
    202232                        case 'd':       /* Increase verbosity of debug messages.  */
    203233                                fd_g_debug_lvl++;
     
    210240                        case '?':       /* Invalid option.  */
    211241                                /* `getopt_long' already printed an error message.  */
    212                                 TRACE_DEBUG(INFO, "getopt_long found an invalid character\n");
     242                                TRACE_DEBUG(INFO, "getopt_long found an invalid character");
    213243                                return EINVAL;
    214244
    215245                        default:        /* bug: option not considered.  */
    216                                 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c);
     246                                TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c", c);
    217247                                ASSERT(0);
    218248                                return EINVAL;
     
    267297        printf( "\nDebug:\n"
    268298                "  These options are mostly useful for developers\n"
     299                "  -l, --dbglocale        Set the locale for error messages\n"
    269300                "  -d, --debug            Increase verbosity of debug messages\n"
    270301                "  -q, --quiet            Decrease verbosity then remove debug messages\n");
Note: See TracChangeset for help on using the changeset viewer.