diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-08-21 20:23:02 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-08-21 20:23:02 +0000 |
| commit | ba711be9bdce4b3d0ced9bff5e2399aa3442e611 (patch) | |
| tree | 4df741cec37f41efecd95ced338f18e4f367875f | |
| parent | 9bfb9d9ed22bfbfec2ff49c73cb1994b2ea5981a (diff) | |
| download | pica-pica-ba711be9bdce4b3d0ced9bff5e2399aa3442e611.tar.gz pica-pica-ba711be9bdce4b3d0ced9bff5e2399aa3442e611.zip | |
updated test_client, fixed found bugs
git-svn-id: svn://localhost/project_picapica/trunk@264 fb96df88-216d-11de-830c-f3023f12d8ac
| -rwxr-xr-x | PICA_client.c | 2 | ||||
| -rwxr-xr-x | PICA_client.h | 2 | ||||
| -rw-r--r-- | PICA_id.c | 23 | ||||
| -rwxr-xr-x | PICA_node.h | 2 | ||||
| -rwxr-xr-x | tests/test_client | bin | 34025 -> 34578 bytes | |||
| -rwxr-xr-x | tests/test_client.c | 37 |
6 files changed, 47 insertions, 19 deletions
diff --git a/PICA_client.c b/PICA_client.c index 03d8c21..61bc8ef 100755 --- a/PICA_client.c +++ b/PICA_client.c @@ -718,7 +718,7 @@ if (!cid->ctx) goto error_ret_2; } -if (!PICA_get_id_from_cert(cert_file, cid->id)) +if (!PICA_get_id_from_cert_file(cert_file, cid->id)) { ret_err=PICA_ERRINVCERT; goto error_ret_3; diff --git a/PICA_client.h b/PICA_client.h index cddd22f..4da2e98 100755 --- a/PICA_client.h +++ b/PICA_client.h @@ -169,7 +169,7 @@ extern "C" { #endif //read certificate from cert_file in PEM format, store id in buffer pointed by id -int PICA_get_id_from_cert(const char *cert_file, unsigned char *id); +int PICA_get_id_from_cert_file(const char *cert_file, unsigned char *id); int PICA_client_init(struct PICA_client_callbacks *clcbs); int PICA_new_connection @@ -24,7 +24,27 @@ return 1; unsigned char *PICA_id_from_base64(const unsigned char *buf, unsigned char *id) { +BIO *biomem, *b64; +static char localidbuf[PICA_ID_SIZE]; +int inlen, bread = 0; +unsigned char *idbuf = id; + +b64 = BIO_new(BIO_f_base64()); +BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); +biomem = BIO_new_mem_buf(buf, -1); +biomem = BIO_push(b64, biomem); + +if (idbuf == NULL) + idbuf = localidbuf; +bread = BIO_read(biomem, idbuf, PICA_ID_SIZE); + +if (bread != PICA_ID_SIZE) + idbuf = NULL; + +BIO_free_all(biomem); + +return idbuf; } char *PICA_id_to_base64(const unsigned char *id, char *buf) @@ -48,7 +68,10 @@ if (outputbuf == NULL) memcpy(outputbuf, sourcebuf, b64len); +*strchr(outputbuf, '\n')='\0'; outputbuf[b64len] = '\0'; BIO_free_all(biomem); + +return outputbuf; } diff --git a/PICA_node.h b/PICA_node.h index 93c3413..43b24f5 100755 --- a/PICA_node.h +++ b/PICA_node.h @@ -67,7 +67,7 @@ #define PICA_NETWORKNAME "TESTNET" // TEMP //CONF -#define NEWCONN_BUFSIZE 10 +#define NEWCONN_BUFSIZE 64 //#define CL_RBUFSIZE 32 //#define CL_WBUFSIZE 128 diff --git a/tests/test_client b/tests/test_client Binary files differindex f08b315..1af0445 100755 --- a/tests/test_client +++ b/tests/test_client diff --git a/tests/test_client.c b/tests/test_client.c index 818860a..dad82ae 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -13,48 +13,48 @@ int _outgoing_chnl=0; unsigned char buf[64*1024]; -int accept_cb(unsigned int id) +int accept_cb(const unsigned char *id) { -printf("accept_cb: %u\n",id); +printf("accept_cb: %s\n",PICA_id_to_base64(id, NULL)); return 1; } //получение сообщения. -void newmsg_cb(unsigned int peer_id,char* msgbuf,unsigned int nb,int type) +void newmsg_cb(const unsigned char *peer_id,char* msgbuf,unsigned int nb,int type) { memcpy(buf,msgbuf,nb); buf[nb]=0; -printf(" %u: ",peer_id); +printf(" %s: ",PICA_id_to_base64(peer_id, NULL)); puts(buf); } //получение подтверждения о доставке сообщения -void msgok_cb(unsigned int peer_id) +void msgok_cb(const unsigned char *peer_id) { puts("[V]"); } //создание канала с собеседником -void channel_established_cb(unsigned int peer_id) +void channel_established_cb(const unsigned char *peer_id) { puts("channel_established_cb"); } -void channel_failed_cb(unsigned int peer_id) +void channel_failed_cb(const unsigned char *peer_id) { -printf("Failed to create channel to %u\n",peer_id); +printf("Failed to create channel to %s\n",PICA_id_to_base64(peer_id, NULL)); chn=0; } //входящий запрос на создание канала от пользователя с номером caller_id //<<int accept_cb(unsigned int caller_id); //запрошенный пользователь не найден, в оффлайне или отказался от общения -void notfound_cb(unsigned int callee_id) +void notfound_cb(const unsigned char *callee_id) { puts("notfound_cb"); } -void channel_closed_cb(unsigned int peer_id, int reason) +void channel_closed_cb(const unsigned char *peer_id, int reason) { -printf("channel_closed_cb( peer_id = %u, reason = %i)\n", peer_id, reason); +printf("channel_closed_cb( peer_id = %s, reason = %i)\n", PICA_id_to_base64(peer_id, NULL), reason); } void nodelist_cb(int type, void *addr_bin, const char *addr_str, unsigned int port) @@ -79,9 +79,9 @@ switch(type) } } -int peer_cert_verify_cb(unsigned int peer_id, const char *cert_pem, unsigned int nb) +int peer_cert_verify_cb(const unsigned char *peer_id, const char *cert_pem, unsigned int nb) { - printf("peer's certificate (%u): \n%.*s\n", peer_id, nb,cert_pem); + printf("peer's certificate (%s): \n%.*s\n", PICA_id_to_base64(peer_id, NULL), nb,cert_pem); return 1; } @@ -100,7 +100,7 @@ struct PICA_client_callbacks cbs = { int main(int argc,char** argv) { int ret; -unsigned int peer_id; +unsigned char peer_id[PICA_ID_SIZE]; if (argc<4) { @@ -139,8 +139,13 @@ return 1; if (argc==5) { - peer_id=atoi(argv[4]); - printf("Creating channel to %u...\n",peer_id); + if (PICA_id_from_base64(argv[4], peer_id) == NULL) + { + puts("invalid peer_id"); + return 1; + } + + printf("Creating channel to %s...\n",PICA_id_to_base64(peer_id, NULL)); ret=PICA_create_channel(c,peer_id,&chn); //sleep(17);//timeout test |
