Changeset c6e00b9 in code for icb.c


Ignore:
Timestamp:
Aug 24, 2017, 2:41:37 PM (8 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
4c07461
Parents:
c3f5bda
Message:

Split long open and private messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icb.c

    rc3f5bda rc6e00b9  
    257257        struct icb_group *ig = is->group;
    258258        struct icb_session *s;
    259         int res, buflen = 1;
     259        int res, buflen;
    260260
    261261        if (strlen(msg) == 0) {
     
    264264        }
    265265
    266         res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN,
    267             is->nick, ICB_M_SEP, msg);
    268         if (res < 0) {
    269                 icb_error(is, "Format error");
    270                 return;
    271         }
    272         buflen += MIN((size_t)res, sizeof buf - 1);
    273         buf[0] = buflen;
    274 
    275         logger(ig->name, is->nick, msg);
    276 
    277         LIST_FOREACH(s, &ig->sess, entry) {
    278                 if (s == is)
    279                         continue;
    280                 icbd_send(s, buf, buflen + 1);
    281         }
     266        do {
     267                res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN,
     268                    is->nick, ICB_M_SEP, msg);
     269                if (res < 0) {
     270                        icbd_log(is, LOG_ERR, "Format error in %s", __func__);
     271                        return;
     272                }
     273                /* res doesn't include the terminating NUL*/
     274                buflen = MIN((size_t)res + 1, sizeof buf - 1);
     275                buf[0] = buflen;
     276
     277                logger(ig->name, is->nick, msg);
     278
     279                LIST_FOREACH(s, &ig->sess, entry) {
     280                        if (s == is)
     281                                continue;
     282                        icbd_send(s, buf, buflen + 1);
     283                }
     284
     285                msg += buflen - 1;
     286        } while (res > buflen - 1);
    282287}
    283288
     
    290295        struct icb_group *ig = is->group;
    291296        struct icb_session *s;
     297        char buf[ICB_MSGSIZE];
    292298        char whom[ICB_MAXNICKLEN];
     299        int res, buflen;
    293300
    294301        icb_vis(whom, to, ICB_MAXNICKLEN, VIS_SP);
     
    314321                }
    315322        }
    316         icb_sendfmt(s, "%c%s%c%s", ICB_M_PERSONAL, is->nick, ICB_M_SEP, msg);
     323
     324        do {
     325                res = snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s",
     326                    ICB_M_PERSONAL, is->nick, ICB_M_SEP, msg);
     327                if (res < 0) {
     328                        icbd_log(is, LOG_ERR, "Format error in %s", __func__);
     329                        return;
     330                }
     331                /* res doesn't include the terminating NUL*/
     332                buflen = MIN((size_t)res + 1, sizeof buf - 1);
     333                buf[0] = buflen;
     334
     335                icbd_send(s, buf, buflen + 1);
     336
     337                msg += buflen - 1;
     338        } while (res > buflen - 1);
    317339}
    318340
     
    659681                return;
    660682        }
    661         buflen += MIN((size_t)res, sizeof buf - 1);
     683        buflen += MIN((size_t)res + 1, sizeof buf - 1);
    662684        buf[0] = buflen;
    663685        icbd_send(is, buf, buflen + 1);
Note: See TracChangeset for help on using the changeset viewer.