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

1.1       misho       1: /*************************************************************************
1.8       misho       2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
                      3: *  by Michael Pounov <misho@elwix.org>
1.1       misho       4: *
                      5: * $Author: misho $
1.10.2.3! misho       6: * $Id: aitio.h,v 1.10.2.2 2011/08/25 14:31:32 misho Exp $
1.1       misho       7: *
1.8       misho       8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
                     15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
                     16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
1.1       misho      46: #ifndef __AITIO_H
                     47: #define __AITIO_H
                     48: 
                     49: 
1.8       misho      50: #include <assert.h>
1.7       misho      51: #include <openssl/evp.h>
                     52: 
                     53: 
1.8       misho      54: #define VACUUM_LEFT    1
                     55: #define VACUUM_BETWEEN 2
                     56: 
                     57: 
1.9       misho      58: typedef void ** sarr_seg_t;
                     59: typedef struct _tagSplitArray {
                     60:        int             sarr_num;
                     61:        int             sarr_seg;
                     62:        int             sarr_siz;
                     63:        sarr_seg_t      *sarr_data;
                     64: } sarr_t;
                     65: 
1.8       misho      66: typedef struct _tagArray {
                     67:        int     arr_num;
                     68:        void    **arr_data;
                     69: } array_t;
                     70: 
1.2       misho      71: typedef struct _tagURLItem {
                     72:        int     vallen;
                     73:        char    *value;
                     74: } url_Item_t;
                     75: 
                     76: struct tagIOURL {
                     77:        unsigned char   url_line[BUFSIZ];
                     78: 
                     79:        url_Item_t      url_tech;
                     80:        url_Item_t      url_user;
                     81:        url_Item_t      url_pass;
                     82:        url_Item_t      url_host;
                     83:        url_Item_t      url_port;
                     84:        url_Item_t      url_path;
                     85:        url_Item_t      url_args;
                     86: 
                     87:        char            *url_reserved;
                     88: };
                     89: 
1.6       misho      90: struct tagReqXML {
                     91:        unsigned char   xml_line[BUFSIZ];
                     92: 
                     93:        url_Item_t      xml_namespace;
                     94:        union {
                     95:                url_Item_t      container;
                     96:                url_Item_t      path;
                     97:        }               xml_node;
                     98:        url_Item_t      xml_data;
                     99:        url_Item_t      xml_attribute;
                    100:        url_Item_t      xml_value;
                    101: };
                    102: 
1.3       misho     103: 
1.1       misho     104: // io_GetErrno() Get error code of last operation
                    105: inline int io_GetErrno();
                    106: // io_GetError() Get error text of last operation
                    107: inline const char *io_GetError();
                    108: 
                    109: 
                    110: /*
                    111:  * ioPromptRead() Read data from input h[0] with prompt to output h[1]
                    112:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
                    113:  * @csPrompt = Prompt before input, may be NULL
                    114:  * @psData = Readed data
                    115:  * @dataLen = Length of data
                    116:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
                    117: */
                    118: int ioPromptRead(int *h, const char *csPrompt, char * __restrict psData, int dataLen);
                    119: /*
                    120:  * ioPromptPassword() Read password from input h[0] with prompt to output h[1]
                    121:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
                    122:  * @csPrompt = Prompt before input, may be NULL
                    123:  * @psPass = Readed password
                    124:  * @passLen = Length of password
                    125:  * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
                    126:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
                    127: */
                    128: int ioPromptPassword(int *h, const char *csPrompt, char * __restrict psPass, int passLen, int confirm);
                    129: 
                    130: /*
                    131:  * ioRegexVerify() Function for verify data match in regex expression
                    132:  * @csRegex = Regulare expression pattern
                    133:  * @csData = Data for check and verify
                    134:  * @startPos = Return start positions
                    135:  * @endPos = Return end positions
                    136:  * return: NULL not match or error; !=NULL begin of matched data
                    137: */
                    138: const char *ioRegexVerify(const char *csRegex, const char *csData, int *startPos, int *endPos);
                    139: /*
                    140:  * ioRegexGet() Function for get data match in regex expression
                    141:  * @csRegex = Regulare expression pattern
                    142:  * @csData = Data from get
                    143:  * @psString = Returned string if match
                    144:  * @strLen = Length of string
                    145:  * return: 0 not match; >0 count of returned chars
                    146: */
                    147: int ioRegexGet(const char *csRegex, const char *csData, char * __restrict psString, int strLen);
                    148: /*
                    149:  * ioRegexReplace() Function for replace data match in regex expression with newdata
                    150:  * @csRegex = Regulare expression pattern
                    151:  * @csData = Source data
                    152:  * @csNew = Data for replace
                    153:  * return: NULL not match or error; !=NULL allocated new string, must be free after use!
                    154: */
                    155: char *ioRegexReplace(const char *csRegex, const char *csData, const char *csNew);
                    156: 
