|
|
| version 1.1.1.1.2.14, 2010/07/07 09:29:42 | version 1.1.1.1.2.22, 2010/07/12 08:46:41 |
|---|---|
| Line 58 rpc_srv_dispatchCall(void *arg) | Line 58 rpc_srv_dispatchCall(void *arg) |
| rpc_SetErr(EINVAL, "Error:: get invalid RPC session ...\n"); | rpc_SetErr(EINVAL, "Error:: get invalid RPC session ...\n"); |
| ret = -5; | ret = -5; |
| goto makeReply; | goto makeReply; |
| } | } else |
| Limit = sizeof(struct tagRPCCall); | |
| // RPC is OK! Go decapsulate variables ... | // RPC is OK! Go decapsulate variables ... |
| if (rpc->call_argc) { | if (rpc->call_argc) { |
| v = (rpc_val_t*) (buf + sizeof(struct tagRPCCall)); | v = (rpc_val_t*) (buf + Limit); |
| // check RPC packet length | |
| if (rpc->call_argc * sizeof(rpc_val_t) > BUFSIZ - Limit) { | |
| rpc_SetErr(EMSGSIZE, "Error:: Too big RPC packet ...\n"); | |
| ret = -5; | |
| goto makeReply; | |
| } else | |
| Limit += rpc->call_argc * sizeof(rpc_val_t); | |
| // RPC received variables types OK! | // RPC received variables types OK! |
| data = (u_char*) v + rpc->call_argc * sizeof(rpc_val_t); | data = (u_char*) v + rpc->call_argc * sizeof(rpc_val_t); |
| for (i = 0; i < rpc->call_argc; i++) { | for (i = 0; i < rpc->call_argc; i++) { |
| switch (v[i].val_type) { | switch (v[i].val_type) { |
| case buffer: | case buffer: |
| if (v[i].val_len > BUFSIZ - Limit) { | |
| rpc_SetErr(EMSGSIZE, "Error:: Too big RPC packet ...\n"); | |
| ret = -5; | |
| goto makeReply; | |
| } else | |
| Limit += v[i].val_len; | |
| v[i].val.buffer = data; | v[i].val.buffer = data; |
| data += v[i].val_len; | data += v[i].val_len; |
| break; | break; |
| case string: | case string: |
| if (v[i].val_len + 1 > BUFSIZ - Limit) { | |
| rpc_SetErr(EMSGSIZE, "Error:: Too big RPC packet ...\n"); | |
| ret = -5; | |
| goto makeReply; | |
| } else | |
| Limit += v[i].val_len; | |
| v[i].val.string = (int8_t*) data; | v[i].val.string = (int8_t*) data; |
| data += v[i].val_len + 1; | data += v[i].val_len + 1; |
| break; | break; |
| Line 93 rpc_srv_dispatchCall(void *arg) | Line 115 rpc_srv_dispatchCall(void *arg) |
| ret = -6; | ret = -6; |
| } else | } else |
| if ((ret = rpc_srv_execCall(f, rpc, v)) == -1) | if ((ret = rpc_srv_execCall(f, rpc, v)) == -1) |
| ret = -6; | ret = -9; |
| else | else |
| argc = rpc_srv_getValsCall(f, &vals); | argc = rpc_srv_getValsCall(f, &vals); |
| Line 179 rpc_srv_dispatchVars(void *arg) | Line 201 rpc_srv_dispatchVars(void *arg) |
| rpc_cli_t *c = arg; | rpc_cli_t *c = arg; |
| rpc_srv_t *s; | rpc_srv_t *s; |
| rpc_blob_t *b; | rpc_blob_t *b; |
| int cx, ret; | int ret; |
| fd_set fds; | fd_set fds; |
| u_char buf[sizeof(struct tagBLOBHdr)]; | u_char buf[sizeof(struct tagBLOBHdr)]; |
| struct tagBLOBHdr *blob; | struct tagBLOBHdr *blob; |
| Line 190 rpc_srv_dispatchVars(void *arg) | Line 212 rpc_srv_dispatchVars(void *arg) |
| } else | } else |
| s = c->cli_parent; | s = c->cli_parent; |
| cx = -1; | |
| do { | do { |
| // check for disable service at this moment? | // check for disable service at this moment? |
| if (s->srv_blob.state == disable) { | if (s->srv_blob.state == disable) { |
| Line 203 rpc_srv_dispatchVars(void *arg) | Line 224 rpc_srv_dispatchVars(void *arg) |
| ret = select(c->cli_sock + 1, &fds, NULL, NULL, NULL); | ret = select(c->cli_sock + 1, &fds, NULL, NULL, NULL); |
| if (ret == -1) { | if (ret == -1) { |
| ret = -2; | ret = -2; |
| } else | } |
| cx++; | |
| memset(buf, 0, sizeof buf); | memset(buf, 0, sizeof buf); |
| if ((ret = recv(c->cli_sock, buf, sizeof buf, 0)) == -1) { | if ((ret = recv(c->cli_sock, buf, sizeof buf, 0)) == -1) { |
| LOGERR; | LOGERR; |
| Line 222 rpc_srv_dispatchVars(void *arg) | Line 243 rpc_srv_dispatchVars(void *arg) |
| } else | } else |
| blob = (struct tagBLOBHdr*) buf; | blob = (struct tagBLOBHdr*) buf; |
| // check BLOB packet session info | // check BLOB packet session info |
| if (memcmp(&blob->hdr_session, &s->srv_session, sizeof blob->hdr_session) || | if (memcmp(&blob->hdr_session, &s->srv_session, sizeof blob->hdr_session)) { |
| blob->hdr_seq != cx) { | rpc_SetErr(EINVAL, "Error:: get invalid BLOB session ...\n"); |
| rpc_SetErr(EINVAL, "Error:: get invalid BLOB session in seq=%d...\n", blob->hdr_seq); | |
| ret = -5; | ret = -5; |
| goto makeReply; | goto makeReply; |
| } | } |
| Line 236 rpc_srv_dispatchVars(void *arg) | Line 256 rpc_srv_dispatchVars(void *arg) |
| blob->hdr_var); | blob->hdr_var); |
| ret = -6; | ret = -6; |
| break; | break; |
| } | } else |
| blob->hdr_len = b->blob_len; | |
| if (rpc_srv_blobMap(s, b) != -1) { | if (rpc_srv_blobMap(s, b) != -1) { |
| ret = rpc_srv_sendBLOB(c, b); | ret = rpc_srv_sendBLOB(c, b); |
| Line 268 rpc_srv_dispatchVars(void *arg) | Line 289 rpc_srv_dispatchVars(void *arg) |
| makeReply: | makeReply: |
| // Replay to client! | // Replay to client! |
| blob->hdr_cmd = ret < 0 ? error : ok; | blob->hdr_cmd = ret < 0 ? error : ok; |
| blob->hdr_seq = ret; | blob->hdr_ret = ret; |
| if ((ret = send(c->cli_sock, buf, sizeof buf, 0)) == -1) { | if ((ret = send(c->cli_sock, buf, sizeof buf, 0)) == -1) { |
| LOGERR; | LOGERR; |
| ret = -8; | ret = -8; |
| Line 412 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) | Line 433 rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv) |
| } | } |
| pthread_mutex_unlock(&srv->srv_blob.mtx); | pthread_mutex_unlock(&srv->srv_blob.mtx); |
| while (pthread_mutex_trylock(&srv->srv_blob.mtx) == EBUSY); | |
| pthread_mutex_destroy(&srv->srv_blob.mtx); | pthread_mutex_destroy(&srv->srv_blob.mtx); |
| } | } |
| Line 580 rpc_srv_initServer(u_int regProgID, u_int regProcID, i | Line 602 rpc_srv_initServer(u_int regProgID, u_int regProcID, i |
| } else | } else |
| memset(srv->srv_clients, 0, srv->srv_numcli * sizeof(rpc_cli_t)); | memset(srv->srv_clients, 0, srv->srv_numcli * sizeof(rpc_cli_t)); |
| pthread_mutex_init(&srv->srv_mtx, NULL); | |
| rpc_srv_registerCall(srv, NULL, CALL_SRVSHUTDOWN, 0); | rpc_srv_registerCall(srv, NULL, CALL_SRVSHUTDOWN, 0); |
| rpc_srv_registerCall(srv, NULL, CALL_SRVCLIENTS, 0); | rpc_srv_registerCall(srv, NULL, CALL_SRVCLIENTS, 0); |
| rpc_srv_registerCall(srv, NULL, CALL_SRVCALLS, 0); | rpc_srv_registerCall(srv, NULL, CALL_SRVCALLS, 0); |
| rpc_srv_registerCall(srv, NULL, CALL_SRVSESSIONS, 0); | rpc_srv_registerCall(srv, NULL, CALL_SRVSESSIONS, 0); |
| pthread_mutex_init(&srv->srv_mtx, NULL); | |
| return srv; | return srv; |
| } | } |
| Line 626 rpc_srv_endServer(rpc_srv_t * __restrict srv) | Line 648 rpc_srv_endServer(rpc_srv_t * __restrict srv) |
| } | } |
| pthread_mutex_unlock(&srv->srv_mtx); | pthread_mutex_unlock(&srv->srv_mtx); |
| while (pthread_mutex_trylock(&srv->srv_mtx) == EBUSY); | |
| pthread_mutex_destroy(&srv->srv_mtx); | pthread_mutex_destroy(&srv->srv_mtx); |
| free(srv); | free(srv); |