Annotation of libaitrpc/inc/aitrpc.h, revision 1.1.1.1.2.18

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.1.1.1.2.18! misho       6: * $Id: aitrpc.h,v 1.1.1.1.2.17 2010/07/07 15:18:22 misho Exp $
1.1       misho       7: *
                      8: *************************************************************************/
                      9: #ifndef __AITRPC_H
                     10: #define __AITRPC_H
                     11: 
                     12: 
                     13: #include <assert.h>
                     14: #include <stdlib.h>
                     15: #include <string.h>
                     16: #include <sys/types.h>
                     17: #include <sys/param.h>
                     18: #include <sys/limits.h>
                     19: #include <sys/socket.h>
                     20: 
                     21: 
                     22: #define RPC_VERSION            1
                     23: #define RPC_DEFPORT            2611
                     24: 
                     25: 
                     26: /* RPC builtin registed calls */
                     27: 
1.1.1.1.2.5  misho      28: #define CALL_BLOBSHUTDOWN      "rpcBLOBServerShutdown"
                     29: #define CALL_BLOBCLIENTS       "rpcBLOBServerClients"
                     30: #define CALL_BLOBVARS          "rpcBLOBServerVars"
1.1.1.1.2.12  misho      31: #define CALL_BLOBSTATE         "rpcBLOBServerState"
1.1.1.1.2.5  misho      32: 
1.1.1.1.2.1  misho      33: #define CALL_SRVSHUTDOWN       "rpcServerShutdown"
1.1       misho      34: #define CALL_SRVCLIENTS                "rpcServerClients"
                     35: #define CALL_SRVCALLS          "rpcServerCalls"
                     36: #define CALL_SRVSESSIONS       "rpcServerSessions"
                     37: 
                     38: 
                     39: /* RPC types */
                     40: 
                     41: typedef enum {
                     42:        empty,                          // empty -> variable is not set
1.1.1.1.2.3  misho      43:        buffer, string, blob,           // buffer -> uint8_t*; string -> int8_t*; blob -> void*(+socket);
1.1       misho      44:        size, offset, datetime,         // size -> size_t; offset -> off_t; datetime -> time_t;
                     45:        real, bigreal,                  // real -> float; bigreal -> double;
                     46:        u8, u16, u32, u64,              // unsigned integers ...
                     47:        i8, i16, i32, i64               // integers ...
                     48: } rpc_type_t;
                     49: 
1.1.1.1.2.6  misho      50: typedef enum {
1.1.1.1.2.8  misho      51:        disable, enable,                // for blob.state
                     52:        ok, error,                      // for blob reply
                     53:        get, set, unset                 // for blob request
1.1.1.1.2.6  misho      54: } cmd_type_t;
                     55: 
1.1       misho      56: /* RPC value */
                     57: 
                     58: typedef struct {
                     59:        rpc_type_t      val_type;
                     60:        size_t          val_len;
                     61:        union {
                     62:                uint8_t         *buffer;
                     63:                int8_t          *string;
1.1.1.1.2.17  misho      64:                uint32_t        blob;
1.1       misho      65:                size_t          size;
                     66:                off_t           offset;
                     67:                time_t          datetime;
                     68:                float           real;
                     69:                double          bigreal;
                     70:                uint8_t         u8;
                     71:                uint16_t        u16;
                     72:                uint32_t        u32;
                     73:                uint64_t        u64;
                     74:                int8_t          i8;
                     75:                int16_t         i16;
                     76:                int32_t         i32;
                     77:                int64_t         i64;
                     78:        } val;
                     79: } __packed rpc_val_t;
                     80: 
                     81: #define RPC_TYPE_VAL(vl)               ((vl)->val_type)
                     82: #define RPC_LEN_VAL(vl)                        ((vl)->val_len)
1.1.1.1.2.3  misho      83: #define RPC_BLOB_CHUNKS(vl, n)         ((vl)->val_len / (n) + ((vl)->val_len % (n)) ? 1 : 0)
1.1       misho      84: #define RPC_EMPTY_VAL(vl)              ((vl)->val_type == empty)
                     85: 
                     86: #define RPC_GET_BUF(vl)                        (assert((vl)->val_type == buffer), (vl)->val.buffer)
                     87: #define RPC_GET_STR(vl)                        (assert((vl)->val_type == string), (vl)->val.string)