1.2       misho     157: /*
1.6       misho     158:  * ioVarAst() Function for evaluate string like asterisk variable "{text[:[-]#[:#]]}"
                    159:  * @csString = Input string
                    160:  * return: NULL error, !=NULL Allocated new string evaluated from input string, must be free()
                    161: */
                    162: char *ioVarAst(const char *csString);
                    163: 
                    164: /*
1.2       misho     165:  * io_Path2File() Parse and make path/filename pair
                    166:  * @csArgs = Input argument line
                    167:  * @psPath = Output Path, if ==NULL path not returned
                    168:  * @pathLen = Size of path array
                    169:  * @psFile = Output File
                    170:  * @fileLen = Size of file array
                    171:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    172: */
                    173: inline int io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen, 
                    174:                char * __restrict psFile, int fileLen);
                    175: 
                    176: /*
1.4       misho     177:  * io_UnquotStr() Remove quots from input text string 
                    178:  * @psLine = Text string
                    179:  * return: 0 nothing to do; 1 successful unquoted string
                    180: */
1.5       misho     181: inline int io_UnquotStr(unsigned char * __restrict psLine);
1.4       misho     182: /*
                    183:  * io_LTrimStr() Remove left whitespaces from text string
                    184:  * @psLine = Text string
                    185:  * return: 0 nothing to do; !=0 Removed bytes
                    186: */
1.5       misho     187: inline int io_LTrimStr(unsigned char * __restrict psLine);
1.4       misho     188: /*
                    189:  * io_RTrimStr() Remove right whitespaces from text string
                    190:  * @psLine = Text string
                    191:  * return: 0 nothing to do; !=0 Removed bytes
                    192: */
1.5       misho     193: inline int io_RTrimStr(unsigned char * __restrict psLine);
1.4       misho     194: /*
                    195:  * io_TrimStr() Remove left and right whitespaces from text string
                    196:  * @psLine = Text string
                    197:  * return: 0 nothing to do; !=0 Removed bytes
                    198: */
1.5       misho     199: inline int io_TrimStr(unsigned char * __restrict psLine);
1.4       misho     200: /*
1.5       misho     201:  * io_Ch2Hex() Convert from Char string to Hex string
1.4       misho     202:  * @psLine = Text string
                    203:  * @lineLen = Length of Text string
1.5       misho     204:  * return: NULL nothing to do or error; !=0 Allocated new converted data without term\0 (must be free)
1.4       misho     205: */
1.5       misho     206: inline unsigned char *io_Ch2Hex(unsigned char *psLine, int lineLen);
1.4       misho     207: /*
1.5       misho     208:  * io_Hex2Ch() Convert from Hex string to Char string
1.4       misho     209:  * @psLine = Text string
                    210:  * @lineLen = Length of Text string
                    211:  * return: NULL nothing to do or error; !=0 Allocated new converted string(must be free)
                    212: */
