Annotation of libaitio/inc/aitio.h, revision 1.5.2.3

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.3 ! misho       6: * $Id: aitio.h,v 1.5.2.2 2010/09/28 07:38:19 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:  * @strLen = String length
        !           103:  * return: NULL error, !=NULL Allocated new string evaluated from input string, must be free()
        !           104: */
        !           105: char *ioVarAst(const char *csString, int strLen);
        !           106: 
        !           107: /*
1.2       misho     108:  * io_Path2File() Parse and make path/filename pair
                    109:  * @csArgs = Input argument line
                    110:  * @psPath = Output Path, if ==NULL path not returned
                    111:  * @pathLen = Size of path array
                    112:  * @psFile = Output File
                    113:  * @fileLen = Size of file array
                    114:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    115: */
                    116: inline int io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen, 
                    117:                char * __restrict psFile, int fileLen);
                    118: /*
                    119:  * io_MakeAV() Parse and make attribute/value pair
                    120:  * @csArgs = Input argument line
                    121:  * @csDelim = Delimiter for separate
                    122:  * @psAttr = Output Attribute
                    123:  * @attrLen = Size of attribute array
                    124:  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
                    125:  * @valLen = Size of value array
                    126:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    127: */
                    128: inline int io_MakeAV(const char * __restrict csArgs, const char *csDelim, 
                    129:                char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen);
                    130: /*
                    131:  * io_SizeArray() Parse and calculate size of array
                    132:  * @csArgs = Input arguments line
                    133:  * @csDelim = Delimiter(s) for separate
                    134:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of items
                    135: */
                    136: inline int io_SizeArray(const char *csArgs, const char *csDelim);
                    137: /*
1.3       misho     138:  * io_MakeArray() Parse and make array of arguments values ... 
                    139:  *     (input string will be modified! and output array must be free)
                    140:  * @psArgs = Input arguments line, after execute string is modified!!!
1.2       misho     141:  * @csDelim = Delimiter(s) for separate
                    142:  * @args = Output array of arguments ... (must be free() after procced function!)
1.3       misho     143:  * @nargs = Maximum requested count of arguments from input string psArgs
1.2       misho     144:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    145: */
                    146: inline int io_MakeArray(char * __restrict psArgs, const char *csDelim, 
                    147:                char *** __restrict args, int nargs);
                    148: 
                    149: /*
1.4       misho     150:  * io_UnquotStr() Remove quots from input text string 
                    151:  * @psLine = Text string
                    152:  * return: 0 nothing to do; 1 successful unquoted string
                    153: */
1.5       misho     154: inline int io_UnquotStr(unsigned char * __restrict psLine);
1.4       misho     155: /*
                    156:  * io_LTrimStr() Remove left whitespaces from text string
                    157:  * @psLine = Text string
                    158:  * return: 0 nothing to do; !=0 Removed bytes
                    159: */
1.5       misho     160: inline int io_LTrimStr(unsigned char * __restrict psLine);
1.4       misho     161: /*
                    162:  * io_RTrimStr() Remove right whitespaces from text string
                    163:  * @psLine = Text string
                    164:  * return: 0 nothing to do; !=0 Removed bytes
                    165: */
1.5       misho     166: inline int io_RTrimStr(unsigned char * __restrict psLine);
1.4       misho     167: /*
                    168:  * io_TrimStr() Remove left and right whitespaces from text string
                    169:  * @psLine = Text string
                    170:  * return: 0 nothing to do; !=0 Removed bytes
                    171: */
1.5       misho     172: inline int io_TrimStr(unsigned char * __restrict psLine);
1.4       misho     173: /*
1.5       misho     174:  * io_Ch2Hex() Convert from Char string to Hex string
1.4       misho     175:  * @psLine = Text string
                    176:  * @lineLen = Length of Text string
1.5       misho     177:  * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be free)
1.4       misho     178: */
1.5       misho     179: inline unsigned char *io_Ch2Hex(unsigned char *psLine, int lineLen);
1.4       misho     180: /*
1.5       misho     181:  * io_Hex2Ch() Convert from Hex string to Char string
1.4       misho     182:  * @psLine = Text string
                    183:  * @lineLen = Length of Text string
                    184:  * return: NULL nothing to do or error; !=0 Allocated new converted string(must be free)
                    185: */
