source: code/icb.c@ 8f5ba64

Last change on this file since 8f5ba64 was 8f5ba64, checked in by Mike Belopuhov <mike@…>, 11 years ago

fix two off-by-ones in icb_vis

  • Property mode set to 100644
File size: 15.0 KB
RevLine 
[cd7b81d]1/*
[626f420]2 * Copyright (c) 2009, 2010, 2013, 2014 Mike Belopuhov
[cd7b81d]3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <sys/param.h>
18#include <sys/queue.h>
19#include <stdarg.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <syslog.h>
24#include <unistd.h>
[626f420]25#include <ctype.h>
[cd7b81d]26#include <event.h>
[b7bc432]27#include <vis.h>
[cd7b81d]28
29#include "icb.h"
30#include "icbd.h"
31
32extern int creategroups;
[a785c27]33extern char srvname[MAXHOSTNAMELEN];
[cd7b81d]34
35void icb_command(struct icb_session *, char *, char *);
36void icb_groupmsg(struct icb_session *, char *);
[d45051e]37int icb_login(struct icb_session *, char *, char *, char *);
[4284008]38int icb_dowho(struct icb_session *, struct icb_group *);
[b6c9dd3]39char *icb_nextfield(char **, int);
[cd7b81d]40
41/*
42 * icb_init: initializes pointers to callbacks
43 */
44void
[7882a6f]45icb_init(void)
[cd7b81d]46{
47 LIST_INIT(&groups);
[a785c27]48
49 if (strlen(srvname) == 0)
50 (void)gethostname(srvname, sizeof srvname);
51 /*
52 * MAXHOSTNAMELEN is usually greater than what we
53 * can actually send, hence truncation:
54 */
55 if (strlen(srvname) > 200)
56 srvname[200] = '\0';
[cd7b81d]57}
58
59/*
60 * icb_start: called upon accepting a new connection, greets new client
61 */
62void
63icb_start(struct icb_session *is)
64{
[a785c27]65 icb_sendfmt(is, "%c%c%c%s%c%s", ICB_M_PROTO, '1', ICB_M_SEP, srvname,
[cd7b81d]66 ICB_M_SEP, "icbd");
67 SETF(is->flags, ICB_SF_PROTOSENT);
68}
69
70/*
71 * icb_input: main input processing routine
72 */
[d45051e]73int
[cd7b81d]74icb_input(struct icb_session *is)
75{
76 char *msg = is->buffer;
[1bcb666]77 unsigned char type;
[d45051e]78 int res = 0;
[cd7b81d]79
80 is->last = getmonotime();
[a2fadb4]81 type = msg[0];
82 msg++;
[cd7b81d]83 if (!ISSETF(is->flags, ICB_SF_LOGGEDIN) && type != ICB_M_LOGIN) {
84 icb_error(is, "Not logged in");
[d45051e]85 return (0);
[cd7b81d]86 }
87 switch (type) {
88 case ICB_M_LOGIN: {
89 char *nick, *group, *client, *cmd;
90
[b6c9dd3]91 client = icb_nextfield(&msg, 1);
92 nick = icb_nextfield(&msg, 1);
93 group = icb_nextfield(&msg, 1);
94 cmd = icb_nextfield(&msg, 1);
[cd7b81d]95 if (strlen(cmd) > 0 && cmd[0] == 'w') {
96 icb_error(is, "Command not implemented");
[7882a6f]97 icbd_drop(is, NULL);
[d45051e]98 return (1);
[cd7b81d]99 }
[1da9ee5]100 if (strlen(cmd) == 0 || strcmp(cmd, "login") != 0) {
101 icb_error(is, "Malformed login packet");
[7882a6f]102 icbd_drop(is, NULL);
[d45051e]103 return (1);
[1da9ee5]104 }
[d45051e]105 res = icb_login(is, group, nick, client);
[cd7b81d]106 break;
107 }
108 case ICB_M_OPEN: {
109 char *grpmsg;
110
[b6c9dd3]111 grpmsg = icb_nextfield(&msg, 0);
[cd7b81d]112 icb_groupmsg(is, grpmsg);
113 break;
114 }
115 case ICB_M_COMMAND: {
116 char *cmd, *arg;
117
[b6c9dd3]118 cmd = icb_nextfield(&msg, 1);
119 arg = icb_nextfield(&msg, 0);
[cd7b81d]120 icb_command(is, cmd, arg);
121 break;
122 }
[1fb1bbe]123 case ICB_M_PONG: {
124 icb_sendfmt(is, "%c", ICB_M_PING);
125 break;
126 }
[cd7b81d]127 case ICB_M_PROTO:
128 case ICB_M_NOOP:
129 /* ignore */
130 break;
131 default:
132 /* everything else is not valid */
[1bcb666]133 icb_error(is, "Undefined message type %u", type);
[cd7b81d]134 }
[d45051e]135 return (res);
[cd7b81d]136}
137
138/*
139 * icb_login: handles login ('a') packets
140 */
[d45051e]141int
[626f420]142icb_login(struct icb_session *is, char *grp, char *nick, char *client)
[cd7b81d]143{
144 char *defgrp = "1";
145 struct icb_group *ig;
146 struct icb_session *s;
[626f420]147 char group[ICB_MAXGRPLEN];
[cd7b81d]148
[626f420]149 if (!nick || strlen(nick) == 0 ||
[b7bc432]150 icb_vis(is->nick, nick, ICB_MAXNICKLEN, VIS_SP)) {
[cd7b81d]151 icb_error(is, "Invalid nick");
[7882a6f]152 icbd_drop(is, NULL);
[d45051e]153 return (1);
[cd7b81d]154 }
[626f420]155 if (!grp || strlen(grp) == 0)
156 strlcpy(group, defgrp, ICB_MAXGRPLEN);
157 else
[b7bc432]158 icb_vis(group, grp, ICB_MAXNICKLEN, VIS_SP);
[cd7b81d]159 LIST_FOREACH(ig, &groups, entry) {
160 if (strcmp(ig->name, group) == 0)
161 break;
162 }
163 if (ig == NULL) {
164 if (!creategroups) {
165 icb_error(is, "Invalid group %s", group);
[7882a6f]166 icbd_drop(is, NULL);
[d45051e]167 return (1);
[cd7b81d]168 } else {
169 if ((ig = icb_addgroup(is, group, NULL)) == NULL) {
170 icb_error(is, "Can't create group %s", group);
[d45051e]171 return (0);
[cd7b81d]172 }
[7882a6f]173 icbd_log(NULL, LOG_DEBUG, "%s created group %s",
[626f420]174 is->nick, group);
[cd7b81d]175 }
176 }
177 LIST_FOREACH(s, &ig->sess, entry) {
[626f420]178 if (strcmp(s->nick, is->nick) == 0) {
[cd7b81d]179 icb_error(is, "Nick is already in use");
[7882a6f]180 icbd_drop(is, NULL);
[d45051e]181 return (1);
[cd7b81d]182 }
183 }
184
185 if (client && strlen(client) > 0)
[b7bc432]186 icb_vis(is->client, client, sizeof is->client, VIS_SP);
[cd7b81d]187 is->group = ig;
188 is->login = time(NULL);
189 is->last = getmonotime();
190
191 /* notify group */
192 icb_status_group(ig, NULL, STATUS_SIGNON, "%s (%s@%s) entered group",
193 is->nick, is->client, is->host);
194
195 CLRF(is->flags, ICB_SF_PROTOSENT);
196 SETF(is->flags, ICB_SF_LOGGEDIN);
197
198 LIST_INSERT_HEAD(&ig->sess, is, entry);
199
200 /* acknowledge successful login */
201 icb_sendfmt(is, "%c", ICB_M_LOGIN);
202
203 /* notify user */
204 icb_status(is, STATUS_STATUS, "You are now in group %s%s", ig->name,
[4284008]205 icb_ismod(ig, is) ? " as moderator" : "");
[cd7b81d]206
207 /* send user a topic name */
208 if (strlen(ig->topic) > 0)
209 icb_status(is, STATUS_TOPIC, "Topic for %s is \"%s\"",
210 ig->name, ig->topic);
[d45051e]211 return (0);
[cd7b81d]212}
213
214/*
215 * icb_groupmsg: handles open message ('b') packets
216 */
217void
218icb_groupmsg(struct icb_session *is, char *msg)
219{
220 char buf[ICB_MSGSIZE];
221 struct icb_group *ig = is->group;
222 struct icb_session *s;
223 int buflen = 1;
224
225 if (strlen(msg) == 0) {
226 icb_error(is, "Empty message");
227 return;
228 }
229
230 buflen += snprintf(&buf[1], sizeof buf - 1, "%c%s%c%s", ICB_M_OPEN,
231 is->nick, ICB_M_SEP, msg);
232 buf[0] = buflen;
233
[45bd56a]234 logger(ig->name, is->nick, msg);
[55923b7]235
[cd7b81d]236 LIST_FOREACH(s, &ig->sess, entry) {
237 if (s == is)
238 continue;
[7882a6f]239 icbd_send(s, buf, buflen + 1);
[cd7b81d]240 }
241}
242
243/*
244 * icb_privmsg: handles personal message ('c') packets
245 */
246void
[626f420]247icb_privmsg(struct icb_session *is, char *to, char *msg)
[cd7b81d]248{
249 struct icb_group *ig = is->group;
250 struct icb_session *s;
[626f420]251 char whom[ICB_MAXNICKLEN];
252
[b7bc432]253 icb_vis(whom, to, ICB_MAXNICKLEN, VIS_SP);
[cd7b81d]254
[efa8586]255 /* try home group first */
[cd7b81d]256 LIST_FOREACH(s, &ig->sess, entry) {
257 if (strcmp(s->nick, whom) == 0)
258 break;
259 }
260 if (!s) {
[efa8586]261 /* try all groups until the first match */
262 LIST_FOREACH(ig, &groups, entry) {
263 LIST_FOREACH(s, &ig->sess, entry) {
264 if (strcmp(s->nick, whom) == 0)
265 break;
266 }
267 if (s)
268 break;
269 }
270 if (!s) {
271 icb_error(is, "No such user %s", whom);
272 return;
273 }
[cd7b81d]274 }
275 icb_sendfmt(s, "%c%s%c%s", ICB_M_PERSONAL, is->nick, ICB_M_SEP, msg);
276}
277
278/*
279 * icb_command: handles command ('h') packets
280 */
281void
282icb_command(struct icb_session *is, char *cmd, char *arg)
283{
284 void (*handler)(struct icb_session *, char *);
[626f420]285 char command[32]; /* XXX */
[cd7b81d]286
[b7bc432]287 icb_vis(command, cmd, sizeof command, VIS_SP);
[626f420]288
289 if ((handler = icb_cmd_lookup(command)) == NULL) {
290 icb_error(is, "Unsupported command: %s", command);
[cd7b81d]291 return;
292 }
293 handler(is, arg);
294}
295
296/*
297 * icb_cmdout: sends out command output ('i') packets, called from the
298 * command handlers
299 */
300void
301icb_cmdout(struct icb_session *is, int type, char *outmsg)
302{
303 char *otype = NULL;
304
305 switch (type) {
306 case CMDOUT_CO:
307 otype = "co";
308 break;
309 case CMDOUT_EC:
310 otype = "ec";
311 break;
312 case CMDOUT_WG:
313 otype = "wg";
314 break;
[4284008]315 case CMDOUT_WH:
316 otype = "wh";
317 break;
318 case CMDOUT_WL:
319 otype = "wl";
320 break;
[cd7b81d]321 default:
[7882a6f]322 icbd_log(is, LOG_ERR, "unknown cmdout type %d", type);
[cd7b81d]323 return;
324 }
[4284008]325 if (outmsg)
326 icb_sendfmt(is, "%c%s%c%s", ICB_M_CMDOUT, otype, ICB_M_SEP,
327 outmsg);
328 else
329 icb_sendfmt(is, "%c%s", ICB_M_CMDOUT, otype);
[cd7b81d]330}
331
332/*
333 * icb_status: sends a status message ('d') to the client
334 */
335void
336icb_status(struct icb_session *is, int type, const char *fmt, ...)
337{
338 va_list ap;
339 char buf[ICB_MSGSIZE];
340 int buflen = 1;
341 static const struct {
342 int type;
343 const char *msg;
344 } msgtab[] = {
345 { STATUS_ARRIVE, "Arrive" },
346 { STATUS_BOOT, "Boot" },
347 { STATUS_DEPART, "Depart" },
[9195a6a]348 { STATUS_HELP, "Help" },
[cd7b81d]349 { STATUS_NAME, "Name" },
[bf02a60]350 { STATUS_NOBEEP, "No-Beep" },
[cd7b81d]351 { STATUS_NOTIFY, "Notify" },
352 { STATUS_SIGNON, "Sign-on" },
353 { STATUS_SIGNOFF, "Sign-off" },
354 { STATUS_STATUS, "Status" },
355 { STATUS_TOPIC, "Topic" },
356 { STATUS_WARNING, "Warning" },
[1022119]357 { 0, NULL }
[cd7b81d]358 };
359
360 if (type < 0 || type > (int)nitems(msgtab) - 1)
361 return;
362 va_start(ap, fmt);
363 buflen += snprintf(&buf[1], sizeof buf - 1, "%c%s%c", ICB_M_STATUS,
364 msgtab[type].msg, ICB_M_SEP);
365 buflen += vsnprintf(&buf[buflen], sizeof buf - buflen, fmt, ap);
366 buf[0] = buflen;
367 va_end(ap);
[7882a6f]368 icbd_send(is, buf, buflen + 1);
[cd7b81d]369}
370
371/*
372 * icb_status: sends a status message ('d') to the group except of the
373 * "ex" if it's not NULL
374 */
375void
376icb_status_group(struct icb_group *ig, struct icb_session *ex, int type,
377 const char *fmt, ...)
378{
[a2fadb4]379 char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
[cd7b81d]380 va_list ap;
381 struct icb_session *s;
382
383 va_start(ap, fmt);
384 (void)vsnprintf(buf, sizeof buf, fmt, ap);
385 LIST_FOREACH(s, &ig->sess, entry) {
386 if (ex && s == ex)
387 continue;
388 icb_status(s, type, buf);
389 }
[23ca6f1]390 logger(ig->name, "", buf);
[7882a6f]391 icbd_log(NULL, LOG_DEBUG, "%s", buf);
[cd7b81d]392 va_end(ap);
393}
394
395/*
396 * icb_error: sends an error message ('e') to the client
397 */
398void
399icb_error(struct icb_session *is, const char *fmt, ...)
400{
401 char buf[ICB_MSGSIZE];
402 va_list ap;
403 int buflen = 1;
404
405 va_start(ap, fmt);
406 buflen += vsnprintf(&buf[2], sizeof buf - 2, fmt, ap);
407 va_end(ap);
408 buf[0] = ++buflen; /* account for ICB_M_ERROR */
409 buf[1] = ICB_M_ERROR;
[7882a6f]410 icbd_send(is, buf, buflen + 1);
411 icbd_log(is, LOG_DEBUG, "%s", buf + 2);
[cd7b81d]412}
413
414/*
415 * icb_remove: removes a session from the associated group
416 */
417void
418icb_remove(struct icb_session *is, char *reason)
419{
420 if (is->group) {
[4284008]421 if (icb_ismod(is->group, is))
[cd7b81d]422 (void)icb_pass(is->group, is, NULL);
423 LIST_REMOVE(is, entry);
424 if (reason)
425 icb_status_group(is->group, NULL, STATUS_SIGNOFF,
426 "%s (%s@%s) just left: %s", is->nick, is->client,
427 is->host, reason);
428 else
429 icb_status_group(is->group, NULL, STATUS_SIGNOFF,
430 "%s (%s@%s) just left", is->nick, is->client,
431 is->host);
[96a2e31]432 is->group = NULL;
[cd7b81d]433 }
434}
435
436/*
437 * icb_addgroup: adds a new group to the list
438 */
439struct icb_group *
440icb_addgroup(struct icb_session *is, char *name, char *mpass)
441{
442 struct icb_group *ig;
443
444 if ((ig = calloc(1, sizeof *ig)) == NULL)
445 return (NULL);
446 strlcpy(ig->name, name, sizeof ig->name);
447 if (mpass)
448 strlcpy(ig->mpass, mpass, sizeof ig->mpass);
449 if (is)
[4284008]450 ig->mod = is;
[cd7b81d]451 LIST_INIT(&ig->sess);
452 LIST_INSERT_HEAD(&groups, ig, entry);
453 return (ig);
454}
455
456#ifdef notused
457/*
458 * icb_delgroup: removes a group from the list
459 */
460void
461icb_delgroup(struct icb_group *ig)
462{
463 struct icb_session *s;
464
465 /* well, i guess we should kick out participants! ;-) */
466 LIST_FOREACH(s, &ig->sess, entry) {
467 icb_status(s, STATUS_WARNING, "Group dismissed");
468 s->group = NULL;
469 }
470 LIST_REMOVE(ig, entry);
471 bzero(ig, sizeof ig); /* paranoic thing, obviously */
472 free(ig);
473}
474#endif
475
476/*
[4284008]477 * icb_dowho: a helper function that sends out a group header as a command
478 * output and user information in the "wl" format
[cd7b81d]479 */
[4284008]480int
481icb_dowho(struct icb_session *is, struct icb_group *ig)
[cd7b81d]482{
[a2fadb4]483 char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
[cd7b81d]484 struct icb_session *s;
[4284008]485 int nusers = 0;
[cd7b81d]486
[4284008]487 icb_cmdout(is, CMDOUT_CO, " ");
488 snprintf(buf, sizeof buf, "Group: %-8s (%cvl) Mod: %-13s Topic: %s",
489 ig->name, ig->mod ? 'm' : 'p', ig->mod ? ig->mod->nick : "(None)",
490 strlen(ig->topic) > 0 ? ig->topic : "(None)");
491 icb_cmdout(is, CMDOUT_CO, buf);
[cd7b81d]492 LIST_FOREACH(s, &ig->sess, entry) {
493 (void)snprintf(buf, sizeof buf,
[bf02a60]494 "%c%c%s%c%lld%c0%c%lld%c%s%c%s%c%s",
[4284008]495 icb_ismod(ig, s) ? 'm' : ' ', ICB_M_SEP,
[cd7b81d]496 s->nick, ICB_M_SEP, getmonotime() - s->last,
497 ICB_M_SEP, ICB_M_SEP, s->login, ICB_M_SEP,
[c102bbf]498 s->client, ICB_M_SEP, s->host, ICB_M_SEP, " ");
[cd7b81d]499 icb_cmdout(is, CMDOUT_WL, buf);
[4284008]500 nusers++;
[cd7b81d]501 }
[4284008]502 return (nusers);
503}
504
505/*
506 * icb_who: sends a list of users of either the specified group or all
507 * groups found on the server
508 */
509void
510icb_who(struct icb_session *is, struct icb_group *ig)
511{
[a2fadb4]512 char buf[ICB_MSGSIZE - 10]; /* truncate to make sure all fits */
[4284008]513 struct icb_group *g;
514
515 if (!ig) {
516 int nusers = 0, ngroups = 0;
517
518 LIST_FOREACH(g, &groups, entry) {
519 nusers += icb_dowho(is, g);
520 ngroups++;
521 }
522 if (nusers > 0) {
523 (void)snprintf(buf, sizeof buf,
524 "Total: %d %s in %d %s",
525 nusers, nusers > 1 ? "users" : "user",
526 ngroups, ngroups > 1 ? "groups" : "group");
527 } else
528 (void)snprintf(buf, sizeof buf, "No users found.");
529 icb_cmdout(is, CMDOUT_CO, buf);
530 } else
531 (void)icb_dowho(is, ig);
[cd7b81d]532}
533
534/*
[4284008]535 * icb_ismod: checks whether group is moderated by "is"
[cd7b81d]536 */
[626f420]537inline int
[4284008]538icb_ismod(struct icb_group *ig, struct icb_session *is)
[cd7b81d]539{
[626f420]540 return (ig->mod == is);
[cd7b81d]541}
542
[1d2125a]543/*
544 * icb_modpermit: checks user against the moderators table if it has
545 * been populated
546 */
547int
[f3c60e6]548icb_modpermit(struct icb_session *is, int enforce)
[1d2125a]549{
550 extern char modtab[ICB_MTABLEN][ICB_MAXNICKLEN];
551 extern int modtabcnt;
552
[82d3c1f]553 icbd_modupdate();
[f3c60e6]554 if ((enforce ? 0 : modtabcnt == 0) ||
[1d2125a]555 bsearch(is->nick, modtab, modtabcnt, ICB_MAXNICKLEN,
556 (int (*)(const void *, const void *))strcmp))
557 return (1);
558 return (0);
559}
560
[cd7b81d]561/*
562 * icb_pass: passes moderation of group "ig" from "from" to "to",
563 * returns -1 if "from" is not a moderator, 1 if passed
564 * to "to" and 0 otherwise (no moderator or passed to the
565 * internal bot)
566 */
567int
568icb_pass(struct icb_group *ig, struct icb_session *from,
569 struct icb_session *to)
570{
[4284008]571 if (ig->mod && ig->mod != from)
[cd7b81d]572 return (-1);
573 if (!from && !to)
574 return (-1);
[4284008]575 ig->mod = to;
[cd7b81d]576 if (to)
577 icb_status(to, STATUS_NOTIFY, "%s just passed you moderation"
578 " of %s", from ? from->nick : "server", ig->name);
579 icb_status_group(ig, to, STATUS_NOTIFY, "%s has passed moderation "
580 "to %s", from ? from->nick : "server", to ? to->nick : "server");
581 return (1);
582}
583
584/*
[4284008]585 * icb_nextfield: advances through a given buffer returning pointer to the
[a202ff1]586 * beginning of the icb field or an empty string otherwise;
587 * cleans up trailing spaces
[cd7b81d]588 */
589char *
[b6c9dd3]590icb_nextfield(char **buf, int notrspace)
[cd7b81d]591{
592 char *start = *buf;
[a202ff1]593 char *end = NULL;
[cd7b81d]594
595 while (*buf && **buf != '\0' && **buf != ICB_M_SEP)
596 (*buf)++;
597 if (*buf && **buf == ICB_M_SEP) {
598 **buf = '\0';
[a202ff1]599 end = *buf;
[cd7b81d]600 (*buf)++;
[a202ff1]601 } else
602 end = *buf;
[b6c9dd3]603 while (notrspace && end && *(--end) == ' ' && end > start)
[a202ff1]604 *end = '\0';
[cd7b81d]605 return (start);
606}
607
608/*
609 * icb_sendfmt: formats a string and sends it over
610 */
611void
612icb_sendfmt(struct icb_session *is, const char *fmt, ...)
613{
614 char buf[ICB_MSGSIZE];
615 va_list ap;
616 int buflen = 1;
617
618 va_start(ap, fmt);
619 buflen += vsnprintf(&buf[1], sizeof buf - 1, fmt, ap);
620 va_end(ap);
621 buf[0] = buflen;
[7882a6f]622 icbd_send(is, buf, buflen + 1);
[cd7b81d]623}
[626f420]624
625/*
626 * icb_vis: strnvis-like function that escapes percentages as well
627 */
628int
[b7bc432]629icb_vis(char *dst, const char *src, size_t dstsize, int flags)
[626f420]630{
631 int si = 0, di = 0, td;
632
[8f5ba64]633 while ((size_t)di < dstsize - 1 && src[si] != '\0') {
[626f420]634 if (src[si] == '%')
635 dst[di++] = '%', dst[di] = '%';
[b7bc432]636 else if (src[si] == ' ' && flags & VIS_SP)
637 dst[di] = '_';
638 else if (isgraph(src[si]) || src[si] == ' ')
[626f420]639 dst[di] = src[si];
640 else {
641 td = snprintf(&dst[di], dstsize - di,
642 "\\%03o", (unsigned char)src[si]);
643 di += td - 1;
644 }
645 si++, di++;
646 }
[8f5ba64]647 dst[MIN((size_t)di, dstsize - 1)] = '\0';
[626f420]648 return (0);
649}
Note: See TracBrowser for help on using the repository browser.