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