Example #1
0
/* Load all users from the user file. */
int umgr_load(UMGR *umgr){
  CBLIST *lines, *elems;
  const char *line;
  char path[URIBUFSIZ];
  int i, size;
  assert(umgr);
  log_print(LL_INFO, "loading the user list");
  sprintf(path, "%s%c%s", umgr->rootdir, ESTPATHCHR, USERFILE);
  if(!(lines = cbreadlines(path))){
    log_print(LL_ERROR, "loading the user list failed");
    return FALSE;
  }
  for(i = 0; i < cblistnum(lines); i++){
    line = cblistval(lines, i, &size);
    if(size < 1) continue;
    elems = cbsplit(line, size, "\t");
    if(cblistnum(elems) >= 5){
      umgr_put(umgr, cblistval(elems, 0, NULL), cblistval(elems, 1, NULL),
               cblistval(elems, 2, NULL), cblistval(elems, 3, NULL), cblistval(elems, 4, NULL));
    } else {
      log_print(LL_WARN, "invalid line: %d", i + 1);
    }
    cblistclose(elems);
  }
  cblistclose(lines);
  return TRUE;
}
Example #2
0
File: qutil.c Project: Piro77/qupl
/* get a map of the cookie */
CBMAP *getcookie(void){
  CBMAP *params;
  CBLIST *pairs;
  char *rbuf, *buf, *key, *val, *dkey, *dval;
  int i;
  params = cbmapopen();
  rbuf = NULL;
  buf = NULL;
  buf = getenv("HTTP_COOKIE");
  if(buf != NULL){
    buf = cbmemdup(buf, -1);
    pairs = cbsplit(buf, -1, ";");
    for(i = 0; i < cblistnum(pairs); i++){
      key = cbmemdup(cblistval(pairs, i, NULL), -1);
      if((val = strchr(key, '=')) != NULL){
        *(val++) = '\0';
        dkey = cburldecode(key, NULL);
        dval = cburldecode(val, NULL);
        cbmapput(params, dkey, -1, dval, -1, FALSE);
        free(dval);
        free(dkey);
      }
      free(key);
    }
    cblistclose(pairs);
    free(buf);
  }
  else {
    return NULL;
  }
  return params;
}
Example #3
0
/* Converts from a CBLIST of char * strings to a Ruby Array of Strings. */
VALUE CBLIST_2_array(const CBLIST *list) 
{
    int count = cblistnum(list);
    int i = 0;
    VALUE ary = rb_ary_new2(count);
    
    for(i = 0; i < count;  i++) {
        int sp = 0;
        const char *val = cblistval(list, i, &sp);
        rb_ary_push(ary, rb_str_new(val, sp));
    }
    
    return ary;
}
Example #4
0
jobject cblisttoobj(JNIEnv *env, const CBLIST *list){
  jclass cls;
  jmethodID mid;
  jobject obj, kobj;
  int i;
  assert(list);
  cls = (*env)->FindClass(env, CLSARRAYLIST);
  mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
  obj = (*env)->NewObject(env, cls, mid);
  mid = (*env)->GetMethodID(env, cls, "add", "(L" CLSOBJECT ";)Z");
  for(i = 0; i < cblistnum(list); i++){
    kobj = (*env)->NewStringUTF(env, cblistval(list, i, NULL));
    (*env)->CallVoidMethod(env, obj, mid, kobj);
    (*env)->DeleteLocalRef(env, kobj);
  }
  return obj;
}
Example #5
0
/* Load all nodes from the node directory. */
int nmgr_load(NMGR *nmgr, int wmode){
  CBLIST *list;
  const char *file;
  char path[URIBUFSIZ];
  int i, err;
  assert(nmgr);
  sprintf(path, "%s%c%s", nmgr->rootdir, ESTPATHCHR, NODEDIR);
  if(!(list = cbdirlist(path))){
    log_print(LL_ERROR, "loading the node directory failed");
    return FALSE;
  }
  err = FALSE;
  for(i = 0; i < cblistnum(list); i++){
    file = cblistval(list, i, NULL);
    if(!strcmp(file, ESTCDIRSTR) || !strcmp(file, ESTPDIRSTR)) continue;
    if(!nmgr_put(nmgr, file, wmode, 0)) err = TRUE;
  }
  cblistclose(list);
  return err ? FALSE : TRUE;
}
Example #6
0
File: qutil.c Project: Piro77/qupl
/* get a map of the CGI parameters */
CBMAP *getparams(void){
  CBMAP *params;
  CBLIST *pairs;
  char *rbuf, *buf, *key, *val, *dkey, *dval;
  const char *tmp;
  int i, len, c;
  params = cbmapopen();
  rbuf = NULL;
  buf = NULL;
  if((tmp = getenv("CONTENT_LENGTH")) != NULL && (len = atoi(tmp)) > 0 && len <= RDATAMAX){
    rbuf = cbmalloc(len + 1);
    for(i = 0; i < len && (c = getchar()) != EOF; i++){
      rbuf[i] = c;
    }
    rbuf[i] = '\0';
    if(i == len) buf = rbuf;
  } else {
    buf = getenv("QUERY_STRING");
  }
  if(buf != NULL){
    buf = cbmemdup(buf, -1);
    pairs = cbsplit(buf, -1, "&");
    for(i = 0; i < cblistnum(pairs); i++){
      key = cbmemdup(cblistval(pairs, i, NULL), -1);
      if((val = strchr(key, '=')) != NULL){
        *(val++) = '\0';
        dkey = cburldecode(key, NULL);
        dval = cburldecode(val, NULL);
        cbmapput(params, dkey, -1, dval, -1, FALSE);
        free(dval);
        free(dkey);
      }
      free(key);
    }
    cblistclose(pairs);
    free(buf);
  }
  free(rbuf);
  return params;
}
Example #7
0
/**
 * call-seq:
 *   document.add_content(index, content) -> document
 *
 * Takes the contents, breaks the words up, and then puts them in the document
 * in normalized form.  This is the common pattern that people use a Document
 * with.  You may also use Document.addword to add one word a time, and
 * Document.add_word_list to add a list of words.
 *
 * It uses the default odanalyzetext method to break up the text,
 * which means you can use the Index::setcharclass method to configure
 * what is a DELIM, GLUE, and SPACE character.  The default is the same
 * as Odeum::breaktext.
 *
 * If the process of normalizing a word creates an empty word, then it
 * is not added to the document's words.  This usually happens for
 * punctation that isn't usualy searched for anyway.
 *
 * The Index used with this document is now required since that object holds
 * the information about how text is broken via the Index::setcharclass method.
 */