1.5       misho     186: inline char *io_Hex2Ch(unsigned char *psLine, int lineLen);
1.4       misho     187: 
                    188: /*
1.2       misho     189:  * ioURLGet() Parse and get data from input URL
                    190:  * @csURL = Input URL line
                    191:  * @url = Output parsed URL
                    192:  * return: 0 error format not find tech:// and return URL like path; 
                    193:                -1 error:: can`t read; >0 ok, up bits for known elements
                    194: */
                    195: int ioURLGet(const char *csURL, struct tagIOURL *url);
                    196: /*
                    197:  * ioURLGetValue() Get value from parsed URL
                    198:  * @url = Input parsed URL
                    199:  * @csAttr = Attribute for search
                    200:  * @psValue = Return value of attribute, if ==NULL only check for existence of attribute
                    201:  * @valLen = Size of psValue array
                    202:  * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position
                    203: */
                    204: int ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen);
                    205: /*
                    206:  * ioURLGetFile() Get file from parsed URL
                    207:  * @url = Input parsed URL
                    208:  * @psValue = Return filename, if not specified file in url path, replace with /
                    209:  * @valLen = Size of psValue array
                    210:  * return: -1 error:: can`t read; 0 ok
                    211: */
                    212: int ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen);
                    213: 
1.3       misho     214: 
                    215: /*
1.5.2.1   misho     216:  * ioXMLGet() Parse and get data from input XML request string [ns:]container[|attribute[=value]][?data]
                    217:  * @csXML = Input XML request line
                    218:  * @xml = Output parsed XML request
                    219:  * return: 0 error format incorrect, -1 error:: can`t read; >0 ok readed elements bits
                    220: */
                    221: int ioXMLGet(const char *csXML, struct tagReqXML *xml);
                    222: 
                    223: 
                    224: /*
1.5       misho     225:  * ioMkDir() Function for racursive directory creation and validation
                    226:  * @csDir = Full directory path
                    227:  * @mode = Mode for directory creation if missing dir
                    228:  * return: -1 error, 0 directory path exist, >0 created missing dirs
                    229: */
                    230: int ioMkDir(const char *csDir, int mode);
                    231: 
                    232: 
                    233: /*
                    234:  * io_rread() Raw VFS read function
                    235:  * @fd = File handle
                    236:  * @buf = Read buffer
                    237:  * @nbytes = Read buffer size
                    238:  * @offset = Read from position, if -1 read nbytes from current position
                    239:  * @update = Update file handle position !0
                    240:  * return: -1 error or !=-1 readed bytes
                    241:  */
                    242: inline int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
                    243: /*
                    244:  * io_rwrite() Raw VFS write function
                    245:  * @fd = File handle
                    246:  * @buf = Write buffer
                    247:  * @nbytes = Write bytes from buffer
                    248:  * @offset = Write at position, if -1 write nbytes from current position
                    249:  * @update = Update file handle position !0
                    250:  * return: -1 error or !=-1 writed bytes
                    251:  */
                    252: inline int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
                    253: 
                    254: /* Disk I/O helper macros */
                    255: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
                    256: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
                    257: 
                    258: 
                    259: /* Debug helper macros */
                    260: extern int io_Debug;
                    261: 
                    262: #define io_initDebug(x)                io_Debug = (x);
                    263: #define io_addDebug            io_Debug++
                    264: #define ioDEBUG(x, fmt, ...)   do { \
                    265:                                        assert((fmt)); \
                    266:                                        char str[STRSIZ] = { 0 }; \
                    267:                                        snprintf(str, STRSIZ, (fmt), ##__VA_ARGS__); \
                    268:                                        if ((x) <= io_Debug) \
                    269:                                                syslog(LOG_DEBUG, "ioDebug(%d):%s(%d): %s\n", \
                    270:                                                                (x), __func__, __LINE__, str); \
                    271:                                } while (0)
                    272: 
                    273: #define ioERROR(x, fmt, ...)   do { \
                    274:                                        assert((fmt)); \
                    275:                                        char str[STRSIZ] = { 0 }; \
                    276:                                        snprintf(str, STRSIZ, (fmt), ##__VA_ARGS__); \
                    277:                                        syslog(LOG_ERR, "ioError():%s(%d): #%d - %s\n", \
                    278:                                                         __func__, __LINE__, (x), str); \
                    279:                                } while (0)
                    280: #define io_sysERROR(x)         do { \
                    281:                                        if (x > 0 || errno) \
                    282:                                                syslog(LOG_ERR, "ioError(sys):%s(%d): #%d - %s\n", \
                    283:                                                                __func__, __LINE__, x > 0 ? x : errno, \
                    284:                                                                strerror(x > 0 ? x : errno)); \
                    285:                                } while (0)
                    286: #define io_aitERROR(ait)       do { \
                    287:                                        if (ait##_GetErrno()) \
                    288:                                                syslog(LOG_ERR, "ioError(ait):%s(%d): #%d - %s\n", \
                    289:                                                                __func__, __LINE__, ait##_GetErrno(), \
                    290:                                                                ait##_GetError()); \
                    291:                                } while (0)
1.3       misho     292: 
1.1       misho     293: 
                    294: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>