Ejemplo n.º 1
0
char *test_parse_del()
{
    char *resp, buf[BUFSIZE];
    parsed_text *parsed = malloc(sizeof(parsed_text));

    prime_buf(buf, "delete");
    resp = parse_del(buf, parsed);
    mu_assert("delete != key error", STR_EQ(resp, "CLIENT_ERROR: no key provided for delete\r\n"));

    prime_buf(buf, "delete foo");
    resp = parse_del(buf, parsed);
    mu_assert("delete foo != NULL", ((resp == NULL) && STR_EQ("foo", parsed->key)));

    return 0;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: sbenning42/42
void			sh_loop(t_sh *sh)
{
	t_lxem		*lexem_list;
	t_tree		*cmd_tree;

	while (42)
	{
		if (sh_readline(sh) < 0)												//Get the user command line
		{
			*gg_status() = 0;														//Default command status is set to 1 // BUG-02: gg_status() must be in the t_sh structure
			continue ;
		}
		*gg_status() = 1;														//Default command status is set to 1 // BUG-02: gg_status() must be in the t_sh structure
		if (sh_lexer(sh, &lexem_list) < 0)										//Split the line into lexem
			continue ;
		if (sh_parser(sh, &cmd_tree, &lexem_list) < 0)							//Parse the lexem list to get a binary command tree
			continue ;
		*gg_status() = (exec_root(sh, cmd_tree) ? 1 : 0);						//Execute all the command tree and get the status of the execution
		if (ISO(sh->o, SH_O_VERBOSE))											//If '-v' is specified in the arg_v, print a debug of the tree
			dump_root(cmd_tree, 0, sh->bin);
		parse_del(&cmd_tree);													//Clear the memory used by the tree
		ft_memdel((void **)&sh->line);											//Clear the memory used by the command line
	}
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: sbenning42/42
void			sh_loop(t_sh *sh)
{
	t_lxem		*lexem_list;
	t_tree		*cmd_tree;

	while (42)
	{
		if (sh_readline(sh) < 0)
		{
			*gg_status() = 0;
			continue ;
		}
		*gg_status() = 1;
		if (sh_lexer(sh, &lexem_list) < 0)
			continue ;
		if (sh_parser(sh, &cmd_tree, &lexem_list) < 0)
			continue ;
		*gg_status() = (exec_root(sh, cmd_tree) ? 1 : 0);
		if (ISO(sh->o, SH_O_VERBOSE))
			dump_root(cmd_tree, 0, sh->bin);
		parse_del(&cmd_tree);
		ft_memdel((void **)&sh->line);
	}
}
Ejemplo n.º 4
0
Archivo: parse.c Proyecto: dolfly/nmdb
/* 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;
}