VALUE Document_add_content(VALUE self, VALUE index, VALUE content) {
    CBLIST *asis_words = NULL;
    CBLIST *norm_words = NULL;
    const char *asis = NULL;
    const char *norm = NULL;
    int asis_len = 0;
    int norm_len = 0;
    int i = 0;
    int count = 0;
    ODDOC *oddoc = NULL;
    ODEUM *odeum = NULL;
    
    DATA_GET(self,ODDOC, oddoc);
    DATA_GET(index,ODEUM, odeum);
    
    
    REQUIRE_TYPE(content, T_STRING);
    
    asis_words = cblistopen();
    norm_words = cblistopen();
    
    odanalyzetext(odeum, RSTRING(content)->ptr, asis_words, norm_words);
    
    // go through words and add them
    count = cblistnum(asis_words);
    
    for(i = 0; i < count;  i++) {
        asis = cblistval(asis_words, i, &asis_len);
        norm = cblistval(norm_words, i, &norm_len);
        
        // only add words that normalize to some content
        oddocaddword(oddoc, norm, asis);
    }
    
    cblistclose(asis_words);
    cblistclose(norm_words);
    
    return self;
}
Example #8
0
/* Add a node to a node manager object. */
int nmgr_put(NMGR *nmgr, const char *name, int wmode, int options){
  NODE node;
  ESTMTDB *db;
  CBLIST *list;
  const char *cbuf, *pv;
  char pbuf[URIBUFSIZ], *vbuf;
  int i, ecode, csiz;
  assert(nmgr && name);
  log_print(LL_DEBUG, "nmgr_put: %s", name);
  if(name[0] == '\0' || cbmapget(nmgr->nodes, name, -1, NULL)){
    log_print(LL_WARN, "duplicated or empty node name: %s", name);
    return FALSE;
  }
  if(strlen(name) >= NODENAMEMAX || !check_alnum_name(name)){
    log_print(LL_WARN, "invalid node name: %s", name);
    return FALSE;
  }
  log_print(LL_INFO, "opening a node (%s): %s", wmode ? "WRITER" : "READER", name);
  sprintf(pbuf, "%s%c%s%c%s", nmgr->rootdir, ESTPATHCHR, NODEDIR, ESTPATHCHR, name);
  if(!(db = est_mtdb_open(pbuf, wmode ? ESTDBWRITER | ESTDBCREAT | options : ESTDBREADER,
                          &ecode))){
    log_print(LL_ERROR, "DB-ERROR: %s", est_err_msg(ecode));
    return FALSE;
  }
  est_mtdb_set_informer(db, db_informer, NULL);
  cbmapiterinit(nmgr->aidxs);
  while((cbuf = cbmapiternext(nmgr->aidxs, NULL)) != NULL){
    est_mtdb_add_attr_index(db, cbuf, *(int *)cbmapiterval(cbuf, NULL));
  }
  node.db = db;
  est_mtdb_add_meta(db, NMKNAME, name);
  node.name = cbmemdup(name, -1);
  vbuf = est_mtdb_meta(db, NMKLABEL);
  node.label = vbuf ? vbuf : cbmemdup(name, -1);
  if((vbuf = est_mtdb_meta(db, NMKADMINS)) != NULL){
    list = cbsplit(vbuf, -1, "\n");
    node.admins = cbmapopenex(cblistnum(list) + MINIBNUM);
    for(i = 0; i < cblistnum(list); i++){
      cbuf = cblistval(list, i, &csiz);
      if(csiz < 1) continue;
      cbmapput(node.admins, cbuf, csiz, "", 0, FALSE);
    }
    cblistclose(list);
    free(vbuf);
  } else {
    node.admins = cbmapopenex(MINIBNUM);
  }
  if((vbuf = est_mtdb_meta(db, NMKUSERS)) != NULL){
    list = cbsplit(vbuf, -1, "\n");
    node.users = cbmapopenex(cblistnum(list) + MINIBNUM);
    for(i = 0; i < cblistnum(list); i++){
      cbuf = cblistval(list, i, &csiz);
      if(csiz < 1) continue;
      cbmapput(node.users, cbuf, csiz, "", 0, FALSE);
    }
    cblistclose(list);
    free(vbuf);
  } else {
    node.users = cbmapopenex(MINIBNUM);
  }
  if((vbuf = est_mtdb_meta(db, NMKLINKS)) != NULL){
    list = cbsplit(vbuf, -1, "\n");
    node.links = cbmapopenex(cblistnum(list) + MINIBNUM);
    for(i = 0; i < cblistnum(list); i++){
      cbuf = cblistval(list, i, NULL);
      if(!(pv = strchr(cbuf, '\t'))) continue;
      cbmapput(node.links, cbuf, pv - cbuf, pv + 1, -1, FALSE);
    }
    cblistclose(list);
    free(vbuf);
  } else {
    node.links = cbmapopenex(MINIBNUM);
  }
  node.mtime = time(NULL);
  node.dirty = FALSE;
  pthread_mutex_init(&(node.mutex), NULL);
  cbmapput(nmgr->nodes, name, -1, (char *)&node, sizeof(NODE), FALSE);
  return TRUE;
}