コード例 #1
0
ファイル: rt_http.c プロジェクト: SystemGarden/habitat
int main(int argc, char **argv) {
     int r, seq1, size1;
     CF_VALS cf;
     RT_LLD lld1;
     time_t time1;
     ITREE *chain;
     ROUTE_BUF *rtbuf;

     cf = cf_create();
     http_init();
     rt_http_init(cf, 1);

     /* test 1: is it there? */
     r = rt_http_access(TURL1, NULL, TURL1, ROUTE_READOK);
     if (r)
	  elog_die(FATAL, "[1] shouldn't have read access to http %s", 
		   TURL1);
     r = rt_http_access(TURL1, NULL, TURL1, ROUTE_WRITEOK);
     if (r)
	  elog_die(FATAL, "[1] shouldn't have write access to http %s", 
		   TURL1);

     /* test 2: open for read only should not create http */
     lld1 = rt_http_open(TURL1, "blah", NULL, 0, TURL1);
     if (!lld1)
	  elog_die(FATAL, "[2] no open http descriptor");

     /* test 3: read an http location */
     chain = rt_http_read(lld1, 0, 0);
     if (itree_n(chain) != 1)
	  elog_die(FATAL, "[3] wrong number of buffers: %d", 
		   itree_n(chain));
     itree_first(chain);
     rtbuf = itree_get(chain);
     if (!rtbuf)
	  elog_die(FATAL, "[3] no buffer");
     if (!rtbuf->buffer)
	  elog_die(FATAL, "[3] NULL buffer");
     if (rtbuf->buflen != strlen(rtbuf->buffer))
	  elog_die(FATAL, "[3] buffer length mismatch %d != %d",
		   rtbuf->buflen, strlen(rtbuf->buffer));
     route_free_routebuf(chain);

     /* test 4: tell test */
     r = rt_http_tell(lld1, &seq1, &size1, &time1);
     if (r)
	  elog_die(FATAL, "[4] http tell should always fail");
     rt_http_close(lld1);

     cf_destroy(cf);
     rt_http_fini();
     return 0;
}
コード例 #2
0
ファイル: configfile.c プロジェクト: garlick/gpib-utils
struct cf_file *cf_create_default (void)
{
    struct cf_file *cf = NULL;
    char path[PATH_MAX];
    char *env;

    if ((env = getenv ("GPIB_UTILS_CONF")))
        cf = cf_create (env);
    if (!cf) {
        struct passwd *pw = getpwuid (geteuid ());
        if (pw) {
            snprintf (path, sizeof (path), "%s/.gpib-utils.conf", pw->pw_dir);
            cf = cf_create (path);
        }
    }
    if (!cf) {
        snprintf (path, sizeof (path), "%s/gpib-utils.conf", X_SYSCONFDIR);
        cf = cf_create (path);
    }
    return cf;
}
コード例 #3
0
ファイル: iiab.c プロジェクト: SystemGarden/habitat
/*
 * Initialise standard routes, logging, configuration, interpret 
 * command line and change directory.
 *
 * A standard set of rules is followed to setup the correct
 * configuration from central places local files and the command line.
 * All the information is then available in the global CF_VALS: iiab_cf.
 * The command line config is available in iiab_cmdarg on its own and also
 * placed in iiab_cf.
 * There are some standard options implemented by this routine:-
 *     -c Configuration file (arg expected)
 *     -C Configuration option (arg expected)
 *     -d Diagnostic debug mode
 *     -D Developer debug mode
 *     -e 'off the shelf' error format (int arg expected 1-7)
 *     -h Help
 *     -v Version print and exit
 * Note:-
 * 1.  If the symbol defined by NM_CFNAME (nmalloc) is not defined or 
 *     set to 0, nmalloc leak checks are disabled
 */
