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

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

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