1.1.1.1.2.3  misho      88: #define RPC_GET_BLOB(vl)               (assert((vl)->val_type == blob), (vl)->val.blob)
1.1       misho      89: #define RPC_GET_SIZE(vl)               (assert((vl)->val_type == size), (vl)->val.size)
                     90: #define RPC_GET_OFF(vl)                        (assert((vl)->val_type == offset), (vl)->val.offset)
                     91: #define RPC_GET_TIME(vl)               (assert((vl)->val_type == datetime), (vl)->val.datetime)
                     92: #define RPC_GET_REAL(vl)               (assert((vl)->val_type == real), (vl)->val.real)
                     93: #define RPC_GET_BREAL(vl)              (assert((vl)->val_type == bigreal), (vl)->val.bigreal)
                     94: #define RPC_GET_U8(vl)                 (assert((vl)->val_type == u8), (vl)->val.u8)
                     95: #define RPC_GET_U16(vl)                        (assert((vl)->val_type == u16), (vl)->val.u16)
                     96: #define RPC_GET_U32(vl)                        (assert((vl)->val_type == u32), (vl)->val.u32)
                     97: #define RPC_GET_U64(vl)                        (assert((vl)->val_type == u64), (vl)->val.u64)
                     98: #define RPC_GET_I8(vl)                 (assert((vl)->val_type == i8), (vl)->val.i8)
                     99: #define RPC_GET_I16(vl)                        (assert((vl)->val_type == i16), (vl)->val.i16)
                    100: #define RPC_GET_I32(vl)                        (assert((vl)->val_type == i32), (vl)->val.i32)
                    101: #define RPC_GET_I64(vl)                        (assert((vl)->val_type == i64), (vl)->val.i64)
                    102: 
                    103: #define RPC_SET_BUF(vl, v, l)          do { rpc_val_t *val = (vl); assert(val); val->val.buffer = malloc(l); \
                    104:                                                if (val->val.buffer) { \
                    105:                                                        val->val_type = buffer; val->val_len = l; \
                    106:                                                        memcpy(val->val.buffer, v, l); \
                    107:                                                } } while (0)
                    108: #define RPC_SET_STR(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val.string = (int8_t*) strdup(v); \
                    109:                                                if (val->val.string) { \
                    110:                                                        val->val_type = string; val->val_len = strlen(v) + 1; \
                    111:                                                } } while (0)
1.1.1.1.2.17  misho     112: #define RPC_SET_BLOB(vl, v, l)         do { rpc_val_t *val = (vl); assert(val); val->val_type = blob; \
                    113:                                                val->val.blob = v; val->val_len = l; } while (0)
                    114: #define RPC_SET_BLOB2(vl, b)           do { rpc_val_t *val = (vl); assert(val); assert(b); val->val_type = blob; \
                    115:                                                val->val.blob = b->blob_var; val->val_len = b->blob_len; } while (0)