1.5       misho     213: inline char *io_Hex2Ch(unsigned char *psLine, int lineLen);
1.4       misho     214: 
                    215: /*
1.8       misho     216:  * io_arrayInit() - Create and initialize dynamic array
                    217:  * @numItems = Number of Items
                    218:  * return: NULL error, != NULL allocated memory for array
                    219:  */
                    220: inline array_t *io_arrayInit(int numItems);
                    221: /*
1.10      misho     222:  * io_arrayDestroy() - Free and destroy dynamic array
1.8       misho     223:  * @parr = Array
                    224:  * return: none
                    225:  */
                    226: inline void io_arrayDestroy(array_t ** __restrict parr);
                    227: /*
1.10      misho     228:  * io_arrayFree() - Free all data in dynamic array items
1.8       misho     229:  *     (WARNING! If assign static array dont use this!!!)
                    230:  * @arr = Array
                    231:  * return: none
                    232:  */
                    233: inline void io_arrayFree(array_t * __restrict arr);
                    234: /*
1.10      misho     235:  * io_arrayFrom() - Create and fill array from array with pointers
1.10.2.1  misho     236:  * @pargv = Array with pointers
1.10      misho     237:  * @argc = Number of Items, if 0 walk through argv and stop when reach NULL item
1.10.2.1  misho     238:  * return: NULL error, != NULL allocated new array
1.10      misho     239:  */
1.10.2.1  misho     240: inline array_t *io_arrayFrom(const char *** __restrict pargv, int argc);
1.10      misho     241: /*
                    242:  * io_arrayTo() - Create and fill array with pointers from dynamic array
                    243:  * @arr = Array
1.10.2.1  misho     244:  * return: NULL error, != NULL allocated memory for array, NULL terminated
1.10      misho     245:  */
                    246: inline char **io_arrayTo(array_t * __restrict arr);
                    247: /*
1.8       misho     248:  * io_arrayLen() - Get last used element in dynamic array (array Length)
                    249:  * @arr = Array
                    250:  * return: -1 error, 0 empty or >0 position of last used element
                    251:  */
                    252: inline int io_arrayLen(array_t * __restrict arr);
                    253: /*
1.10      misho     254:  * io_arrayConcat() Concat source array to destination array
                    255:  * @dest = Destination array
                    256:  * @src = Source array
                    257:  * return: -1 error; >0 new count of destination array
                    258:  */
                    259: int io_arrayConcat(array_t * __restrict dest, array_t * __restrict src);
                    260: /*
1.8       misho     261:  * io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!!
                    262:  * @arr = Array
                    263:  * @newNumItems = Number of Items
                    264:  * return: -1 error, 0 ok
                    265:  */
                    266: int io_arrayGrow(array_t * __restrict arr, int newNumItems);
                    267: /*
                    268:  * io_arrayVacuum() - Vacuum dynamic array, empty elements will be deleted
                    269:  * @arr = Array
                    270:  * @fromWhere = 1 begin, 2 ALL empty elements
                    271:  * return: -1 error, 0 ok
                    272:  */
                    273: int io_arrayVacuum(array_t * __restrict arr, int fromWhere);
                    274: 
1.10.2.3! misho     275: #define io_arraySize(_arr)             (assert((_arr)), (_arr)->arr_num)
1.8       misho     276: 
1.10.2.3! misho     277: #define io_arrayGet(_arr, _d, _type)   (assert((_arr) && (_arr)->arr_num > _d), \
        !           278:                                                ((_type) *((_arr)->arr_data + _d)))
1.8       misho     279: #define io_arraySet(_arr, _d, _ptr)    do { \
1.10.2.3! misho     280:                                                assert((_arr) && (_arr)->arr_num > _d); \
        !           281:                                                *((_arr)->arr_data + _d) = (void*) _ptr; \
1.8       misho     282:                                        } while (0)
1.10.2.1  misho     283: #define io_arrayDel(_arr, _d, _fri)    do { \
1.10.2.3! misho     284:                                                assert((_arr) && (_arr)->arr_num > _d); \
1.10.2.1  misho     285:                                                if (_fri) \
1.10.2.3! misho     286:                                                        free(*((_arr)->arr_data + _d)); \
        !           287:                                                *((_arr)->arr_data + _d) = NULL; \
