Beispiel #1
0
/**
	get_params : void -> #list
	<doc>parse all GET and POST params and return them into a chained list</doc>
**/
static value get_params() {
	mcontext *c = CONTEXT();
	const char *args = c->r->args;
	value p = val_null;

	// PARSE "GET" PARAMS
	if( args != NULL )
		parse_get(&p,args);

	// PARSE "POST" PARAMS
	if( c->post_data != NULL )
		parse_get(&p,val_string(c->post_data));

	return p;
}
Beispiel #2
0
void parse(void) {

  parse_fail = 0;
  checked(char* token = parse_string());

  if ( *token == '\0' )           return;
  else if ( TOKEN_IS("SET"))      parse_set();
  else if ( TOKEN_IS("GET"))      parse_get();
  else if ( TOKEN_IS("HELLO"))    { }
  else if ( TOKEN_IS("COMMIT"))   eeprom_commit();

  //  else if ( TOKEN_IS("SELFTEST")) selftest_perform();
  else                            { parse_fail = 1; uart_puts_P(" UNKNOWN COMMAND"); }

#ifdef COMMANDLINE_DEBUG
  // string fully consumed?
  if ( *current_pos != '\0' )  {
	parse_fail = 1;
	uart_puts_P("too much input: "); 
	uart_puts(current_pos);
	uart_puts_P(NEWLINE);
  }
#endif

  if ( parse_fail ) uart_puts_P("FAIL"); 
  else uart_puts_P("OK");

  uart_puts_P(NEWLINE);

}
Beispiel #3
0
/**
	get_params : void -> #list
	<doc>parse all GET and POST params and return them into a chained list</doc>
**/
static value get_params() {
	mcontext *c = CONTEXT();
	const char *args = c->r->args;
	value p = val_null;

	// PARSE "GET" PARAMS
	if( args != NULL )
		parse_get(&p,args);

	// PARSE "POST" PARAMS
	if( c->post_data != NULL ) {
		const char *ctype = ap_table_get(c->r->headers_in,"Content-Type");
		if( ctype == NULL || strstr(ctype,"urlencoded") != NULL )
			parse_get(&p,val_string(c->post_data));
	}

	return p;
}
Beispiel #4
0
char *test_parse_get()
{
    char *resp, buf[BUFSIZE];
    parsed_text *parsed = malloc(sizeof(parsed_text));

    prime_buf(buf, "get");
    resp = parse_get(buf, parsed);
    mu_assert("get != keys provided error", STR_EQ(resp, "CLIENT_ERROR: no keys provided in get command\r\n"));

    prime_buf(buf, "get foo");
    resp = parse_get(buf, parsed);
    mu_assert("get foo != NULL", ((resp == NULL) && STR_EQ("foo", parsed->keys[0])));

    prime_buf(buf, "gets foo bar");
    resp = parse_get(buf, parsed);
    mu_assert("get foo bar != NULL", ((resp == NULL) && STR_EQ("foo", parsed->keys[0]) && STR_EQ("bar", parsed->keys[1])));

    return 0;
}
Beispiel #5
0
/* Parse an incoming message. Note that the protocol might have sent this
 * directly over the network (ie. TIPC) or might have wrapped it around (ie.
 * TCP). Here we only deal with the clean, stripped, non protocol-specific
 * message. */
int parse_message(struct req_info *req,
		const unsigned char *buf, size_t len)
{
	uint32_t hdr, ver, id;
	uint16_t cmd, flags;
	const unsigned char *payload;
	size_t psize;

	/* The header is:
	 * 4 bytes	Version + ID
	 * 2 bytes	Command
	 * 2 bytes	Flags
	 * Variable 	Payload
	 */

	hdr = * ((uint32_t *) buf);
	hdr = htonl(hdr);

	/* FIXME: little endian-only */
	ver = (hdr & 0xF0000000) >> 28;
	id = hdr & 0x0FFFFFFF;
	req->id = id;

	cmd = ntohs(* ((uint16_t *) buf + 2));
	flags = ntohs(* ((uint16_t *) buf + 3));

	if (ver != PROTO_VER) {
		stats.net_version_mismatch++;
		req->reply_err(req, ERR_VER);
		return 0;
	}

	/* We define payload as the stuff after buf. But be careful because
	 * there might be none (if len == 1). Doing the pointer arithmetic
	 * isn't problematic, but accessing the payload should be done only if
	 * we know we have enough data. */
	payload = buf + 8;
	psize = len - 8;

	/* Store the id encoded in network byte order, so that we don't have
	 * to calculate it at send time. */
	req->id = htonl(id);
	req->cmd = cmd;
	req->flags = flags;
	req->payload = payload;
	req->psize = psize;

	if (cmd == REQ_GET) {
		parse_get(req);
	} else if (cmd == REQ_SET) {
		parse_set(req);
	} else if (cmd == REQ_DEL) {
		parse_del(req);
	} else if (cmd == REQ_CAS) {
		parse_cas(req);
	} else if (cmd == REQ_INCR) {
		parse_incr(req);
	} else if (cmd == REQ_FIRSTKEY) {
		parse_firstkey(req);
	} else if (cmd == REQ_NEXTKEY) {
		parse_nextkey(req);
	} else if (cmd == REQ_STATS) {
		parse_stats(req);
	} else {
		stats.net_unk_req++;
		req->reply_err(req, ERR_UNKREQ);
	}

	return 1;
}