Mercurial > hg > nnchat
comparison network.c @ 423:6727fec3c326
Rename nn_conn_send_msg() to nn_conn_send_msg_v() and add new nn_conn_send_msg().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 May 2012 11:09:48 +0300 |
parents | d015ecbd231d |
children | 162011bbec48 |
comparison
equal
deleted
inserted
replaced
422:8eb2839a565c | 423:6727fec3c326 |
---|---|
517 else | 517 else |
518 return NULL; | 518 return NULL; |
519 } | 519 } |
520 | 520 |
521 | 521 |
522 BOOL nn_conn_send_msg(nn_conn_t *conn, const char *user, const char *fmt, ...) | 522 BOOL nn_conn_send_msg(nn_conn_t *conn, const char *user, const char *str) |
523 { | 523 { |
524 char *tmp, *msg; | 524 char *msg; |
525 | |
526 if (str == NULL) | |
527 return FALSE; | |
528 | |
529 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str); | |
530 | |
531 if (msg != NULL) | |
532 { | |
533 BOOL ret = nn_conn_send_buf(conn, msg, strlen(msg) + 1); | |
534 th_free(msg); | |
535 return ret; | |
536 } | |
537 else | |
538 return FALSE; | |
539 } | |
540 | |
541 | |
542 BOOL nn_conn_send_msg_v(nn_conn_t *conn, const char *user, const char *fmt, ...) | |
543 { | |
544 char *tmp; | |
525 va_list ap; | 545 va_list ap; |
526 | 546 |
527 va_start(ap, fmt); | 547 va_start(ap, fmt); |
528 tmp = th_strdup_vprintf(fmt, ap); | 548 tmp = th_strdup_vprintf(fmt, ap); |
529 va_end(ap); | 549 va_end(ap); |
530 | 550 |
531 if (tmp == NULL) | 551 return nn_conn_send_msg(conn, user, tmp); |
532 return FALSE; | 552 } |
533 | |
534 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, tmp); | |
535 th_free(tmp); | |
536 | |
537 if (msg != NULL) | |
538 { | |
539 BOOL ret = nn_conn_send_buf(conn, msg, strlen(msg) + 1); | |
540 th_free(msg); | |
541 return ret; | |
542 } | |
543 else | |
544 return FALSE; | |
545 } |