1.9       misho     288:                                        } while (0)
1.8       misho     289: 
                    290: /*
                    291:  * io_arrayPush() - Push element into dynamic array like stack manner, place at first empty position
                    292:  * @arr = Array
                    293:  * @data = Element, if set NULL return only first empty position
                    294:  * return: -1 not found empty position, array is full!, >-1 return position of stored element into array
                    295:  */
                    296: inline int io_arrayPush(array_t * __restrict arr, void **data);
                    297: /*
                    298:  * io_arrayPop() - Pop element from dynamic array like stack manner, last used position
                    299:  * @arr = Array
1.10.2.1  misho     300:  * @data = Element, if set NULL return only last used position
1.8       misho     301:  * @delAfter = Delete after Pop element, !=0 delete element from array after return data
                    302:  * return: -1 not found used position, array is empty!, >-1 return element position
                    303:  */
                    304: inline int io_arrayPop(array_t * __restrict arr, void ** __restrict data, int delAfter);
                    305: 
                    306: /*
                    307:  * io_argsNum() Parse and calculate number of arguments
                    308:  * @csArgs = Input arguments line
                    309:  * @csDelim = Delimiter(s) for separate
                    310:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of items
                    311:  */
                    312: inline int io_argsNum(const char *csArgs, const char *csDelim);
                    313: 
                    314: /*
                    315:  * io_arrayMake() Parse and make array from arguments ... (input string will be modified!!! 
                    316:  *     and output array must be free with io_arrayDestroy() after use!)
                    317:  * @psArgs = Input arguments line, after execute string is modified!!!
                    318:  * @nargs = Maximum requested count of arguments from input string psArgs, if 0 all psArgs
                    319:  * @csDelim = Delimiter(s) for separate
                    320:  * @parr = Output array of arguments ... (must be free with io_arrayDestroy() after use!)
                    321:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    322:  */
                    323: int io_arrayMake(char * __restrict psArgs, int nargs, const char *csDelim, 
                    324:                array_t ** __restrict parr);
                    325: 
                    326: /*
                    327:  * io_MakeAV() Parse and make attribute/value pair
                    328:  * @csArgs = Input argument line
                    329:  * @csDelim = Delimiter for separate
                    330:  * @psAttr = Output Attribute
                    331:  * @attrLen = Size of attribute array
                    332:  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return
                    333:  * @valLen = Size of value array
                    334:  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
                    335: */
                    336: int io_MakeAV(const char * __restrict csArgs, const char *csDelim, 
                    337:                char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen);
                    338: 
1.9       misho     339: /*
                    340:  * io_sarrInit() - Create and initialize dynamic split-order array
                    341:  * @numItems = Number of Items
                    342:  * @segLen = Length of segment
                    343:  * return: NULL error, != NULL allocated memory for array
                    344:  */
                    345: inline sarr_t *io_sarrInit(int numItems, int segLen);
                    346: /*
                    347:  * io_sarrDestroy() - Free all data in dynamic split-order array and Destroy array
                    348:  * @parr = Array
                    349:  * return: none
                    350:  */
                    351: inline void io_sarrDestroy(sarr_t ** __restrict parr);
                    352: /*
                    353:  * io_sarrGrow() - Grow/Shrink dynamic split-order array, Use with care when it shrink!!!
                    354:  * @arr = Array
                    355:  * @newNumItems = Number of Items
                    356:  * return: -1 error, 0 ok
                    357:  */
                    358: int io_sarrGrow(sarr_t * __restrict arr, int newNumItems);
                    359: /*
                    360:  * io_sarrVacuum() - Vacuum dynamic split-order array, empty segments will be freed
                    361:  * @arr = Array
                    362:  * return: -1 error, >-1 freed segments
                    363:  */
                    364: inline int io_sarrVacuum(sarr_t * __restrict arr);
1.10.2.3! misho     365: #define io_sarrSize(_arr)              (assert((_arr)), (_arr)->sarr_num)
1.9       misho     366: /*
                    367:  * io_sarrGet() - Get element from dynamic split-order array
                    368:  * @arr = Array
                    369:  * @idx = Index (warning 1st element is at position 1)
                    370:  * return: NULL not found, !=NULL element
                    371:  */
                    372: inline void *io_sarrGet(sarr_t * __restrict arr, unsigned int idx);
                    373: /*
                    374:  * io_sarrGet2() - Always get element from dynamic split-order array
                    375:  *     Function automatic grow array. Good use for Hash tables! 
                    376:  * @arr = Array
                    377:  * @idx = Index (warning 1st element is at position 1)
                    378:  * return: NULL not found, !=NULL element
                    379:  */
                    380: void *io_sarrGet2(sarr_t * __restrict arr, unsigned int idx);
                    381: /*
                    382:  * io_sarrSet() - Set element to dynamic split-order array
                    383:  * @arr = Array
                    384:  * @idx = Index (warning 1st element is at position 1)
                    385:  * @data = Value
                    386:  * return: NULL error or empty, !=NULL old value in element
                    387:  */
                    388: inline void *io_sarrSet(sarr_t * __restrict arr, unsigned int idx, void *data);
