Esempio n. 1
0
struct cf_file *cf_create (const char *pathname)
{
    struct cf_file *cf = xzmalloc (sizeof (*cf));
    int saved_errno;
    int rc;

    cf->magic = CF_MAGIC;
    cf->db = hash_create (0, (hash_key_f)hash_key_string,
                             (hash_cmp_f)strcmp,
                             (hash_del_f)cfi_destroy);
    rc = ini_parse (pathname, parse_cb, cf);
    if (rc == -1) { /* open error */
        goto error;
    } else if (rc == -2) { /* out of mem */
        errno = ENOMEM;
        goto error;
    } else if (rc > 0) { /* line number */
        fprintf (stderr, "%s line %d: parse error\n", pathname, rc);
        errno = EINVAL;
        goto error;
    }
    return cf;
error:
    saved_errno = errno;
    cf_destroy (cf);
    errno = saved_errno;
    return NULL;
}
Esempio n. 2
0
void iiab_stop()
{
     /* remove lock file if applicable */
     if (iiab_havelock) {
	  unlink(iiab_havelock);
	  nfree(iiab_havelock);
     }

     /* finalise and free iiab class data */
     nfree(iiab_cmdopts);
     nfree(iiab_cmdusage);
     cf_destroy(iiab_cmdarg);
     cf_destroy(iiab_cf);

     /* finalise co-operative clases co-ordinated by iiab */
     rs_fini();
     elog_fini();
     route_fini();
     callback_fini();
     iiab_free_dir_locations();
}
Esempio n. 3
0
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;
}