1.1       misho     116: #define RPC_SET_SIZE(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = size; val->val.size = v; \
                    117:                                                val->val_len = sizeof(size_t); } while (0)
                    118: #define RPC_SET_OFF(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = offset; val->val.offset = v; \
                    119:                                                val->val_len = sizeof(off_t); } while (0)
                    120: #define RPC_SET_TIME(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = datetime; val->val.datetime = v; \
                    121:                                                val->val_len = sizeof(time_t); } while (0)
                    122: #define RPC_SET_REAL(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = real; val->val.real = v; \
                    123:                                                val->val_len = sizeof(float); } while (0)
                    124: #define RPC_SET_BREAL(vl, v)           do { rpc_val_t *val = (vl); assert(val); val->val_type = bigreal; val->val.bigreal = v; \
                    125:                                                val->val_len = sizeof(double); } while (0)
                    126: #define RPC_SET_U8(vl, v)              do { rpc_val_t *val = (vl); assert(val); val->val_type = u8; val->val.u8 = v; \
                    127:                                                val->val_len = sizeof(uint8_t); } while (0)
                    128: #define RPC_SET_U16(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u16; val->val.u16 = v; \
                    129:                                                val->val_len = sizeof(uint16_t); } while (0)
                    130: #define RPC_SET_U32(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u32; val->val.u32 = v; \
                    131:                                                val->val_len = sizeof(uint32_t); } while (0)
                    132: #define RPC_SET_U64(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u64; val->val.u64 = v; \
                    133:                                                val->val_len = sizeof(uint64_t); } while (0)
                    134: #define RPC_SET_I8(vl, v)              do { rpc_val_t *val = (vl); assert(val); val->val_type = i8; val->val.i8 = v; \
                    135:                                                val->val_len = sizeof(int8_t); } while (0)
                    136: #define RPC_SET_I16(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i16; val->val.i16 = v; \
                    137:                                                val->val_len = sizeof(int16_t); } while (0)
                    138: #define RPC_SET_I32(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i32; val->val.i32 = v; \
                    139:                                                val->val_len = sizeof(int32_t); } while (0)
                    140: #define RPC_SET_I64(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i64; val->val.i64 = v; \
                    141:                                                val->val_len = sizeof(int64_t); } while (0)
                    142: 
                    143: #define RPC_FREE_VAL(vl)               do { rpc_val_t *val = (vl); assert(val); \
                    144:                                                if (val->val_type == buffer && val->val.buffer) { \
                    145:                                                        free(val->val.buffer); \
                    146:                                                        val->val.buffer = NULL; \
                    147:                                                } \
                    148:                                                if (val->val_type == string && val->val.string) { \
                    149:                                                        free(val->val.string); \
                    150:                                                        val->val.string = NULL; \
                    151:                                                } \
                    152:                                                val->val_type = val->val_len = 0; \
                    153:                                        } while (0)
                    154: 
                    155: 
1.1.1.1.2.18! misho     156: #define RPC_CALLBACK_CHK_RETARGS(f, n) do { \
1.1       misho     157:                                                if (f->func_args != n) { \
                    158:                                                        rpc_SetErr(22, "Error:: different number of arguments!\n"); \
                    159:                                                        return -1; \
                    160:                                                } \
1.1.1.1.2.1  misho     161:                                        } while (0)
1.1.1.1.2.11  misho     162: #define RPC_CALLBACK_CHECK_INPUT(f)    do { \
                    163:                                                if (!f) { \
1.1.1.1.2.1  misho     164:                                                        rpc_SetErr(22, "Error:: invalid callback parameters ...\n"); \
                    165:                                                        return -1; \
                    166:                                                } \
                    167:                                        } while (0)
1.1       misho     168: 
                    169: 
                    170: /* RPC session identification */
                    171: 
                    172: typedef struct {
                    173:        uint8_t         sess_version;
                    174:        uint32_t        sess_program;
                    175:        uint32_t        sess_process;
                    176: } __packed rpc_sess_t;
                    177: 
                    178: 
                    179: /* Server managment RPC functions ... */
                    180: 
                    181: // RPC function registration element!
                    182: typedef struct tagRPCFunc {
                    183:        uint16_t                func_tag;
                    184:        uint32_t                func_hash;
                    185:        int8_t                  func_file[MAXPATHLEN];
                    186:        int8_t                  func_name[UCHAR_MAX + 1];
                    187: 
                    188:        int8_t                  func_args;
                    189:        rpc_val_t               *func_vals;
                    190: 
1.1.1.1.2.11  misho     191:        void                    *func_parent;
1.1       misho     192:        struct tagRPCFunc       *func_next;
                    193: } rpc_func_t;
                    194: 
                    195: 
                    196: /* Network RPC packet - Client request */
                    197: 
                    198: struct tagRPCCall {
                    199:        rpc_sess_t      call_session;
                    200:        uint16_t        call_tag;
                    201:        uint32_t        call_hash;
                    202:        uint8_t         call_argc;
                    203: } __packed;
                    204: 
                    205: /* Network RPC packet - Server response */
                    206: 
                    207: struct tagRPCRet {
                    208:        rpc_sess_t      ret_session;
                    209:        uint16_t        ret_tag;
                    210:        uint32_t        ret_hash;
                    211:        int32_t         ret_retcode;
                    212:        int32_t         ret_errno;
                    213:        uint8_t         ret_argc;
                    214: } __packed;
                    215: 
1.1.1.1.2.6  misho     216: /* Network BLOB packet - Header */
                    217: 
                    218: struct tagBLOBHdr {
                    219:        rpc_sess_t      hdr_session;
                    220:        uint8_t         hdr_cmd;
                    221:        uint32_t        hdr_var;
                    222:        uint32_t        hdr_seq;
                    223:        uint32_t        hdr_len;
                    224: } __packed;
                    225: 