1.10.2.3! misho     389: #define io_sarrDel(_arr, _idx)         io_sarrSet((_arr), _idx, NULL)
        !           390: #define io_sarr(_arr, _idx, _type)     (_type)io_sarrGet((_arr), _idx)
1.10.2.2  misho     391: /*
                    392:  * io_sarr2array() - Convert from split-order array to dynamic array
                    393:  * @sa = split array
                    394:  * @sarrFree = after convert split array !=0 will be destroyed sarray
                    395:  * return: NULL error or != NULL new array
                    396:  */
                    397: array_t *io_sarr2array(sarr_t ** __restrict sa, int sarrFree);
                    398: /*
                    399:  * io_array2sarr() - Convert from dynamic array to split-order array
                    400:  * @a = array
                    401:  * @arrFree = after convert array !=0 will be destroyed
                    402:  * return: NULL error or != NULL new sarr
                    403:  */
                    404: sarr_t *io_array2sarr(array_t ** __restrict a, int arrFree);
1.8       misho     405: 
                    406: /*
1.10      misho     407:  * io_CopyEnv() Copy environment to new environment array;
                    408:  * @oldenv = Environment array
                    409:  * return: NULL error; !=NULL Allocated new environment array(must be free)
                    410: */
                    411: char **io_CopyEnv(const char **oldenv);
                    412: /*
                    413:  * io_ExecArgs() Build exec arguments from other array
                    414:  * @psProg = Program name for execute
                    415:  * @oldarg = Arguments array
                    416:  * return: NULL error; !=NULL Allocated execution array(must be free)
                    417: */
                    418: char **io_ExecArgs(const char *psProg, const char **oldarg);
                    419: /*
                    420:  * io_FreeNullTerm() Free dynamic allocated null terminated array with strings
                    421:  * @arr = Pointer to array for free
                    422:  * return: none
                    423: */
                    424: inline void io_FreeNullTerm(char *** __restrict arr);
                    425: 
                    426: /*
1.2       misho     427:  * ioURLGet() Parse and get data from input URL
                    428:  * @csURL = Input URL line
                    429:  * @url = Output parsed URL
                    430:  * return: 0 error format not find tech:// and return URL like path; 
                    431:                -1 error:: can`t read; >0 ok, up bits for known elements
                    432: */
                    433: int ioURLGet(const char *csURL, struct tagIOURL *url);
                    434: /*
                    435:  * ioURLGetValue() Get value from parsed URL
                    436:  * @url = Input parsed URL
                    437:  * @csAttr = Attribute for search
                    438:  * @psValue = Return value of attribute, if ==NULL only check for existence of attribute
                    439:  * @valLen = Size of psValue array
                    440:  * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position
                    441: */
                    442: int ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen);
                    443: /*
                    444:  * ioURLGetFile() Get file from parsed URL
                    445:  * @url = Input parsed URL
                    446:  * @psValue = Return filename, if not specified file in url path, replace with /
                    447:  * @valLen = Size of psValue array
                    448:  * return: -1 error:: can`t read; 0 ok
                    449: */
                    450: int ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen);
                    451: 
1.3       misho     452: 
                    453: /*
1.6       misho     454:  * ioXMLGet() Parse and get data from input XML request string [ns:]container[|attribute[=value]][?data]
                    455:  * @csXML = Input XML request line
                    456:  * @xml = Output parsed XML request
                    457:  * return: 0 error format incorrect, -1 error:: can`t read; >0 ok readed elements bits
                    458: */
                    459: int ioXMLGet(const char *csXML, struct tagReqXML *xml);
                    460: 
                    461: 
                    462: /*
1.5       misho     463:  * ioMkDir() Function for racursive directory creation and validation
                    464:  * @csDir = Full directory path
                    465:  * @mode = Mode for directory creation if missing dir
                    466:  * return: -1 error, 0 directory path exist, >0 created missing dirs
                    467: */
                    468: int ioMkDir(const char *csDir, int mode);
                    469: 
1.6       misho     470: /*
                    471:  * ioWatchDirLoop() Function for watching changes in directory and fire callback
                    472:  * @csDir = Full directory path
                    473:  * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
                    474:  * return: -1 error, !=-1 ok, number of total signaled events
                    475: */
                    476: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
                    477: 
