Exemple #1
0
easy_lr* range_easy_create(const char* config_file) {
  easy_lr* elr = malloc(sizeof(easy_lr));
  int debug = 0;
  // The apr bits -- must pair this with apr_terminate()
  apr_initialize();
  apr_pool_create(&(elr->pool), NULL);
  apr_pool_create(&(elr->querypool), elr->pool); // pool for transient range eval - cleared at each eval
  //create a real lr
  elr->lr = libcrange_new(elr->pool, config_file);

  if (debug) {
    printf("DEBUG: after libcrange_new have an lr with attrs:\n");
    printf("DEBUG: lr->default_domain: %s\n", elr->lr->default_domain);
    printf("DEBUG: lr->confdir: %s\n", elr->lr->confdir);
    printf("DEBUG: lr->config_file: %s\n", elr->lr->config_file);
    printf("DEBUG: lr->funcdir: %s\n", elr->lr->funcdir);
    printf("DEBUG: lr->want_caching: %d\n", elr->lr->want_caching);
    dump_hash_values(elr->lr->vars);
    fprintf(stderr, "DEBUG: lr->vars: ");
    set_dump(elr->lr->vars);
  }

  // copy/reference bits from it, to public config in easy_lr
  return elr;
}
Exemple #2
0
libcrange* get_static_lr(void)
{
    if (static_lr == NULL) {
        apr_pool_create(&static_pool, NULL);
        static_lr = libcrange_new(static_pool, NULL);
        atexit(destroy_static_pool);
    }

    return static_lr;
}
Exemple #3
0
/* TODO: Comment */
static void *doit(void *a){
  int rc, thread_id = (pthread_t) a;
  FCGX_Request request;
  apr_pool_t* pool;
  struct range_request* rr;
  struct libcrange *lr;
  char *config_file = NULL;
  char * r_query;		/* range query */
  int r_status = 0;

  apr_initialize();
  atexit(apr_terminate);
  apr_pool_create(&pool, NULL);

  config_file = LIBCRANGE_CONF;

  lr = libcrange_new(pool, config_file);

  /* malloc for query */
  r_query = (char *)malloc(QUERY_STR_SIZE);

  FCGX_InitRequest(&request, 0, 0);

  for (;;)
    {
      static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER;

      apr_pool_t* sub_pool;

      apr_pool_create(&sub_pool, pool);

      /* zero it out */
      bzero(r_query, QUERY_STR_SIZE);
      r_status = 0;
	

      /* Some platforms require accept() serialization, some don't.. */
      pthread_mutex_lock(&accept_mutex);
      rc = FCGX_Accept_r(&request);
      pthread_mutex_unlock(&accept_mutex);

      if (rc < 0)
	break;

      
      r_status = get_range_query(&request, r_query);
      rr = range_expand(lr, sub_pool, r_query);

      FCGX_FPrintF(request.out, "Content-type: text/plain\r\n");
      
      /* set headers */
      if (range_request_has_warnings(rr)) {
      	const char *warnings = range_request_warnings(rr);
      	FCGX_FPrintF(request.out,
      		     "RangeException: %s\r\nRange_FCGI_Thread_Id: %d\r\n",
      		     warnings, thread_id);
      }

      /* End Delimiter */
      FCGX_FPrintF(request.out, "\r\n");

      /* r_status == 1, then wants list */
      if (r_status == 1) {
      	const char **nodes = range_request_nodes(rr);
      	while(*nodes) {
      	  FCGX_FPrintF(request.out, "%s\n", *nodes++);
      	}
      } else if (r_status == 0) {
      	FCGX_FPrintF(request.out, "%s\n", range_request_compressed(rr));
      }
      
      apr_pool_destroy(sub_pool);

      FCGX_Finish_r(&request);

    } /* for (;;) */

  /* free, what I hogged :-) */
  free(r_query);

  apr_pool_destroy(pool);

  return NULL;
}