1.1       misho     226: /* Network RPC client & server elements */
                    227: 
                    228: typedef struct {
                    229:        struct sockaddr cli_sa;         // host info
                    230:        int             cli_sock;       // socket
                    231:        pthread_t       cli_tid;        // TID of thread
                    232: 
                    233:        void            *cli_parent;    // pointer to parent rpc_srv_t for server or to rpc_sess_t for client
                    234: } rpc_cli_t;
                    235: 
                    236: 
1.1.1.1.2.5  misho     237: // BLOB registration element!
                    238: typedef struct tagBLOB {
1.1.1.1.2.6  misho     239:        uint32_t        blob_var;
                    240: 
1.1.1.1.2.5  misho     241:        size_t          blob_len;       // size of allocated BLOB data
                    242:        void            *blob_data;     // BLOB data
                    243: 
                    244:        struct tagBLOB  *blob_next;
                    245: } rpc_blob_t;
                    246: 
                    247: typedef struct {
1.1       misho     248:        rpc_sess_t      srv_session;    // RPC session registration info
1.1.1.1.2.5  misho     249:        int             srv_numcli;     // maximum concurent client connections
1.1       misho     250: 
1.1.1.1.2.5  misho     251:        rpc_cli_t       srv_server;     // RPC server socket
                    252:        rpc_cli_t       *srv_clients;   // connected rpc client sockets
1.1       misho     253: 
                    254:        rpc_func_t      *srv_funcs;     // registered functions list
1.1.1.1.2.5  misho     255: 
                    256:        pthread_mutex_t srv_mtx;
                    257: 
                    258:        struct {
                    259:                int             state;          // BLOB server state: ==0 disable | !=0 enable
1.1.1.1.2.6  misho     260:                char            dir[UCHAR_MAX + 1];
1.1.1.1.2.5  misho     261: 
                    262:                rpc_cli_t       server;         // BLOB server socket
                    263:                rpc_cli_t       *clients;       // connected blob client sockets
                    264: 
                    265:                rpc_blob_t      *blobs;         // registered blob variables list
                    266: 
                    267:                pthread_mutex_t mtx;
                    268:        }               srv_blob;
1.1       misho     269: } rpc_srv_t;
                    270: 
                    271: 
1.1.1.1.2.11  misho     272: /* 
                    273:  * (*rpc_callback_t)() Callback type definition for RPC call in server process
                    274:  * @arg1 = current execution RPC call function
                    275:  * @arg2 = number of items in input array from call request
                    276:  * @arg3 = input array with values from RPC call execution request
                    277:  * return: -1 error or >-1 success execution
                    278:  */
                    279: typedef int (*rpc_callback_t)(rpc_func_t *, int, rpc_val_t *);
1.1       misho     280: 
                    281: 
                    282: // -----------------------------------------------------------------------
                    283: 
                    284: /* Error support functions */
                    285: 
                    286: // cli_GetErrno() Get error code of last operation
                    287: inline int cli_GetErrno();
                    288: // cli_GetError() Get error text of last operation
                    289: inline const char *cli_GetError();
                    290: 
                    291: 
                    292: /* RPC Server side functions */
                    293: 
                    294: /*
                    295:  * rpc_srv_initServer() Init & create RPC Server
                    296:  * @regProgID = ProgramID for authentication & recognition
                    297:  * @regProcID = ProcessID for authentication & recognition
                    298:  * @concurentClients = Concurent clients at same time to this server
                    299:  * @family = Family socket type, AF_INET or AF_INET6
                    300:  * @csHost = Host name or IP address for bind server, if NULL any address
                    301:  * @Port = Port for bind server, if Port == 0 default port is selected
                    302:  * return: NULL == error or !=NULL bind and created RPC server instance
                    303:  */
                    304: rpc_srv_t *rpc_srv_initServer(u_int regProgID, u_int regProcID, int concurentClients, 
                    305:                u_short family, const char *csHost, u_short Port);
                    306: /*
                    307:  * rpc_srv_endServer() Destroy RPC server, close all opened sockets and free resources
                    308:  * @srv = RPC Server instance
                    309:  * return: none
                    310:  */
                    311: void rpc_srv_endServer(rpc_srv_t * __restrict srv);
                    312: /*
                    313:  * rpc_srv_execServer() Execute Main server loop and wait for clients requests
                    314:  * @srv = RPC Server instance
                    315:  * return: -1 error or 0 ok, infinite loop ...
                    316:  */
                    317: int rpc_srv_execServer(rpc_srv_t * __restrict srv);
                    318: 
                    319: /*
1.1.1.1.2.5  misho     320:  * rpc_srv_initBLOBServer() Init & create BLOB Server
                    321:  * @Port = Port for bind server, if Port == 0 default port is selected
1.1.1.1.2.6  misho     322:  * @diskDir = Disk place for BLOB file objects
1.1.1.1.2.5  misho     323:  * return: -1 == error or 0 bind and created BLOB server instance
                    324:  */