1.5       misho     478: 
                    479: /*
                    480:  * io_rread() Raw VFS read function
                    481:  * @fd = File handle
                    482:  * @buf = Read buffer
                    483:  * @nbytes = Read buffer size
                    484:  * @offset = Read from position, if -1 read nbytes from current position
                    485:  * @update = Update file handle position !0
                    486:  * return: -1 error or !=-1 readed bytes
                    487:  */
                    488: inline int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
                    489: /*
                    490:  * io_rwrite() Raw VFS write function
                    491:  * @fd = File handle
                    492:  * @buf = Write buffer
                    493:  * @nbytes = Write bytes from buffer
                    494:  * @offset = Write at position, if -1 write nbytes from current position
                    495:  * @update = Update file handle position !0
                    496:  * return: -1 error or !=-1 writed bytes
                    497:  */
                    498: inline int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update);
                    499: 
                    500: /* Disk I/O helper macros */
                    501: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
                    502: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
                    503: 
                    504: 
                    505: /* Debug helper macros */
                    506: extern int io_Debug;
                    507: 
                    508: #define io_initDebug(x)                io_Debug = (x);
                    509: #define io_addDebug            io_Debug++
                    510: #define ioDEBUG(x, fmt, ...)   do { \
                    511:                                        assert((fmt)); \
                    512:                                        char str[STRSIZ] = { 0 }; \
1.10.2.3! misho     513:                                        snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
1.5       misho     514:                                        if ((x) <= io_Debug) \
                    515:                                                syslog(LOG_DEBUG, "ioDebug(%d):%s(%d): %s\n", \
                    516:                                                                (x), __func__, __LINE__, str); \
                    517:                                } while (0)
                    518: 
                    519: #define ioERROR(x, fmt, ...)   do { \
                    520:                                        assert((fmt)); \
                    521:                                        char str[STRSIZ] = { 0 }; \
1.10.2.3! misho     522:                                        snprintf(str, sizeof str, (fmt), ##__VA_ARGS__); \
1.5       misho     523:                                        syslog(LOG_ERR, "ioError():%s(%d): #%d - %s\n", \
                    524:                                                         __func__, __LINE__, (x), str); \
                    525:                                } while (0)
                    526: #define io_sysERROR(x)         do { \
                    527:                                        if (x > 0 || errno) \
                    528:                                                syslog(LOG_ERR, "ioError(sys):%s(%d): #%d - %s\n", \
                    529:                                                                __func__, __LINE__, x > 0 ? x : errno, \
                    530:                                                                strerror(x > 0 ? x : errno)); \
                    531:                                } while (0)
                    532: #define io_aitERROR(ait)       do { \
                    533:                                        if (ait##_GetErrno()) \
                    534:                                                syslog(LOG_ERR, "ioError(ait):%s(%d): #%d - %s\n", \
                    535:                                                                __func__, __LINE__, ait##_GetErrno(), \
                    536:                                                                ait##_GetError()); \
                    537:                                } while (0)
1.3       misho     538: 
1.1       misho     539: 
1.7       misho     540: /* Crypto framework */
                    541: 
                    542: /*
                    543:  * ioCipher() Cipher wrapper for all supported crypto algorythms
                    544:  * @pInput = input buffer
                    545:  * @inLen = input buffer len
                    546:  * @ppOutput = output allocated buffe, must be free after use
                    547:  * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
                    548:  * @pKey = key
                    549:  * @pIV = IV, salt (8 bytes)
                    550:  * @nMode = Mode 0 - decrypting or 1 - encrypting
                    551:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
                    552: */
                    553: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher, 
                    554:                unsigned char *pKey, unsigned char *pIV, int nMode);
                    555: 
                    556: /*
                    557:  * io_Blowfish() Blowfish cipher algorythm, work with ASCII hex strings
                    558:  * @pInput = input buffer
                    559:  * @inLen = input buffer len
                    560:  * @ppOutput = output allocated buffe, must be free after use
                    561:  * @pKey = key
                    562:  * @pIV = IV, salt (8 bytes)
                    563:  * @nMode = Mode 0 - decrypting or 1 - encrypting
                    564:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
                    565: */
1.8       misho     566: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
                    567:                unsigned char *pKey, unsigned char *pIV, int nMode);
1.7       misho     568: 
                    569: 
1.1       misho     570: #endif

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