Ejemplo n.º 1
0
/*
 * df_static_trigger - look thru the display filter list and set the
 *		       filter to any triggers that don't require scanning
 *		       the message segment.
 */
char *
dfilter_trigger(struct mail_bodystruct *body, char *cmdbuf, size_t cmdbuflen)
{
    int    passed = 0;
    char **l, *test, *cmd;

    for(l = ps_global->VAR_DISPLAY_FILTERS ; l && *l && !passed; l++){

	get_pair(*l, &test, &cmd, 1, 1);

	dprint((5, "static trigger: \"%s\" --> \"%s\" and \"%s\"",
		   (l && *l) ? *l : "?",
		   test ? test : "<NULL>", cmd ? cmd : "<NULL>"));

	if((passed = (df_valid_test(body, test) && valid_filter_command(&cmd))) != 0){
	  strncpy(cmdbuf, cmd, cmdbuflen);
	  cmdbuf[cmdbuflen-1] = '\0';
	}

	fs_give((void **) &test);
	fs_give((void **) &cmd);
    }

    return(passed ? cmdbuf : NULL);
}
Ejemplo n.º 2
0
API void dump_line(value_t val) {
  if (val.type == PairType) {
    pair_t pair = get_pair(val);
    unsee();
    _dump(pair.left);
    val = pair.right;
    while (val.type == PairType) {
      print_char(' ');
      pair_t pair = get_pair(val);
      unsee();
      _dump(pair.left);
      val = pair.right;
    }
  }
  print(COFF"\n");
}
Ejemplo n.º 3
0
API value_t list_remove(value_t list, value_t val) {
  if (list.type != PairType) return Nil;
  pair_t pair = get_pair(list);
  if (eq(pair.left, val)) return pair.right;
  value_t prev = list;
  value_t node = pair.right;
  while (node.type == PairType) {
    pair = get_pair(node);
    if (eq(pair.left, val)) {
      set_cdr(prev, pair.right);
      break;
    }
    node = pair.right;
  }
  return list;
}
Ejemplo n.º 4
0
int oss_map_get(const oss_map_t *map, const char *key, char *out_buf, unsigned int out_buf_len)
{
	unsigned int index;
	oss_bucket_t *bucket;
	oss_pair_t *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
	if (out_buf == NULL && out_buf_len == 0) {
		return strlen(pair->value) + 1;
	}
	if (out_buf == NULL) {
		return 0;
	}
	if (strlen(pair->value) >= out_buf_len) {
		return 0;
	}
	strcpy(out_buf, pair->value);
	return 1;
}
Ejemplo n.º 5
0
Archivo: strmap.c Proyecto: jkal/toyws
int strmap_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf)
{
	unsigned int index;
	Bucket *bucket;
	Pair *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
	if (out_buf == NULL && n_out_buf == 0) {
		return strlen(pair->value) + 1;
	}
	if (out_buf == NULL) {
		return 0;
	}
	if (strlen(pair->value) >= n_out_buf) {
		return 0;
	}
	strcpy(out_buf, pair->value);
	return 1;
}
Ejemplo n.º 6
0
API bool list_has(value_t list, value_t val) {
  while (list.type == PairType) {
    pair_t pair = get_pair(list);
    if (eq(pair.left, val)) return true;
    list = pair.right;
  }
  return false;
}
Ejemplo n.º 7
0
Node* make_graph(int start, int end){
    /*
        Recursive function:
        It returns the root node
        of each subgraph
    */
    Node *node;
    int last_arg;
    char aux_int = 'x';

    last_arg = get_last_arg(start, end);

    if (input[start] == '(' && input[end] == ')' && end == get_pair(start)) {
        node = make_graph(start+1, end-1);
    }
    else if (input[start] == '[' && input[end] == ']' && end == get_pair(start)) {
        node = (Node*) malloc(sizeof(Node));
        node->type = '@';
        node->left = make_leaf(':');
        node->right = make_graph(start+1, end-1);
    }
    else if (last_arg == start || (input[start] >= 48 && input[start] <=57)) {
        if (input[start] >= 48 && input[start] <= 57)
            node = make_Nleaf(start,last_arg);
        else
            node = make_leaf(input[start]);
    }
    else {

        node = (Node*) malloc(sizeof(Node));
        node->type = '@';

        // if (input[end] == '+' || input[end] == '-'){
        //     node->left = make_leaf(input[end]);
        //     node->right = make_graph(start, end-1);
        // }
        // else {
            node->left = make_graph(start, last_arg-1);
            node->right = make_graph(last_arg, end);
        // }
    }

    return node;

}
Ejemplo n.º 8
0
API value_t list_reverse(value_t list) {
  value_t copy = Nil;
  while (list.type == PairType) {
    pair_t pair = get_pair(list);
    copy = cons(pair.left, copy);
    list = pair.right;
  }
  return copy;
}
Ejemplo n.º 9
0
// in-place reverse.
API value_t list_ireverse(value_t list) {
  value_t reversed = Nil;
  while (list.type == PairType) {
    pair_t pair = get_pair(list);
    set_cdr(list, reversed);
    reversed = list;
    list = pair.right;
  }
  return reversed;
}
Ejemplo n.º 10
0
pointer create_pair(pointer car, pointer cdr)
{
    pointer ret = ploy_alloc(get_type(DT_Pair));

    pair* value = get_pair(ret);

    value->_car = car;
    value->_cdr = cdr;

    return ret;
}
Ejemplo n.º 11
0
API value_t list_sort(value_t list) {
  if (isNil(list)) return Nil;
  if (list.type != PairType) return TypeError;
  value_t before = Nil, after = Nil;
  pair_t pair = get_pair(list);
  value_t node = pair.right;
  while (node.type == PairType) {
    pair_t next = get_pair(node);
    if (pair.left.raw > next.left.raw) {
      before = cons(next.left, before);
    }
    else {
      after = cons(next.left, after);
    }
    node = next.right;
  }
  return list_append(
    list_sort(before),
    cons(pair.left, list_sort(after)));
}
Ejemplo n.º 12
0
const char *dino_strmap_get_value(const str_map_t *map, const char *key) {
    if (NULL == map || NULL == key) {
        return "";
    }

    unsigned int index = (unsigned int) (hash(key) % map->count);
    bucket_t *bucket = &(map->buckets[index]);
    pair_t *pair = get_pair(bucket, key);
    if (NULL == pair) {
        return "";
    }

    return pair->value;
}
Ejemplo n.º 13
0
API value_t list_add(value_t list, value_t val) {
  if (isNil(list)) return cons(val, Nil);
  value_t node = list;
  while (node.type == PairType) {
    pair_t pair = get_pair(node);
    if (eq(pair.left, val)) return list;
    if (isNil(pair.right)) {
      set_cdr(node, cons(val, Nil));
      return list;
    }
    node = pair.right;
  }
  return TypeError;
}
Ejemplo n.º 14
0
bool dino_strmap_exists(const str_map_t *map, const char *key) {
    if (NULL == map || NULL == key) {
        return false;
    }

    unsigned int index = (unsigned int) (hash(key) % map->count);
    bucket_t *bucket = &(map->buckets[index]);
    pair_t *pair = get_pair(bucket, key);

    if (NULL == pair) {
        return false;
    }

    return true;
}
Ejemplo n.º 15
0
int main()
{
	struct indicator *indicators;
	struct strategy *strategies;
	struct coll_ctrl_blk *coll_ctrl_blks;

	indicators = load_indicators("indicators.xml");
	print_indicators(indicators);
	//destroy_indicators(indicators);
	strategies = load_strategies("strategies.xml");
	print_strategies(strategies);
	//destroy_strategies(strategies);
	//printf("name offset in Indicator is: %u\n", offsetof(struct indicator, name));
	//printf("size of int: %u\n", sizeof(int));
	struct data data;
	init_data(&data);
	put_value(&data, "hello", "wold");
	struct pair *pair_ptr = get_pair(&data, "hello");
	printf("%s, %s\n", pair_ptr->name, pair_ptr->value);
	coll_ctrl_blks = generate_coll_ctrl_blks(indicators, strategies);
	print_coll_ctrl_blks(coll_ctrl_blks);
	struct coll_ctrl_blk *coll_ctrl_blk_ptr = find_coll_ctrl_blk(coll_ctrl_blks, 1);
	printf("Indicator NAME: %s\n", coll_ctrl_blk_ptr->indicator_ptr->name);
	generate_coll_commands(coll_ctrl_blk_ptr);
	
	destroy_indicators(indicators);
	destroy_strategies(strategies);

	ssh_init();
	struct ssh_client client;
	struct line *lines;
	init_client(&client);
	login(&client, "127.0.0.1", 22, "tshi", "123456");
	lines = exec_command(&client, "date");
	print_lines(lines);
	destroy_lines(lines);
	lines = exec_command(&client, "top -b -n 1");
	print_lines(lines);
	destroy_lines(lines);
	close_client(&client);
	ssh_exit();
	
	return (0);
}
Ejemplo n.º 16
0
int oss_map_exists(const oss_map_t *map, const char *key)
{
	unsigned int index;
	oss_bucket_t *bucket;
	oss_pair_t *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
	return 1;
}
Ejemplo n.º 17
0
void *map_get(const Map *map, const char *key)
{
    unsigned int index;
    Bucket *bucket;
    Pair *pair;

    if (map == NULL) {
        return NULL;
    }
    if (key == NULL) {
        return NULL;
    }
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    pair = get_pair(map, bucket, key);
    if (pair == NULL) {
        return NULL;
    }
    return pair->value;
}
Ejemplo n.º 18
0
Archivo: strmap.c Proyecto: jkal/toyws
int strmap_exists(const StrMap *map, const char *key)
{
	unsigned int index;
	Bucket *bucket;
	Pair *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
	return 1;
}
Ejemplo n.º 19
0
int sm_get(const StrMap *map, const char *key, void **out_buf)
{
	unsigned int index;
	Bucket *bucket;
	Pair *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
  *out_buf = pair->value;
	return 1;
}
Ejemplo n.º 20
0
/*
 * Read the keywords array into a KEYWORD_S structure.
 * Make sure that all of the strings are UTF-8.
 */