1.1.1.1.2.6  misho     325: int rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_short Port, const char *diskDir);
1.1.1.1.2.5  misho     326: /*
                    327:  * rpc_srv_endBLOBServer() Destroy BLOB server, close all opened sockets and free resources
                    328:  * @srv = RPC Server instance
                    329:  * return: none
                    330:  */
                    331: void rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv);
                    332: /*
                    333:  * rpc_srv_execBLOBServer() Execute Main BLOB server loop and wait for clients requests
                    334:  * @srv = RPC Server instance
                    335:  * return: -1 error or 0 ok, infinite loop ...
                    336:  */
                    337: int rpc_srv_execBLOBServer(rpc_srv_t * __restrict srv);
                    338: 
                    339: /*
1.1.1.1.2.6  misho     340:  * rpc_srv_getBLOB() Get registered BLOB 
                    341:  * @srv = RPC Server instance
                    342:  * @var = hash for variable
                    343:  * return: NULL not found, !=NULL return blob var
                    344:  */
                    345: inline rpc_blob_t *rpc_srv_getBLOB(rpc_srv_t * __restrict srv, uint32_t var);
                    346: 
                    347: /*
1.1       misho     348:  * rpc_srv_registerCall() Register call to RPC server
                    349:  * @srv = RPC Server instance
                    350:  * @csModule = Module name, if NULL self binary
                    351:  * @csFunc = Function name
1.1.1.1.2.17  misho     352:  * @args = Number of return function arguments, use for restriction case!
1.1       misho     353:  * return: -1 error or 0 register ok
                    354:  */
                    355: int rpc_srv_registerCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc, 
                    356:                unsigned char args);
                    357: /*
                    358:  * rpc_srv_unregisterCall() Unregister call from RPC server
                    359:  * @srv = RPC Server instance
                    360:  * @csModule = Module name, if NULL self binary
                    361:  * @csFunc = Function name
                    362:  * return: -1 error, 0 not found call, 1 unregister ok
                    363:  */
                    364: int rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    365: /*
                    366:  * rpc_srv_getFunc() Get registered call from RPC server by Name
                    367:  * @srv = RPC Server instance
                    368:  * @csModule = Module name, if NULL self binary
                    369:  * @csFunc = Function name
                    370:  * return: NULL not found call, !=NULL return call
                    371:  */
                    372: rpc_func_t *rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    373: /*
                    374:  * rpc_srv_getCall() Get registered call from RPC server
                    375:  * @srv = RPC Server instance
                    376:  * @tag = tag for function
                    377:  * @hash = hash for function
                    378:  * return: NULL not found call, !=NULL return call
                    379:  */
                    380: inline rpc_func_t *rpc_srv_getCall(rpc_srv_t * __restrict srv, uint16_t tag, uint32_t hash);
                    381: /*
                    382:  * rpc_srv_execCall() Execute registered call from RPC server
                    383:  * @call = Register RPC call
                    384:  * @rpc = IN RPC call structure
                    385:  * @args = IN RPC call array of rpc values
                    386:  * return: -1 error, !=-1 ok
                    387:  */
1.1.1.1.2.11  misho     388: int rpc_srv_execCall(rpc_func_t * __restrict call, struct tagRPCCall * __restrict rpc, 
                    389:                rpc_val_t * __restrict args);
