utils/getvar/getvar.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following functions.
  1. main

   1 /******************
   2   Copyright (c) 2002                                        RIPE NCC
   3 
   4   All Rights Reserved
   5 
   6   Permission to use, copy, modify, and distribute this software and its
   7   documentation for any purpose and without fee is hereby granted,
   8   provided that the above copyright notice appear in all copies and that
   9   both that copyright notice and this permission notice appear in
  10   supporting documentation, and that the name of the author not be
  11   used in advertising or publicity pertaining to distribution of the
  12   software without specific, written prior permission.
  13 
  14   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  16   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  17   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  18   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20   ***************************************/
  21 
  22 #include <stdio.h>
  23 #include <sys/types.h>
  24 #include <fcntl.h>
  25 
  26 #include <glib.h>
  27 #include <string.h>
  28 #include <stdlib.h>
  29 #include <stubs.h>
  30 #include "ca_configFns.h"
  31 #include "ca_dictionary.h"
  32 #include "ca_macros.h"
  33 #include "ca_srcAttribs.h"
  34 
  35 int main (int argc, char** argv)
     /* [<][>][^][v][top][bottom][index][help] */
  36 {
  37 /* Initialise the linked list of sources. */
  38 
  39 ca_dbSource_t *source_hdl;
  40 char *source_name, *config_name, *property;
  41 int errflg;
  42 int c;
  43 extern int optind;
  44 extern char *optarg;
  45 
  46 
  47 errflg=0;
  48         if(argc<2)errflg++;
  49 
  50         while ((c = getopt(argc, argv, "s:c:p:?")) != EOF)
  51         switch (c) {
  52                 case 's':
  53                 source_name = optarg;
  54                 break;  
  55 
  56                 case 'c':
  57                 config_name = optarg;
  58                 break;
  59 
  60                 case 'p':
  61                 property = optarg;
  62                 break;
  63                 
  64                 case '?':
  65                 default :
  66                 errflg++;
  67                 break;
  68         }
  69         if (errflg) {
  70          fprintf(stderr,"usage: getvar -s <source> -c <configfile> -p <property>\n");
  71          fprintf(stderr,"list of properties:\n\tdatabase\tdatabase name\n"
  72                                              "\tdbhost\tsql server hostname\n"
  73                                              "\tdbport\tsql server port\n"
  74                                              "\tdbuser\tsql user name\n"
  75                                              "\tdbpswd\tsql user password\n");
  76          exit (2);
  77         }
  78 
  79 
  80  ca_init(config_name);
  81  
  82  source_hdl = ca_get_SourceHandleByName(source_name);
  83 
  84  if(source_hdl == NULL) exit(1);
  85 
  86  if(strcasecmp(property, "dbname")==0){
  87   printf("%s", ca_get_srcdbname(source_hdl)); exit(0);
  88  } else 
  89  if(strcasecmp(property, "dbhost")==0){
  90   printf("%s",ca_get_srcdbmachine(source_hdl)); exit(0);
  91  } else
  92  if(strcasecmp(property, "dbport")==0){
  93   printf("%d",ca_get_srcdbport(source_hdl)); exit(0);
  94  } else
  95  if(strcasecmp(property, "dbuser")==0){
  96   printf("%s",ca_get_srcdbuser(source_hdl)); exit(0);
  97  } else
  98  if(strcasecmp(property, "dbpswd")==0){
  99   printf("%s",ca_get_srcdbpassword(source_hdl)); exit(0);
 100  } else {
 101   printf(""); exit(1);
 102  }
 103 
 104 }

/* [<][>][^][v][top][bottom][index][help] */