KEYWORD_S *
init_keyword_list(char **keywordarray)
{
    char     **t, *nickname, *keyword;
    KEYWORD_S *head = NULL, **tail;

    tail = &head;
    for(t = keywordarray; t && *t && **t; t++){
	nickname = keyword = NULL;
	get_pair(*t, &nickname, &keyword, 0, 0);
	*tail = new_keyword_s(keyword, nickname);
	tail  = &(*tail)->next;

	if(keyword)
	  fs_give((void **) &keyword);

	if(nickname)
	  fs_give((void **) &nickname);
    }

    return(head);
}
Ejemplo n.º 21
0
int sm_remove(const StrMap *map, const char *key)
{
	unsigned int index;
	Bucket *bucket;
	Pair *pair;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL) {
		return 0;
	}
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	pair = get_pair(bucket, key);
	if (pair == NULL) {
		return 0;
	}
	pair->value = NULL;
	
	return 1;
}
Ejemplo n.º 22
0
size_t  __unused dino_strmap_get(const str_map_t *map, const char *key, char *out_buf, unsigned int n_out_buf) {
    if (NULL == map || NULL == key) {
        return 0;
    }

    unsigned int index = (unsigned int) (hash(key) % map->count);
    bucket_t *bucket = &(map->buckets[index]);
    pair_t *pair = get_pair(bucket, key);
    if (NULL == pair) {
        return 0;
    }
    if (NULL == out_buf && n_out_buf == 0) {
        return strlen(pair->value) + 1;
    }
    if (NULL == out_buf) {
        return 0;
    }
    if (strlen(pair->value) >= n_out_buf) {
        return 0;
    }
    strcpy(out_buf, pair->value);

    return 1;
}
Ejemplo n.º 23
0
CURLdigest Curl_input_digest(struct connectdata *conn,
                             bool proxy,
                             const char *header) /* rest of the *-authenticate:
                                                    header */
{
  bool more = TRUE;
  char *token = NULL;
  char *tmp = NULL;
  bool foundAuth = FALSE;
  bool foundAuthInt = FALSE;
  struct SessionHandle *data=conn->data;
  bool before = FALSE; /* got a nonce before */
  struct digestdata *d;

  if(proxy) {
    d = &data->state.proxydigest;
  }
  else {
    d = &data->state.digest;
  }

  /* skip initial whitespaces */
  while(*header && ISSPACE(*header))
    header++;

  if(checkprefix("Digest", header)) {
    header += strlen("Digest");

    /* If we already have received a nonce, keep that in mind */
    if(d->nonce)
      before = TRUE;

    /* clear off any former leftovers and init to defaults */
    Curl_digest_cleanup_one(d);

    while(more) {
      char value[MAX_VALUE_LENGTH];
      char content[MAX_CONTENT_LENGTH];

      while(*header && ISSPACE(*header))
        header++;

      /* extract a value=content pair */
      if(!get_pair(header, value, content, &header)) {
        if(Curl_raw_equal(value, "nonce")) {
          d->nonce = strdup(content);
          if(!d->nonce)
            return CURLDIGEST_NOMEM;
        }
        else if(Curl_raw_equal(value, "stale")) {
          if(Curl_raw_equal(content, "true")) {
            d->stale = TRUE;
            d->nc = 1; /* we make a new nonce now */
          }
        }
        else if(Curl_raw_equal(value, "realm")) {
          d->realm = strdup(content);
          if(!d->realm)
            return CURLDIGEST_NOMEM;
        }
        else if(Curl_raw_equal(value, "opaque")) {
          d->opaque = strdup(content);
          if(!d->opaque)
            return CURLDIGEST_NOMEM;
        }
        else if(Curl_raw_equal(value, "qop")) {
          char *tok_buf;
          /* tokenize the list and choose auth if possible, use a temporary
             clone of the buffer since strtok_r() ruins it */
          tmp = strdup(content);
          if(!tmp)
            return CURLDIGEST_NOMEM;
          token = strtok_r(tmp, ",", &tok_buf);
          while(token != NULL) {
            if(Curl_raw_equal(token, "auth")) {
              foundAuth = TRUE;
            }
            else if(Curl_raw_equal(token, "auth-int")) {
              foundAuthInt = TRUE;
            }
            token = strtok_r(NULL, ",", &tok_buf);
          }
          free(tmp);
          /*select only auth o auth-int. Otherwise, ignore*/
          if(foundAuth) {
            d->qop = strdup("auth");
            if(!d->qop)
              return CURLDIGEST_NOMEM;
          }
          else if(foundAuthInt) {
            d->qop = strdup("auth-int");
            if(!d->qop)
              return CURLDIGEST_NOMEM;
          }
        }
        else if(Curl_raw_equal(value, "algorithm")) {
          d->algorithm = strdup(content);
          if(!d->algorithm)
            return CURLDIGEST_NOMEM;
          if(Curl_raw_equal(content, "MD5-sess"))
            d->algo = CURLDIGESTALGO_MD5SESS;
          else if(Curl_raw_equal(content, "MD5"))
            d->algo = CURLDIGESTALGO_MD5;
          else
            return CURLDIGEST_BADALGO;
        }
        else {
          /* unknown specifier, ignore it! */
        }
      }
      else
        break; /* we're done here */

      /* pass all additional spaces here */
      while(*header && ISSPACE(*header))
        header++;
      if(',' == *header)
        /* allow the list to be comma-separated */
        header++;
    }
    /* We had a nonce since before, and we got another one now without
       'stale=true'. This means we provided bad credentials in the previous
       request */
    if(before && !d->stale)
      return CURLDIGEST_BAD;

    /* We got this header without a nonce, that's a bad Digest line! */
    if(!d->nonce)
      return CURLDIGEST_BAD;
  }
  else
    /* else not a digest, get out */
    return CURLDIGEST_NONE;

  return CURLDIGEST_FINE;
}
Ejemplo n.º 24
0
API void _dump(value_t val) {
  switch (val.type) {
    case AtomType:
      switch (val.data) {
        case -4: print(CERROR"type-error"); return;
        case -1: print(CNIL"nil"); return;
        case 1: print(CBOOL"true"); return;
        case 0: print(CBOOL"false"); return;

        default: print(CUNDEF"undefined"); return;
      }
    case IntegerType:
      print(CINT);
      print_int(val.data);
      return;
    case SymbolType:
      if (val.data < 0) print(CSYM);
      else print(CBUILTIN);
      print(symbols_get_name(val.data));
      return;
    case PairType: {
      value_t node = seen;
      while (node.type == PairType) {
        pair_t pair = get_pair(node);
        if (eq(pair.left, val)) {
          print(CPAREN"("CSEP"..."CPAREN")");
          return;
        }
        node = pair.right;
      }
      seen = cons(val, seen);
      pair_t pair = get_pair(val);
      const char *opener, *closer;
      if (eq(pair.left, quoteSym)) {
        if (pair.right.type != PairType) {
          if (pair.right.type == SymbolType && pair.right.data < 0) {
            const char* data = symbols_get_name(pair.right.data);
            const char* p = data;
            bool whole = true;
            while (whole && *p) whole = *p++ != ' ';
            if (!whole) {
              print(CSTRING"\"");
              print(data);
              print("\"");
              return;
            }
          }
          print(CPAREN"'");
          _dump(pair.right);
          return;
        }
        opener = "'(";
        closer = ")";
        val = pair.right;
        pair = get_pair(val);
      }
      else if (eq(pair.left, listSym) && pair.right.type == PairType) {
        opener = "[";
        closer = "]";
        val = pair.right;
        pair = get_pair(val);
      }
      else {
        opener = "(";
        closer = ")";
      }
      print(CPAREN);
      print(opener);
      if (isNil(pair.right)) {
        _dump(pair.left);
      }
      else if (pair.right.type == PairType) {
        _dump(pair.left);
        while (pair.right.type == PairType) {
          print_char(' ');
          pair = get_pair(pair.right);
          _dump(pair.left);
        }
        if (!isNil(pair.right)) {
          print(CSEP" . ");
          _dump(pair.right);
        }
      } else {
        _dump(pair.left);
        print(CSEP" . ");
        _dump(pair.right);
      }
      print(CPAREN);
      print(closer);
      return;
    }
  }
}
Ejemplo n.º 25
0
static ret_t
parse (cherokee_handler_ssi_t *hdl,
       cherokee_buffer_t      *in,
       cherokee_buffer_t      *out)
{
	ret_t              ret;
	char              *p, *q;
	char              *begin;
	int                re;
	cuint_t            len;
	operations_t       op;
	path_type_t        path;
	struct stat        info;
	cherokee_boolean_t ignore;
	cherokee_buffer_t  key     = CHEROKEE_BUF_INIT;
	cherokee_buffer_t  val     = CHEROKEE_BUF_INIT;
	cherokee_buffer_t  pair    = CHEROKEE_BUF_INIT;
	cherokee_buffer_t  fpath   = CHEROKEE_BUF_INIT;

	q = in->buf;

	while (true) {
		begin = q;

		/* Check the end
		 */
		if (q >= in->buf + in->len)
			break;

		/* Find next SSI tag
		 */
		p = strstr (q, "<!--#");
		if (p == NULL) {
			cherokee_buffer_add (out, begin, (in->buf + in->len) - begin);
			ret = ret_ok;
			goto out;
		}

		q = strstr (p + 5, "-->");
		if (q == NULL) {
			ret = ret_error;
			goto out;
		}

		len = q - p;
		len -= 5;

		cherokee_buffer_clean (&key);
		cherokee_buffer_add (&key, p+5, len);
		cherokee_buffer_trim (&key);

		q += 3;
		TRACE(ENTRIES, "Found key '%s'\n", key.buf);

		/* Add the previous chunk
		 */
		cherokee_buffer_add (out, begin, p - begin);

		/* Check element
		 */
		op     = op_none;
		ignore = false;

		if (strncmp (key.buf, "include", 7) == 0) {
			op  = op_include;
			len = 7;
		} else if (strncmp (key.buf, "fsize", 5) == 0) {
			op  = op_size;
			len = 5;
		} else if (strncmp (key.buf, "flastmod", 8) == 0) {
			op  = op_lastmod;
			len = 8;
		} else {
			LOG_ERROR (CHEROKEE_ERROR_HANDLER_SSI_PROPERTY, key.buf);
		}

		/* Deeper parsing
		 */
		path = path_none;

		switch (op) {
		case op_size:
		case op_include:
		case op_lastmod:
			/* Read a property key
			 */
			cherokee_buffer_move_to_begin (&key, len);
			cherokee_buffer_trim (&key);

			cherokee_buffer_clean (&pair);
			get_pair (&key, &pair);

			cherokee_buffer_drop_ending (&key, pair.len);
			cherokee_buffer_trim (&key);

			/* Parse the property
			 */
			if (strncmp (pair.buf, "file=", 5) == 0) {
				path = path_file;
				len  = 5;
			} else if (strncmp (pair.buf, "virtual=", 8) == 0) {
				path = path_virtual;
				len  = 8;
			}

			cherokee_buffer_clean (&val);
			get_val (pair.buf + len, &val);

			cherokee_buffer_clean (&fpath);

			switch (path) {
			case path_file:
				cherokee_buffer_add_buffer (&fpath, &hdl->dir);
				cherokee_buffer_add_char   (&fpath, '/');
				cherokee_buffer_add_buffer (&fpath, &val);

				TRACE(ENTRIES, "Path: file '%s'\n", fpath.buf);
				break;
			case path_virtual:
				cherokee_buffer_add_buffer (&fpath, &HANDLER_VSRV(hdl)->root);
				cherokee_buffer_add_char   (&fpath, '/');
				cherokee_buffer_add_buffer (&fpath, &val);

				TRACE(ENTRIES, "Path: virtual '%s'\n", fpath.buf);
				break;
			default:
				ignore = true;
				SHOULDNT_HAPPEN;
			}

			/* Path security check: ensure that the file
			 * to include is inside the document root.
			 */
			if (! cherokee_buffer_is_empty (&fpath)) {
				cherokee_path_short (&fpath);

				if (fpath.len < HANDLER_VSRV(hdl)->root.len) {
					ignore = true;

				}  else {
					re = strncmp (fpath.buf,
					              HANDLER_VSRV(hdl)->root.buf,
					              HANDLER_VSRV(hdl)->root.len);
					if (re != 0) {
						ignore = true;
					}
				}
			}

			/* Perform the operation
			 */
			if (! ignore) {
				switch (op) {
				case op_include: {
					cherokee_buffer_t file_content = CHEROKEE_BUF_INIT;

					ret = cherokee_buffer_read_file (&file_content, fpath.buf);
					if (unlikely (ret != ret_ok)) {
						cherokee_buffer_mrproper (&file_content);
						ret = ret_error;
						goto out;
					}

					TRACE(ENTRIES, "Including file '%s'\n", fpath.buf);

					ret = parse (hdl, &file_content, out);
					if (unlikely (ret != ret_ok)) {
						cherokee_buffer_mrproper (&file_content);
						ret = ret_error;
						goto out;
					}

					cherokee_buffer_mrproper (&file_content);
					break;
				}

				case op_size:
					TRACE(ENTRIES, "Including file size '%s'\n", fpath.buf);
					re = cherokee_stat (fpath.buf, &info);
					if (re >=0) {
						cherokee_buffer_add_ullong10 (out, info.st_size);
					}
					break;

				case op_lastmod:
					TRACE(ENTRIES, "Including file modification date '%s'\n", fpath.buf);
					re = cherokee_stat (fpath.buf, &info);
					if (re >= 0) {
						struct tm *ltime;
						struct tm  ltime_buf;
						char       tmp[50];

						ltime = cherokee_localtime (&info.st_mtime, &ltime_buf);
						if (ltime != NULL) {
							strftime (tmp, sizeof(tmp), "%d-%b-%Y %H:%M", ltime);
							cherokee_buffer_add (out, tmp, strlen(tmp));
						}
					}
					break;
				default:
					SHOULDNT_HAPPEN;
				}
			} /* !ignore */

			break;
		default:
			SHOULDNT_HAPPEN;
		} /* switch(op) */
	} /* while */

	ret = ret_ok;

out:
	cherokee_buffer_mrproper (&key);
	cherokee_buffer_mrproper (&val);
	cherokee_buffer_mrproper (&pair);
	cherokee_buffer_mrproper (&fpath);

	return ret;
}
Ejemplo n.º 26
0
Archivo: strmap.c Proyecto: jkal/toyws
int strmap_put(StrMap *map, const char *key, const char *value)
{
	unsigned int key_len, value_len, index;
	Bucket *bucket;
	Pair *tmp_pairs, *pair;
	char *tmp_value;
	char *new_key, *new_value;

	if (map == NULL) {
		return 0;
	}
	if (key == NULL || value == NULL) {
		return 0;
	}
	key_len = strlen(key);
	value_len = strlen(value);
	/* Get a pointer to the bucket the key string hashes to */
	index = hash(key) % map->count;
	bucket = &(map->buckets[index]);
	/* Check if we can handle insertion by simply replacing
	 * an existing value in a key-value pair in the bucket.
	 */
	if ((pair = get_pair(bucket, key)) != NULL) {
		/* The bucket contains a pair that matches the provided key,
		 * change the value for that pair to the new value.
		 */
		if (strlen(pair->value) < value_len) {
			/* If the new value is larger than the old value, re-allocate
			 * space for the new larger value.
			 */
			tmp_value = realloc(pair->value, (value_len + 1) * sizeof(char));
			if (tmp_value == NULL) {
				return 0;
			}
			pair->value = tmp_value;
		}
		/* Copy the new value into the pair that matches the key */
		strcpy(pair->value, value);
		return 1;
	}
	/* Allocate space for a new key and value */
	new_key = malloc((key_len + 1) * sizeof(char));
	if (new_key == NULL) {
		return 0;
	}
	new_value = malloc((value_len + 1) * sizeof(char));
	if (new_value == NULL) {
		free(new_key);
		return 0;
	}
	/* Create a key-value pair */
	if (bucket->count == 0) {
		/* The bucket is empty, lazily allocate space for a single
		 * key-value pair.
		 */
		bucket->pairs = malloc(sizeof(Pair));
		if (bucket->pairs == NULL) {
			free(new_key);
			free(new_value);
			return 0;
		}
		bucket->count = 1;
	}
	else {
		/* The bucket wasn't empty but no pair existed that matches the provided
		 * key, so create a new key-value pair.
		 */
		tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
		if (tmp_pairs == NULL) {
			free(new_key);
			free(new_value);
			return 0;
		}
		bucket->pairs = tmp_pairs;
		bucket->count++;
	}
	/* Get the last pair in the chain for the bucket */
	pair = &(bucket->pairs[bucket->count - 1]);
	pair->key = new_key;
	pair->value = new_value;
	/* Copy the key and its value into the key-value pair */
	strcpy(pair->key, key);
	strcpy(pair->value, value);
	return 1;
}
Ejemplo n.º 27
0
APREQ_DECLARE(apr_status_t)apreq_parse_cookie_header(apr_pool_t *p,
                                                     apr_table_t *j,
                                                     const char *hdr)
{
    apreq_cookie_t *c;
    unsigned version;
    apr_status_t rv = APR_SUCCESS;

 parse_cookie_header:

    c = NULL;
    version = NETSCAPE;

    while (apr_isspace(*hdr))
        ++hdr;


    if (*hdr == '$' && strncasecmp(hdr, "$Version", 8) == 0) {
        /* XXX cheat: assume "$Version" => RFC Cookie header */
        version = RFC;
    skip_version_string:
        switch (*hdr++) {
        case 0:
            return rv;
        case ',':
            goto parse_cookie_header;
        case ';':
            break;
        default:
            goto skip_version_string;
        }
    }

    for (;;) {
        apr_status_t status;
        const char *name, *value;
        apr_size_t nlen = 0, vlen;

        while (*hdr == ';' || apr_isspace(*hdr))
            ++hdr;

        switch (*hdr) {

        case 0:
            /* this is the normal exit point */
            if (c != NULL) {
                ADD_COOKIE(j, c);
            }
            return rv;

        case ',':
            ++hdr;
            if (c != NULL) {
                ADD_COOKIE(j, c);
            }
            goto parse_cookie_header;

        case '$':
            ++hdr;
            if (c == NULL) {
                rv = APREQ_ERROR_BADCHAR;
                goto parse_cookie_error;
            }
            else if (version == NETSCAPE) {
                rv = APREQ_ERROR_MISMATCH;
            }

            status = get_pair(p, &hdr, &name, &nlen, &value, &vlen, 1);
            if (status != APR_SUCCESS) {
                rv = status;
                goto parse_cookie_error;
            }

            status = apreq_cookie_attr(p, c, name, nlen, value, vlen);

            switch (status) {

            case APR_ENOTIMPL:
                rv = APREQ_ERROR_BADATTR;
                /* fall thru */

            case APR_SUCCESS:
                break;

            default:
                rv = status;
                goto parse_cookie_error;
            }

            break;

        default:
            if (c != NULL) {
                ADD_COOKIE(j, c);
            }

            status = get_pair(p, &hdr, &name, &nlen, &value, &vlen, 0);

            if (status != APR_SUCCESS) {
                c = NULL;
                rv = status;
                goto parse_cookie_error;
            }

            c = apreq_cookie_make(p, name, nlen, value, vlen);
            apreq_cookie_tainted_on(c);
            if (version != NETSCAPE)
                apreq_cookie_version_set(c, version);
        }
    }

 parse_cookie_error:

    switch (*hdr) {

    case 0:
        return rv;

    case ',':
    case ';':
        if (c != NULL)
            ADD_COOKIE(j, c);
        ++hdr;
        goto parse_cookie_header;

    default:
        ++hdr;
        goto parse_cookie_error;
    }

    /* not reached */
    return rv;
}
Ejemplo n.º 28
0
void set_cdr(pointer P, pointer V)
{
    assert(is_type(P, DT_Pair));
    ploy_free(get_pair(P)->_cdr);
    get_pair(P)->_cdr = V;
}
Ejemplo n.º 29
0
void clear_cdr(pointer P)
{
    assert(is_type(P, DT_Pair));
    get_pair(P)->_cdr = NIL;
}
Ejemplo n.º 30
0
void database::get(char* plat_fileName, char* db_fileName) {
  printf("\treading platform file: %s\n", plat_fileName);
  macros->read_from(plat_fileName, missing_ok);

  FILE* f = fopen(db_fileName, "r");
  if (!f && missing_ok)  return;
  if (!f) perror(db_fileName), Plat.fatal();
  printf("\treading database: %s\n", db_fileName);

  int lineNo = 0;
  while (!feof(f)) {
#   define LEN 1024
    char line[LEN];
    
    
    // read line into line[]
    int i, c;
    for ( i = 0,  c = fgetc(f);
          i < LEN-1  &&  c != EOF  &&  (char)c != '\n'  &&  (char)c != '\r';
          ++i,  c = fgetc(f) )
      line[i] = (char)c;

    line[i] = '\0';
    lineNo++;
    
    // check for comment
    if ( strncmp( line,  Plat.commentPrefix(),  strlen(Plat.commentPrefix()))
         == 0)
      continue;

    static char token1[BUFSIZ];
    static char token2[BUFSIZ];
    static char token3[BUFSIZ];
    static char token4[BUFSIZ];
    
    static bool cannot_recurse = 0;
    if (cannot_recurse)
      Plat.fatal("cannot_recurse");
    cannot_recurse = true;

    token1[0] = token2[0] = token3[0] = token4[0] = '\0';
    int n = sscanf(line, " %s %s %s %s", token1, token2, token3, token4);
    if (n < 0)  n = sscanf(line, " %s %s %s", token1, token2, token3); // added this line because of next one
    if (n < 0)  n = sscanf(line, " %s %s", token1, token2); // added this line for MW 4
    if (n <= 0) {
      // empty line?
      char *c;
      for (c = line; *c && isspace(*c); c++) {}
      if (*c == '\0')
        n = 0; // flag empty line, error
      else if (n == 0)
        n = -1; // flag error
    }
    
    if ( n == 0 ) {  // empty line
    } 
    else if (n == 2)
      get_pair(token1, token2,                 plat_fileName, db_fileName, line, lineNo - 1);	 
    else if (n == 4) 
      get_quad(token1, token2, token3, token4, plat_fileName, db_fileName, line, lineNo - 1);
    else {
      char err[BUFSIZ];
      sprintf(err, "invalid line: \"%s\"\nerror position: line %ld\n", line, (long)lineNo);
      Plat.fatal(err);
    }
    cannot_recurse = false;  
  }   
}