1.1       misho     390: 
                    391: 
                    392: /*
1.1.1.1.2.11  misho     393:  * rpc_srv_retValsCall() Declare return variables for RPC call and zeroed values
                    394:                                        (for safe handling return values, use this!)
                    395:  * @call = RPC function call
                    396:  * @return_vals = Number of return variables
                    397:  * return: NULL error, !=NULL array with return values for RPC call with return_vals items
                    398:  */
                    399: inline rpc_val_t *rpc_srv_retValsCall(rpc_func_t * __restrict call, int return_vals);
                    400: /*
                    401:  * rpc_srv_declValsCall() Declare return variables for RPC call, 
                    402:                                if already allocated memory for RPC call return values 
                    403:                                function reallocate used space with return_vals count elements
1.1       misho     404:  * @call = RPC function call
                    405:  * @return_vals = Number of return variables
                    406:  * return: -1 error, !=-1 ok
                    407:  */
                    408: inline int rpc_srv_declValsCall(rpc_func_t * __restrict call, int return_vals);
                    409: /*
                    410:  * rpc_srv_freeValsCall() Free return variables for RPC call
                    411:  * @call = RPC function call
                    412:  * return: none
                    413:  */
                    414: inline void rpc_srv_freeValsCall(rpc_func_t * __restrict call);
                    415: /*
                    416:  * rpc_srv_copyValsCall() Copy return variables for RPC call to new variable
                    417:  * @call = RPC function call
                    418:  * @newvals = New allocated variables array, must be free after use
                    419:  * return: -1 error, !=-1 Returned number of copied RPC variables
                    420:  */
                    421: inline int rpc_srv_copyValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict newvals);
                    422: /*
1.1.1.1.2.11  misho     423:  * rpc_srv_zeroValsCall() Clean values from return variables of RPC call
1.1       misho     424:  * @call = RPC function call
                    425:  * return: -1 error, !=-1 Returned number of cleaned RPC variables
                    426:  */
1.1.1.1.2.11  misho     427: inline int rpc_srv_zeroValsCall(rpc_func_t * __restrict call);
1.1       misho     428: /*
                    429:  * rpc_srv_getValsCall() Get return variables for RPC call
                    430:  * @call = RPC function call
                    431:  * @vals = Returned variables, may be NULL
                    432:  * return: -1 error, !=-1 Number of returned variables
                    433:  */
                    434: inline int rpc_srv_getValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict vals);
                    435: 
                    436: 
1.1.1.1.2.7  misho     437: /*
1.1.1.1.2.10  misho     438:  * rpc_srv_blobCreate() Create map blob to memory region and return object
                    439:  * @srv = RPC Server instance
                    440:  * @len = BLOB length object
                    441:  * return: NULL error or !=NULL allocated BLOB object
                    442:  */
                    443: inline rpc_blob_t *rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len);
                    444: /*
1.1.1.1.2.7  misho     445:  * rpc_srv_blobMap() Map blob to memory region 
                    446:  * @srv = RPC Server instance
                    447:  * @blob = Map to this BLOB element
                    448:  * return: -1 error or 0 ok
                    449:  */
                    450: inline int rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    451: /*
                    452:  * rpc_srv_blobUnmap() Unmap blob memory region 
                    453:  * @blob = Mapped BLOB element
                    454:  * return: none
                    455:  */
                    456: inline void rpc_srv_blobUnmap(rpc_blob_t * __restrict blob);
                    457: /*
                    458:  * rpc_srv_blobFree() Free blob from disk & memory
                    459:  * @srv = RPC Server instance
                    460:  * @blob = Mapped BLOB element
                    461:  * return: -1 error or 0 ok
                    462:  */
                    463: inline int rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    464: 
