update changelog with port/createauto
[vde.git] / vde-2 / include / cmdparse.h
blob0aa0053fcc61da525b03579e539b183ee8da8682
1 /*
2 * Copyright (C) 2007 - Renzo Davoli, Luca Bigliardi
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 /**
19 * @file cmdparse.h
20 * @brief finite state automata for communication and parsing
21 * @author Renzo Davoli, Luca Bigliardi
22 * @date 2007-05-17
25 #ifndef _CMDPARSE_H_
26 #define _CMDPARSE_H_
28 /** A state of automata */
29 struct utmstate;
31 /** Automata */
32 struct utm {
33 struct utmstate *head;
34 int timeout;
37 /** Automata buffer containing data read but not parsed yet.
38 * State machine has finished to chomp whole parse buffer
39 * when pos == len
41 struct utm_buf {
42 char *buf;
43 int len;
44 int pos;
47 /** Automata output.
48 * In a parse machine is possible to build a list of outputs,
49 * each element can be tagged.
51 struct utm_out {
52 char *buf;
53 size_t sz;
54 int tag;
55 struct utm_out *next;
58 /**
59 * @brief utmout_alloc - create an empty automata output buffer
61 * @return pointer to the empty buffer, NULL if error
63 struct utm_out *utmout_alloc(void);
65 /**
66 * @brief utmout_free - safe destroy output buffer list
68 * @param out automata output buffer list to free
70 void utmout_free(struct utm_out *out);
72 /**
73 * @brief utm_alloc - create finite state automata
75 * @param conf configuration file containing the list of states
77 * @return finite state automata on success, NULL on error
79 struct utm *utm_alloc(char *conf);
81 /**
82 * @brief utm_free - free finite state automata structure
84 * @param utm finite state automata to destroy
86 void utm_free(struct utm *utm);
88 /**
89 * @brief utm_run
91 * @param utm finite state automata
92 * @param buf automata buffer (related to fd)
93 * @param fd file descriptor to read and write to
94 * @param argc number of arguments in argv
95 * @param argv NULL terminated list of arguments
96 * @param out output buffer of machine
97 * @param debug run machine in verbose mode
99 * @return exit value of machine, it depends to configuration
101 int utm_run(struct utm *utm, struct utm_buf *buf, int fd, int argc, char **argv, struct utm_out *out, int debug);
103 #endif