void iiab_start(char *opts,	/* Command line option string as getopts(3) */
		int argc,	/* Number of arguments in command line */
		char **argv,	/* Array of argument strings */
		char *usage,	/* String describing usage */
		char *appcf	/* Application configuration string */ )
{
     int r;
     char *appcf_expanded;
     int elogfmt;

     if ( !(opts && usage) )
	  elog_die(FATAL, "opts or usage not set");

     /* save our launch directory & work out the standard places */
     iiab_dir_locations(argv[0]);

     /* consolidated command line options and usage */
     /* -- setup global variables -- */
     iiab_cmdopts  = util_strjoin(IIAB_DEFOPTS, opts, NULL);
     iiab_cmdusage = util_strjoin(IIAB_DEFUSAGE, usage, usage?"\n":"", 
				  IIAB_DEFWHERE, NULL);
     iiab_cmdarg   = cf_create();
     iiab_cf       = cf_create();

     /* initialise common IIAB classes: callbacks, error logging, 
      * i/o and old storage routes */
     callback_init();
     iiab_init_routes();     /* initialise new route mechanism */
     elog_init(1, argv[0], NULL);
     rs_init();

     /* collect command line arguments and place in special config list
      * which is use for generating the main config list
      */
     r = cf_cmd(iiab_cmdarg, iiab_cmdopts, argc, argv, iiab_cmdusage);
     if ( ! r ) {
          nm_deactivate();
	  elog_send(FATAL, "incorrect command line, can't continue further");
	  exit(1);
     }

     /* help! print out help before we do anything else and send it
      * to stderr as the user needs to read it */
     if (cf_defined(iiab_cmdarg, "h")) {
          nm_deactivate();
	  fprintf(stderr, "usage %s %s", 
		  cf_getstr(iiab_cmdarg,"argv0"), iiab_cmdusage);
	  exit(1);
     }

     /* load app's dir locations into config, expand the application config
      * string (which needs the dir locations in iiab_cf), then do the
      * fullconfig load */
     iiab_dir_setcf(iiab_cf);
     appcf_expanded = nmalloc(strlen(appcf) * 2);
     route_expand(appcf_expanded, appcf, NULL, 0);
     iiab_cf_load(iiab_cf, iiab_cmdarg, iiab_cmdusage, appcf_expanded);
     nfree(appcf_expanded);

     /***********************************************
      * (d) Carry out common configuration actions
      * 1. configure event logging
      * 2. memory checking 
      * 3. version switch
      * 4. adapt logging for -d and -D special debug cases
      * 5. adapt logging format for -e
      * 6. final initialisation for subsystems needing configuration
      * 7. license checking: go/no-go
      ***********************************************/

     /* configure event logging */
     elog_configure(iiab_cf);

     /*
      * nmalloc deactivation check.
      * Deactivate nmalloc checking if NM_CFNAME is set to 0 in config
      */
     if ( !cf_defined(iiab_cf, NM_CFNAME) ||
	  cf_getint(iiab_cf, NM_CFNAME) == 0 )
	  nm_deactivate();

     /* command line switches (excluding -c and -C) */

     /* -v flag: version print and exit */
     if (cf_defined(iiab_cmdarg, "v")) {
	  fprintf(stderr, "Version of %s is %s\n", 
		  cf_getstr(iiab_cmdarg,"argv0"), VERSION);
	  exit(0);
     }
     /* if -d diag flag specified, override supplied event 
      * configuration and instead route DIAG and above to stderr */
     if (cf_defined(iiab_cmdarg, "d")) {
	  elog_setallpurl("none:");
	  elog_setabovepurl(DIAG, "stderr:");
	  elog_printf(DIAG, "event configuration overidden: diagnosis "
		      "to stderr");
     }
     /* -D debug flag: as above but route everything to stderr */
     if (cf_defined(iiab_cmdarg, "D")) {
	  elog_setabovepurl(DEBUG, "stderr:");
	  elog_printf(DEBUG, "event configuration overidden: debug "
		      "to stderr");
     }

     /* -e flag: use precanned elog formats */
     if (cf_defined(iiab_cmdarg, "e")) {
	  elogfmt = cf_getint(iiab_cmdarg, "e");
	  if (elogfmt < 0 || elogfmt > ELOG_MAXFMT)
	       elog_printf(ERROR, "standard error format out of range "
			   "(0-%d), using default", ELOG_MAXFMT);
	  else
	       elog_setallformat(elog_stdfmt[elogfmt]);
     }


     /*  diagnostics: config and dirs */
     cf_dump(iiab_cf);		/* dump config to diag */
     iiab_dir_dump();		/* dump dir locations to diag */

     /* final set of initialisations that require configurations */
     http_init();

#if 0
     /* self destruction due to snapshot time out, licenses etc
      * disabled, but kept here just in case we want to do it again */
     if ( ! cf_defined(iiab_cf, IIAB_LICNAME) )
	  if (time(NULL) > IIAB_EXPIRE)
	       elog_printf(FATAL, "This is development software "
			   "and almost certainly out of date.\n"
			   "You should arrange an update from system garden "
			   "by e-mailing [email protected]\n"
			   "or checking the web site "
			   "http://www.systemgarden.com.\n"
			   "This software will run unaffected in its current "
			   "form but you will be nagged from now on");
#endif

#if 0
     /* return to the launch dir */
     chdir(iiab_dir_launch);
#endif
}