1.1.1.1.2.9  misho     465: /*
1.1.1.1.2.10  misho     466:  * rpc_srv_registerBLOB() Register new BLOB to server
                    467:  * @srv = RPC Server instance
                    468:  * @len = BLOB length
1.1.1.1.2.16  misho     469:  * return: NULL error or new registered BLOB
1.1.1.1.2.10  misho     470:  */
                    471: rpc_blob_t *rpc_srv_registerBLOB(rpc_srv_t * __restrict srv, size_t len);
                    472: /*
                    473:  * rpc_srv_unregisterBLOB() Unregister BLOB from server
                    474:  * @srv = RPC Server instance
                    475:  * @var = BLOB Variable for unregister
                    476:  * return: -1 error, 0 not found call, 1 unregister ok
                    477:  */
                    478: int rpc_srv_unregisterBLOB(rpc_srv_t * __restrict srv, uint32_t var);
                    479: 
                    480: /*
1.1.1.1.2.9  misho     481:  * rpc_srv_sendBLOB() Send mapped BLOB to client
                    482:  * @cli = Client instance
                    483:  * @blob = Mapped BLOB element
                    484:  * return: -1 error, 0 ok
                    485:  */
                    486: int rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
                    487: /*
                    488:  * rpc_srv_recvBLOB() Receive BLOB from client
                    489:  * @cli = Client instance
1.1.1.1.2.10  misho     490:  * @blob = Mapped BLOB element
                    491:  * return: -1 error, 0 ok, >0 unreceived data from client, may be error?
1.1.1.1.2.9  misho     492:  */
1.1.1.1.2.10  misho     493: int rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
1.1.1.1.2.9  misho     494: 
1.1.1.1.2.13  misho     495: /*
                    496:  * rpc_cli_sendBLOB() Send BLOB to server
                    497:  * @cli = Client instance
                    498:  * @var = BLOB variable
                    499:  * @data = BLOB data
1.1.1.1.2.14  misho     500:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     501:  */
                    502: int rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void * __restrict data);
                    503: /*
                    504:  * rpc_cli_recvBLOB() Receive BLOB from server
                    505:  * @cli = Client instance
                    506:  * @var = BLOB variable
                    507:  * @data = BLOB data, must be free after use!
1.1.1.1.2.17  misho     508:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     509:  */
                    510: int rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data);
                    511: 
1.1.1.1.2.7  misho     512: 
1.1       misho     513: /* RPC Client side functions */
                    514: 
                    515: /*
                    516:  * rpc_cli_openClient() Connect to RPC Server
                    517:  * @ProgID = ProgramID for RPC session request
                    518:  * @ProcID = ProcessID for RPC session request
                    519:  * @family = Family socket type, AF_INET or AF_INET6
                    520:  * @csHost = Host name or IP address for bind server
                    521:  * @Port = Port for bind server, if Port == 0 default port is selected
                    522:  * return: NULL == error or !=NULL connection to RPC server established
                    523:  */
                    524: rpc_cli_t *rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short family, 
                    525:                const char *csHost, u_short Port);
                    526: /*
                    527:  * rpc_cli_closeClient() Close connection to RPC server and free resources
                    528:  * @cli = RPC Client session
                    529:  * return: none
                    530:  */
                    531: void rpc_cli_closeClient(rpc_cli_t * __restrict cli);
                    532: /*
                    533:  * rpc_cli_execCall() Execute RPC call
                    534:  * @cli = RPC Client session
                    535:  * @csModule = Module name, if NULL self binary
                    536:  * @csFunc = Function name for execute
                    537:  * @in_argc = IN count of arguments
                    538:  * @in_vals = IN RPC call array of rpc values
                    539:  * @out_argc = OUT returned count of arguments
                    540:  * @out_vals = OUT returned array of rpc values, must be free after use (see rpc_cli_freeVals())
                    541:  * return: -1 error or != -1 ok result
                    542:  */
                    543: int rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, const char *csFunc, int in_argc, 
                    544:                rpc_val_t * __restrict in_vals, int *out_argc, rpc_val_t ** __restrict out_vals);
                    545: /*
                    546:  * rpc_cli_freeVals() Free rpc_val_t array returned from RPC call
                    547:  * @args = Number of arguments in array
                    548:  * @vals = Value elements
                    549:  * return: none
                    550:  */
                    551: inline void rpc_cli_freeVals(int args, rpc_val_t *vals);
                    552: 
                    553: 
1.1.1.1.2.14  misho     554: /*
                    555:  * rpc_cli_openBLOBClient() Connect to BLOB Server
                    556:  * @rpccli = RPC Client session
                    557:  * @Port = Port for bind server, if Port == 0 default port is selected
                    558:  * return: NULL == error or !=NULL connection to BLOB server established
                    559:  */
                    560: rpc_cli_t *rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, u_short Port);
                    561: /*
                    562:  * rpc_cli_closeBLOBClient() Close connection to BLOB server and free resources
                    563:  * @cli = BLOB Client session
                    564:  * return: none
                    565:  */
                    566: void rpc_cli_closeBLOBClient(rpc_cli_t * __restrict cli);
                    567: 
                    568: 
1.1       misho     569: #endif

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