Annotation of libaitio/inc/aitio.h, revision 1.5.2.4
1.1 misho 1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.5.2.4 ! misho 6: * $Id: aitio.h,v 1.5.2.3 2011/02/10 19:34:52 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #ifndef __AITIO_H
10: #define __AITIO_H
11:
12:
1.2 misho 13: typedef struct _tagURLItem {
14: int vallen;
15: char *value;
16: } url_Item_t;
17:
18: struct tagIOURL {
19: unsigned char url_line[BUFSIZ];
20:
21: url_Item_t url_tech;
22: url_Item_t url_user;
23: url_Item_t url_pass;
24: url_Item_t url_host;
25: url_Item_t url_port;
26: url_Item_t url_path;
27: url_Item_t url_args;
28:
29: char *url_reserved;
30: };
31:
1.5.2.1 misho 32: struct tagReqXML {
33: unsigned char xml_line[BUFSIZ];
34:
35: url_Item_t xml_namespace;
1.5.2.2 misho 36: union {
37: url_Item_t container;
38: url_Item_t path;
39: } xml_node;
1.5.2.1 misho 40: url_Item_t xml_data;
41: url_Item_t xml_attribute;
42: url_Item_t xml_value;
43: };
44:
1.3 misho 45:
1.1 misho 46: // io_GetErrno() Get error code of last operation
47: inline int io_GetErrno();
48: // io_GetError() Get error text of last operation
49: inline const char *io_GetError();
50:
51:
52: /*
53: * ioPromptRead() Read data from input h[0] with prompt to output h[1]
54: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
55: * @csPrompt = Prompt before input, may be NULL
56: * @psData = Readed data
57: * @dataLen = Length of data
58: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
59: */
60: int ioPromptRead(int *h, const char *csPrompt, char * __restrict psData, int dataLen);
61: /*
62: * ioPromptPassword() Read password from input h[0] with prompt to output h[1]
63: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
64: * @csPrompt = Prompt before input, may be NULL
65: * @psPass = Readed password
66: * @passLen = Length of password
67: * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
68: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
69: */
70: int ioPromptPassword(int *h, const char *csPrompt, char * __restrict psPass, int passLen, int confirm);
71:
72: /*
73: * ioRegexVerify() Function for verify data match in regex expression
74: * @csRegex = Regulare expression pattern
75: * @csData = Data for check and verify
76: * @startPos = Return start positions
77: * @endPos = Return end positions
78: * return: NULL not match or error; !=NULL begin of matched data
79: */
80: const char *ioRegexVerify(const char *csRegex, const char *csData, int *startPos, int *endPos);
81: /*
82: * ioRegexGet() Function for get data match in regex expression
83: * @csRegex = Regulare expression pattern
84: * @csData = Data from get
85: * @psString = Returned string if match
86: * @strLen = Length of string
87: * return: 0 not match; >0 count of returned chars
88: */
89: int ioRegexGet(const char *csRegex, const char *csData, char * __restrict psString, int strLen);
90: /*
91: * ioRegexReplace() Function for replace data match in regex expression with newdata
92: * @csRegex = Regulare expression pattern
93: * @csData = Source data
94: * @csNew = Data for replace
95: * return: NULL not match or error; !=NULL allocated new string, must be free after use!
96: */
97: char *ioRegexReplace(const char *csRegex, const char *csData, const char *csNew);
98:
1.2 misho 99: /*
1.5.2.3 misho 100: * ioVarAst() Function for evaluate string like asterisk variable "{text[:[-]#[:#]]}"
101: * @csString = Input string
102: * return: NULL error, !=NULL Allocated new string evaluated from input string, must be free()
103: */
1.5.2.4 ! misho 104: char *ioVarAst(const char *csString);
1.5.2.3 misho 105:
106: /*
1.2 misho 107: * io_Path2File() Parse and make path/filename pair
108: * @csArgs = Input argument line
109: * @psPath = Output Path, if ==NULL path not returned
110: * @pathLen = Size of path array
111: * @psFile = Output File
112: * @fileLen = Size of file array
113: * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
114: */
115: inline int io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen,
116: char * __restrict psFile, int fileLen);
117: /*
118: * io_MakeAV() Parse and make attribute/value pair
119: * @csArgs = Input argument line
120: * @csDelim = Delimiter for separate
121: * @psAttr = Output Attribute
122: * @attrLen = Size of attribute array
123: * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
124: * @valLen = Size of value array
125: * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
126: */
127: inline int io_MakeAV(const char * __restrict csArgs, const char *csDelim,
128: char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen);
129: /*
130: * io_SizeArray() Parse and calculate size of array
131: * @csArgs = Input arguments line
132: * @csDelim = Delimiter(s) for separate
133: * return: 0 error format; -1 error:: can`t read; >0 ok, number of items
134: */
135: inline int io_SizeArray(const char *csArgs, const char *csDelim);
136: /*
1.3 misho 137: * io_MakeArray() Parse and make array of arguments values ...
138: * (input string will be modified! and output array must be free)
139: * @psArgs = Input arguments line, after execute string is modified!!!
1.2 misho 140: * @csDelim = Delimiter(s) for separate
141: * @args = Output array of arguments ... (must be free() after procced function!)
1.3 misho 142: * @nargs = Maximum requested count of arguments from input string psArgs
1.2 misho 143: * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
144: */
145: inline int io_MakeArray(char * __restrict psArgs, const char *csDelim,
146: char *** __restrict args, int nargs);
147:
148: /*
1.4 misho 149: * io_UnquotStr() Remove quots from input text string
150: * @psLine = Text string
151: * return: 0 nothing to do; 1 successful unquoted string
152: */
1.5 misho 153: inline int io_UnquotStr(unsigned char * __restrict psLine);
1.4 misho 154: /*
155: * io_LTrimStr() Remove left whitespaces from text string
156: * @psLine = Text string
157: * return: 0 nothing to do; !=0 Removed bytes
158: */
1.5 misho 159: inline int io_LTrimStr(unsigned char * __restrict psLine);
1.4 misho 160: /*
161: * io_RTrimStr() Remove right whitespaces from text string
162: * @psLine = Text string
163: * return: 0 nothing to do; !=0 Removed bytes
164: */
1.5 misho 165: inline int io_RTrimStr(unsigned char * __restrict psLine);
1.4 misho 166: /*
167: * io_TrimStr() Remove left and right whitespaces from text string
168: * @psLine = Text string
169: * return: 0 nothing to do; !=0 Removed bytes
170: */
1.5 misho 171: inline int io_TrimStr(unsigned char * __restrict psLine);
1.4 misho 172: /*
1.5 misho 173: * io_Ch2Hex() Convert from Char string to Hex string
1.4 misho 174: * @psLine = Text string
175: * @lineLen = Length of Text string
1.5 misho 176: * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be free)
1.4 misho 177: */
1.5 misho 178: inline unsigned char *io_Ch2Hex(unsigned char *psLine, int lineLen);
1.4 misho 179: /*
1.5 misho 180: * io_Hex2Ch() Convert from Hex string to Char string
1.4 misho 181: * @psLine = Text string
182: * @lineLen = Length of Text string
183: * return: NULL nothing to do or error; !=0 Allocated new converted string(must be free)
184: */
1.5 misho 185: inline char *io_Hex2Ch(unsigned char *psLine, int lineLen);
1.4 misho 186:
187: /*
1.2 misho 188: * ioURLGet() Parse and get data from input URL
189: * @csURL = Input URL line
190: * @url = Output parsed URL
191: * return: 0 error format not find tech:// and return URL like path;
192: -1 error:: can`t read; >0 ok, up bits for known elements
193: */
194: int ioURLGet(const char *csURL, struct tagIOURL *url);
195: /*
196: * ioURLGetValue() Get value from parsed URL
197: * @url = Input parsed URL
198: * @csAttr = Attribute for search
199: * @psValue = Return value of attribute, if ==NULL only check for existence of attribute
200: * @valLen = Size of psValue array
201: * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position
202: */
203: int ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen);
204: /*
205: * ioURLGetFile() Get file from parsed URL
206: * @url = Input parsed URL
207: * @psValue = Return filename, if not specified file in url path, replace with /
208: * @valLen = Size of psValue array
209: * return: -1 error:: can`t read; 0 ok
210: */
211: int ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen);
212:
1.3 misho 213:
214: /*
1.5.2.1 misho 215: * ioXMLGet() Parse and get data from input XML request string [ns:]container[|attribute[=value]][?data]
216: * @csXML = Input XML request line
217: * @xml = Output parsed XML request
218: * return: 0 error format incorrect, -1 error:: can`t read; >0 ok readed elements bits
219: */
220: int ioXMLGet(const char *csXML, struct tagReqXML *xml);
221:
222:
223: /*
1.5 misho 224: * ioMkDir() Function for racursive directory creation and validation
225: * @csDir = Full directory path
226: * @mode = Mode for directory creation if missing dir
227: * return: -1 error, 0 directory path exist, >0 created missing dirs
228: */
229: int ioMkDir(const char *csDir, int mode);
230:
231:
232: /*
233: * io_rread() Raw VFS read function
234: * @fd = File handle
235: * @buf = Read buffer
236: * @nbytes = Read buffer size
237: * @offset = Read from position, if -1 read nbytes from current position
238: * @update = Update file handle position !0
239: * return: -1 error or !=-1 readed bytes
240: */
241: inline int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
242: /*
243: * io_rwrite() Raw VFS write function
244: * @fd = File handle
245: * @buf = Write buffer
246: * @nbytes = Write bytes from buffer
247: * @offset = Write at position, if -1 write nbytes from current position
248: * @update = Update file handle position !0
249: * return: -1 error or !=-1 writed bytes
250: */
251: inline int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
252:
253: /* Disk I/O helper macros */
254: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
255: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
256:
257:
258: /* Debug helper macros */
259: extern int io_Debug;
260:
261: #define io_initDebug(x) io_Debug = (x);
262: #define io_addDebug io_Debug++
263: #define ioDEBUG(x, fmt, ...) do { \
264: assert((fmt)); \
265: char str[STRSIZ] = { 0 }; \
266: snprintf(str, STRSIZ, (fmt), ##__VA_ARGS__); \
267: if ((x) <= io_Debug) \
268: syslog(LOG_DEBUG, "ioDebug(%d):%s(%d): %s\n", \
269: (x), __func__, __LINE__, str); \
270: } while (0)
271:
272: #define ioERROR(x, fmt, ...) do { \
273: assert((fmt)); \
274: char str[STRSIZ] = { 0 }; \
275: snprintf(str, STRSIZ, (fmt), ##__VA_ARGS__); \
276: syslog(LOG_ERR, "ioError():%s(%d): #%d - %s\n", \
277: __func__, __LINE__, (x), str); \
278: } while (0)
279: #define io_sysERROR(x) do { \
280: if (x > 0 || errno) \
281: syslog(LOG_ERR, "ioError(sys):%s(%d): #%d - %s\n", \
282: __func__, __LINE__, x > 0 ? x : errno, \
283: strerror(x > 0 ? x : errno)); \
284: } while (0)
285: #define io_aitERROR(ait) do { \
286: if (ait##_GetErrno()) \
287: syslog(LOG_ERR, "ioError(ait):%s(%d): #%d - %s\n", \
288: __func__, __LINE__, ait##_GetErrno(), \
289: ait##_GetError()); \
290: } while (0)
1.3 misho 291:
1.1 misho 292:
293: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>