cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob a00635532d446f3f4e5eaf499aff27ade1941a00 1057 bytes (raw)
$ git show gl-env:listen_parser.rl	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
/*
 * Copyright (C) 2012-2016 all contributors <cmogstored-public@bogomips.org>
 * License: GPLv3 or later (see COPYING for details)
 */
#include "cmogstored.h"
#include "listen_parser.h"
%%{
	machine listen_parser;
	include listen_parser_common "listen_parser_common.rl";

	main := listen '\0'> {
		a = mog_listen_parse_internal(mark_beg, mark_len,
		                              port_beg, port_len, sa_family);
	};
}%%

%% write data;

static struct mog_addrinfo *listen_parse(char *str)
{
	char *p, *pe, *eof = NULL;
	char *mark_beg = NULL;
	char *port_beg = NULL;
	size_t mark_len = 0;
	size_t port_len = 0;
	sa_family_t sa_family = AF_INET;
	struct mog_addrinfo *a = NULL;
	int cs;

	%% write init;

	p = str;
	pe = str + strlen(str) + 1;

	%% write exec;

	if ((cs == listen_parser_error) && a)
		mog_addrinfo_free(&a);

	assert(p <= pe && "buffer overflow after listen parse");
	return a;
}

struct mog_addrinfo *mog_listen_parse(const char *str)
{
	char *tmp = xstrdup(str);
	struct mog_addrinfo *rv = listen_parse(tmp);
	free(tmp);

	return rv;
}

git clone https://yhbt.net/cmogstored.git