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