示例#1
0
文件: subshell.c 项目: kagera/cbsi
void preprocess_token_list(token_t* tokenlist) {
	script_t* newscript;
	token_t* me;
	char* cp;

	me = tokenlist;
	while(me) {
		if(memcmp(me->buf, open_tag, 2)) {
			me->tag = HTML;
		} else {
			me->tag = NOOP;
			me->buf[me->len] = '\0';
			cp = me->buf + 2;
			if(memcmp(cp, g_tag[ECHO], 1) == 0) {
				me->tag = ECHO;
				me->buf = find_whitespace(me->buf);
				me->len = strlen(me->buf);
			} else if(memcmp(cp, g_tag[TRANSLATE], 1) == 0) {
				me->tag = TRANSLATE;
				me->buf = find_whitespace(me->buf);
				me->len = strlen(me->buf);
			}
			if(isspace(*cp)) {
				me->tag = RUN;
				me->buf = cp;
			}
			if(me->tag == NOOP) {
				die_with_message(me->script, cp, g_err_msg[E_NO_OP]);
			}
			me->len = strlen(me->buf);
		}
		me = me->next;
	}
}
示例#2
0
/** Helper: parse space-separated arguments from the string <b>s</b> ending at
 * <b>eol</b>, and store them in the args field of <b>tok</b>.  Store the
 * number of parsed elements into the n_args field of <b>tok</b>.  Allocate
 * all storage in <b>area</b>.  Return the number of arguments parsed, or
 * return -1 if there was an insanely high number of arguments. */
static inline int
get_token_arguments(memarea_t *area, directory_token_t *tok,
                    const char *s, const char *eol)
{
/** Largest number of arguments we'll accept to any token, ever. */
#define MAX_ARGS 512
  char *mem = memarea_strndup(area, s, eol-s);
  char *cp = mem;
  int j = 0;
  char *args[MAX_ARGS];
  while (*cp) {
    if (j == MAX_ARGS)
      return -1;
    args[j++] = cp;
    cp = (char*)find_whitespace(cp);
    if (!cp || !*cp)
      break; /* End of the line. */
    *cp++ = '\0';
    cp = (char*)eat_whitespace(cp);
  }
  tok->n_args = j;
  tok->args = memarea_memdup(area, args, j*sizeof(char*));
  return j;
#undef MAX_ARGS
}
示例#3
0
/* 
 * Pass in the request.  Set the ->path field in r to point to the
 * path that is being requested.
 */
int 
shttp_get_path(struct http_req *r)
{
	char *curr, *end, *path;

	assert(r);
	assert(r->request);
	
	if (strncmp(r->request, "GET ", strlen("GET "))) return -1;
	path = curr = r->request + sizeof("GET ")-1;

	end = find_whitespace(curr);
	if (*end == '\0') return -1;
	*end = '\0';

	if (*path == '/') path++;
	r->path = path;
	
	return 0;
}
static int http_get_parse(char *req, int len, get_ret_t *ret)
{
	char *s = req, *e, *end;
	char *path;
	int path_len, minor_version;

	end = req + len;

	if (memcmp_fail_loc(s, "GET ", len, 4, &e)) goto malformed_request;

	path = remove_whitespace(e, len);
	e = find_whitespace(path, len - (path-s));
	path_len = e-path;
	e = remove_whitespace(e, len - (e-s));

	if (get_http_version(e, len - (e-s), &e, &minor_version)) goto malformed_request;
	if (minor_version != 0 && minor_version != 1) {
		/* This should be seen as an error: */
		e = s;
		goto malformed_request;
	}

	ret->head_flags = 0;
	if (http_find_header_end(e, len - (e-s), &e, ret->head_flags)) goto malformed_request;

	ret->end = e;
	ret->path = path;
	ret->path_len = path_len;
	return 0;

malformed_request:
	ret->path = NULL;
	ret->path_len = -1;
	ret->end = e;
	return -1;
}