- The big forward port. I probably broke lots of stuff, so please look over any
[ircu2.10.12-pk.git] / ircd / send.c
1 /*
2  * IRC - Internet Relay Chat, common/send.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 1, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * $Id$
21  */
22 #include "config.h"
23
24 #include "send.h"
25 #include "channel.h"
26 #include "class.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "ircd_features.h"
30 #include "ircd_snprintf.h"
31 #include "ircd_string.h"
32 #include "list.h"
33 #include "match.h"
34 #include "msg.h"
35 #include "numnicks.h"
36 #include "parse.h"
37 #include "s_bsd.h"
38 #include "s_debug.h"
39 #include "s_misc.h"
40 #include "s_user.h"
41 #include "struct.h"
42 #include "sys.h"
43
44 #include <assert.h>
45 #include <stdio.h>
46 #include <string.h>
47
48
49 static int sentalong[MAXCONNECTIONS];
50 static int sentalong_marker;
51 struct SLink *opsarray[32];     /* don't use highest bit unless you change
52                                    atoi to strtoul in sendto_op_mask() */
53 static struct Connection *send_queues = 0;
54
55 /*
56  * dead_link
57  *
58  * An error has been detected. The link *must* be closed,
59  * but *cannot* call ExitClient (m_bye) from here.
60  * Instead, mark it with FLAG_DEADSOCKET. This should
61  * generate ExitClient from the main loop.
62  *
63  * If 'notice' is not NULL, it is assumed to be a format
64  * for a message to local opers. It can contain only one
65  * '%s', which will be replaced by the sockhost field of
66  * the failing link.
67  *
68  * Also, the notice is skipped for "uninteresting" cases,
69  * like Persons and yet unknown connections...
70  */
71
72 static void dead_link(struct Client *to, char *notice)
73 {
74   SetFlag(to, FLAG_DEADSOCKET);
75   /*
76    * If because of BUFFERPOOL problem then clean dbuf's now so that
77    * notices don't hurt operators below.
78    */
79   DBufClear(&(cli_recvQ(to)));
80   MsgQClear(&(cli_sendQ(to)));
81   client_drop_sendq(cli_connect(to));
82
83   /*
84    * Keep a copy of the last comment, for later use...
85    */
86   ircd_strncpy(cli_info(to), notice, REALLEN);
87
88   if (!IsUser(to) && !IsUnknown(to) && !HasFlag(to, FLAG_CLOSING))
89     sendto_opmask_butone(0, SNO_OLDSNO, "%s for %s", cli_info(to), cli_name(to));
90   Debug((DEBUG_ERROR, cli_info(to)));
91 }
92
93 static int can_send(struct Client* to)
94 {
95   assert(0 != to);
96   return (IsDead(to) || IsMe(to) || -1 == cli_fd(to)) ? 0 : 1;
97 }
98
99 /* This helper routine kills the connection with the highest sendq, to
100  * try to free up some buffer memory.
101  */
102 void
103 kill_highest_sendq(int servers_too)
104 {
105   int i;
106   unsigned int highest_sendq = 0;
107   struct Client *highest_client = 0;
108
109   for (i = HighestFd; i >= 0; i--)
110   {
111     if (!LocalClientArray[i] || (!servers_too && cli_serv(LocalClientArray[i])))
112       continue; /* skip servers */
113     
114     /* If this sendq is higher than one we last saw, remember it */
115     if (MsgQLength(&(cli_sendQ(LocalClientArray[i]))) > highest_sendq)
116     {
117       highest_client = LocalClientArray[i];
118       highest_sendq = MsgQLength(&(cli_sendQ(highest_client)));
119     }
120   }
121
122   if (highest_client)
123     dead_link(highest_client, "Buffer allocation error");
124 }
125
126 /*
127  * flush_connections
128  *
129  * Used to empty all output buffers for all connections. Should only
130  * be called once per scan of connections. There should be a select in
131  * here perhaps but that means either forcing a timeout or doing a poll.
132  * When flushing, all we do is empty the obuffer array for each local
133  * client and try to send it. if we cant send it, it goes into the sendQ
134  * -avalon
135  */
136 void flush_connections(struct Client* cptr)
137 {
138   if (cptr) {
139     send_queued(cptr);
140   }
141   else {
142     struct Connection* con;
143     for (con = send_queues; con; con = con_next(con)) {
144       assert(0 < MsgQLength(&(con_sendQ(con))));
145       send_queued(con_client(con));
146     }
147   }
148 }
149
150 /*
151  * send_queued
152  *
153  * This function is called from the main select-loop (or whatever)
154  * when there is a chance that some output would be possible. This
155  * attempts to empty the send queue as far as possible...
156  */
157 void send_queued(struct Client *to)
158 {
159   assert(0 != to);
160   assert(0 != cli_local(to));
161
162   if (IsBlocked(to) || !can_send(to))
163     return;                     /* Don't bother */
164
165   while (MsgQLength(&(cli_sendQ(to))) > 0) {
166     unsigned int len;
167
168     if ((len = deliver_it(to, &(cli_sendQ(to))))) {
169       msgq_delete(&(cli_sendQ(to)), len);
170       cli_lastsq(to) = MsgQLength(&(cli_sendQ(to))) / 1024;
171       if (IsBlocked(to)) {
172         update_write(to);
173         return;
174       }
175     }
176     else {
177       if (IsDead(to)) {
178         char tmp[512];
179         sprintf(tmp,"Write error: %s",(strerror(cli_error(to))) ? (strerror(cli_error(to))) : "Unknown error" );
180         dead_link(to, tmp);
181       }
182       return;
183     }
184   }
185
186   /* Ok, sendq is now empty... */
187   client_drop_sendq(cli_connect(to));
188   update_write(to);
189 }
190
191 void send_buffer(struct Client* to, struct MsgBuf* buf, int prio)
192 {
193   assert(0 != to);
194   assert(0 != buf);
195
196   if (cli_from(to))
197     to = cli_from(to);
198
199   if (!can_send(to))
200     /*
201      * This socket has already been marked as dead
202      */
203     return;
204
205   if (MsgQLength(&(cli_sendQ(to))) > get_sendq(to)) {
206     if (IsServer(to))
207       sendto_opmask_butone(0, SNO_OLDSNO, "Max SendQ limit exceeded for %C: "
208                            "%zu > %zu", to, MsgQLength(&(cli_sendQ(to))),
209                            get_sendq(to));
210     dead_link(to, "Max sendQ exceeded");
211     return;
212   }
213
214   Debug((DEBUG_SEND, "Sending [%p] to %s", buf, cli_name(to)));
215
216   msgq_add(&(cli_sendQ(to)), buf, prio);
217   client_add_sendq(cli_connect(to), &send_queues);
218   update_write(to);
219
220   /*
221    * Update statistics. The following is slightly incorrect
222    * because it counts messages even if queued, but bytes
223    * only really sent. Queued bytes get updated in SendQueued.
224    */
225   ++(cli_sendM(to));
226   ++(cli_sendM(&me));
227   /*
228    * This little bit is to stop the sendQ from growing too large when
229    * there is no need for it to. Thus we call send_queued() every time
230    * 2k has been added to the queue since the last non-fatal write.
231    * Also stops us from deliberately building a large sendQ and then
232    * trying to flood that link with data (possible during the net
233    * relinking done by servers with a large load).
234    */
235   if (MsgQLength(&(cli_sendQ(to))) / 1024 > cli_lastsq(to))
236     send_queued(to);
237 }
238
239 /*
240  * Send a msg to all ppl on servers/hosts that match a specified mask
241  * (used for enhanced PRIVMSGs)
242  *
243  *  addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
244  */
245
246 static int match_it(struct Client *from, struct Client *one, const char *mask, int what)
247 {
248   switch (what)
249   {
250     case MATCH_HOST:
251       return (match(mask, cli_user(one)->host) == 0 ||
252         (HasHiddenHost(one) && match(mask, cli_user(one)->realhost) == 0));
253     case MATCH_SERVER:
254     default:
255       return (match(mask, cli_name(cli_user(one)->server)) == 0);
256   }
257 }
258
259 /*
260  * Send a raw command to a single client; use *ONLY* if you absolutely
261  * must send a command without a prefix.
262  */
263 void sendrawto_one(struct Client *to, const char *pattern, ...)
264 {
265   struct MsgBuf *mb;
266   va_list vl;
267
268   va_start(vl, pattern);
269   mb = msgq_vmake(to, pattern, vl);
270   va_end(vl);
271
272   send_buffer(to, mb, 0);
273
274   msgq_clean(mb);
275 }
276
277 /*
278  * Send a (prefixed) command to a single client; select which of <cmd>
279  * <tok> to use depending on if to is a server or not.  <from> is the
280  * originator of the command.
281  */
282 void sendcmdto_one(struct Client *from, const char *cmd, const char *tok,
283                    struct Client *to, const char *pattern, ...)
284 {
285   struct VarData vd;
286   struct MsgBuf *mb;
287
288   to = cli_from(to);
289
290   vd.vd_format = pattern; /* set up the struct VarData for %v */
291   va_start(vd.vd_args, pattern);
292
293   mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd,
294                  &vd);
295
296   va_end(vd.vd_args);
297
298   send_buffer(to, mb, 0);
299
300   msgq_clean(mb);
301 }
302
303 /*
304  * Send a (prefixed) command to a single client in the priority queue;
305  * select  which of <cmd> <tok> to use depending on if to is a server
306  *or not.  <from> is the originator of the command.
307  */
308 void sendcmdto_prio_one(struct Client *from, const char *cmd, const char *tok,
309                         struct Client *to, const char *pattern, ...)
310 {
311   struct VarData vd;
312   struct MsgBuf *mb;
313
314   to = cli_from(to);
315
316   vd.vd_format = pattern; /* set up the struct VarData for %v */
317   va_start(vd.vd_args, pattern);
318
319   mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd,
320                  &vd);
321
322   va_end(vd.vd_args);
323
324   send_buffer(to, mb, 1);
325
326   msgq_clean(mb);
327 }
328
329 /*
330  * Send a (prefixed) command to all servers but one, using tok; cmd
331  * is ignored in this particular function.
332  */
333 void sendcmdto_serv_butone(struct Client *from, const char *cmd,
334                            const char *tok, struct Client *one,
335                            const char *pattern, ...)
336 {
337   struct VarData vd;
338   struct MsgBuf *mb;
339   struct DLink *lp;
340
341   vd.vd_format = pattern; /* set up the struct VarData for %v */
342   va_start(vd.vd_args, pattern);
343
344   /* use token */
345   mb = msgq_make(&me, "%C %s %v", from, tok, &vd);
346   va_end(vd.vd_args);
347
348   /* send it to our downlinks */
349   for (lp = cli_serv(&me)->down; lp; lp = lp->next) {
350     if (one && lp->value.cptr == cli_from(one))
351       continue;
352     send_buffer(lp->value.cptr, mb, 0);
353   }
354
355   msgq_clean(mb);
356 }
357
358 /*
359  * Send a (prefix) command originating from <from> to all channels
360  * <from> is locally on.  <from> must be a user. <tok> is ignored in
361  * this function.
362  *
363  * Update: don't send to 'one', if any. --Vampire
364  */
365 /* XXX sentalong_marker used XXX
366  *
367  * There is not an easy way to revoke the need for sentalong_marker
368  * from this function.  Thoughts and ideas would be welcome... -Kev
369  *
370  * One possibility would be to internalize the sentalong array; that
371  * could be prohibitively big, though.  We could get around that by
372  * making one that's the number of connected servers or something...
373  * or perhaps by adding a special flag to the servers we've sent a
374  * message to, and then a final loop through the connected servers
375  * to delete the flag. -Kev
376  */
377 void sendcmdto_common_channels_butone(struct Client *from, const char *cmd,
378                                       const char *tok, struct Client *one,
379                                       const char *pattern, ...)
380 {
381   struct VarData vd;
382   struct MsgBuf *mb;
383   struct Membership *chan;
384   struct Membership *member;
385
386   assert(0 != from);
387   assert(0 != cli_from(from));
388   assert(0 != pattern);
389   assert(!IsServer(from) && !IsMe(from));
390
391   vd.vd_format = pattern; /* set up the struct VarData for %v */
392
393   va_start(vd.vd_args, pattern);
394
395   /* build the buffer */
396   mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd);
397   va_end(vd.vd_args);
398
399   sentalong_marker++;
400   if (-1 < cli_fd(cli_from(from)))
401     sentalong[cli_fd(cli_from(from))] = sentalong_marker;
402   /*
403    * loop through from's channels, and the members on their channels
404    */
405   for (chan = cli_user(from)->channel; chan; chan = chan->next_channel) {
406     if (IsZombie(chan))
407       continue;
408     for (member = chan->channel->members; member;
409          member = member->next_member)
410       if (MyConnect(member->user) && -1 < cli_fd(cli_from(member->user)) &&
411           member->user != one &&
412           sentalong[cli_fd(cli_from(member->user))] != sentalong_marker) {
413         sentalong[cli_fd(cli_from(member->user))] = sentalong_marker;
414         send_buffer(member->user, mb, 0);
415       }
416   }
417
418   if (MyConnect(from) && from != one)
419     send_buffer(from, mb, 0);
420
421   msgq_clean(mb);
422 }
423
424 /*
425  * Send a (prefixed) command to all local users on the channel specified
426  * by <to>; <tok> is ignored by this function
427  *
428  * Update: don't send to 'one', if any. --Vampire
429  */
430 void sendcmdto_channel_butserv_butone(struct Client *from, const char *cmd,
431                                       const char *tok, struct Channel *to,
432                                       struct Client *one, const char *pattern,
433                                       ...)
434 {
435   struct VarData vd;
436   struct MsgBuf *mb;
437   struct Membership *member;
438
439   vd.vd_format = pattern; /* set up the struct VarData for %v */
440   va_start(vd.vd_args, pattern);
441
442   /* build the buffer */
443   mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd);
444   va_end(vd.vd_args);
445
446   /* send the buffer to each local channel member */
447   for (member = to->members; member; member = member->next_member) {
448     if (MyConnect(member->user) && member->user != one && !IsZombie(member))
449       send_buffer(member->user, mb, 0);
450   }
451
452   msgq_clean(mb);
453 }
454
455 /*
456  * Send a (prefixed) command to all users on this channel, including
457  * remote users; users to skip may be specified by setting appropriate
458  * flags in the <skip> argument.  <one> will also be skipped.
459  */
460 /* XXX sentalong_marker used XXX
461  *
462  * We can drop sentalong_marker from this function by adding a field to
463  * channels and to connections; what we do is make a user's connection
464  * a "member" of the channel by adding it to the new list, and we use
465  * the struct Membership status as a reference count.  Then, to implement
466  * this function, we just walk the list of connections.  Unfortunately,
467  * this doesn't account for sending only to channel ops, or for not
468  * sending to +d users; we could account for that by splitting those
469  * counts out, but that would imply adding two more fields (at least) to
470  * the struct Membership... -Kev
471  */
472 void sendcmdto_channel_butone(struct Client *from, const char *cmd,
473                               const char *tok, struct Channel *to,
474                               struct Client *one, unsigned int skip,
475                               const char *pattern, ...)
476 {
477   struct Membership *member;
478   struct VarData vd;
479   struct MsgBuf *user_mb;
480   struct MsgBuf *serv_mb;
481
482   vd.vd_format = pattern;
483
484   /* Build buffer to send to users */
485   va_start(vd.vd_args, pattern);
486   user_mb = msgq_make(0, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? "%:#C %s @%v" : "%:#C %s %v",
487                       from, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? MSG_NOTICE : cmd, &vd);
488   va_end(vd.vd_args);
489
490   /* Build buffer to send to servers */
491   va_start(vd.vd_args, pattern);
492   serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd);
493   va_end(vd.vd_args);
494
495   /* send buffer along! */
496   sentalong_marker++;
497   for (member = to->members; member; member = member->next_member) {
498     /* skip one, zombies, and deaf users... */
499     if (cli_from(member->user) == one || IsZombie(member) ||
500         (skip & SKIP_DEAF && IsDeaf(member->user)) ||
501         (skip & SKIP_NONOPS && !IsChanOp(member)) ||
502         (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member)) ||
503         (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) ||
504         cli_fd(cli_from(member->user)) < 0 ||
505         sentalong[cli_fd(cli_from(member->user))] == sentalong_marker)
506       continue;
507     sentalong[cli_fd(cli_from(member->user))] = sentalong_marker;
508
509     if (MyConnect(member->user)) /* pick right buffer to send */
510       send_buffer(member->user, user_mb, 0);
511     else
512       send_buffer(member->user, serv_mb, 0);
513   }
514
515   msgq_clean(user_mb);
516   msgq_clean(serv_mb);
517 }
518
519 /*
520  * Send a (prefixed) command to all users except <one> that have
521  * <flag> set.
522  */
523 void sendwallto_group_butone(struct Client *from, int type, struct Client *one,
524                              const char *pattern, ...)
525 {
526   struct VarData vd;
527   struct Client *cptr;
528   struct MsgBuf *mb;
529   struct DLink *lp;
530   char *prefix=NULL;
531   char *tok=NULL;
532   int i;
533
534   vd.vd_format = pattern;
535
536   /* Build buffer to send to users */
537   va_start(vd.vd_args, pattern);
538   switch (type) {
539         case WALL_DESYNCH:
540                 prefix="";
541                 tok=TOK_DESYNCH;
542                 break;
543         case WALL_WALLOPS:
544                 prefix="* ";
545                 tok=TOK_WALLOPS;
546                 break;
547         case WALL_WALLUSERS:
548                 prefix="$ ";
549                 tok=TOK_WALLUSERS;
550                 break;
551         default:
552                 assert(0);
553   }
554   mb = msgq_make(0, "%:#C " MSG_WALLOPS " :%s%v", from, prefix,&vd);
555   va_end(vd.vd_args);
556
557   /* send buffer along! */
558   for (i = 0; i <= HighestFd; i++)
559   {
560     if (!(cptr = LocalClientArray[i]) ||
561         (cli_fd(cli_from(cptr)) < 0) ||
562         (type == WALL_DESYNCH && !HasFlag(cptr, FLAG_DEBUG)) ||
563         (type == WALL_WALLOPS &&
564          (!HasFlag(cptr, FLAG_WALLOP) || (feature_bool(FEAT_HIS_WALLOPS) &&
565                                           !IsAnOper(cptr)))) ||
566         (type == WALL_WALLUSERS && !HasFlag(cptr, FLAG_WALLOP)))
567       continue; /* skip it */
568     send_buffer(cptr, mb, 1);
569   }
570
571   msgq_clean(mb);
572
573   /* Build buffer to send to servers */
574   va_start(vd.vd_args, pattern);
575   mb = msgq_make(&me, "%C %s :%v", from, tok, &vd);
576   va_end(vd.vd_args);
577
578   /* send buffer along! */
579   for (lp = cli_serv(&me)->down; lp; lp = lp->next) {
580     if (one && lp->value.cptr == cli_from(one))
581       continue;
582     send_buffer(lp->value.cptr, mb, 1);
583   }
584
585   msgq_clean(mb);
586 }
587
588 /*
589  * Send a (prefixed) command to all users who match <to>, under control
590  * of <who>
591  */
592 /* XXX sentalong_marker used XXX
593  *
594  * This is also a difficult one to solve.  The basic approach would be
595  * to walk the client list of each connected server until we find a
596  * match--but then, we also have to walk the client list of all the
597  * servers behind that one.  We could implement this recursively--or we
598  * could add (yet another) field to the connection struct that would be
599  * a linked list of clients introduced through that link, and just walk
600  * that, making this into an iterative implementation.  Unfortunately,
601  * we probably would not be able to use tail recursion for the recursive
602  * solution, so a deep network could exhaust our stack space; therefore
603  * I favor the extra linked list, even though that increases the
604  * complexity of the database. -Kev
605  */
606 void sendcmdto_match_butone(struct Client *from, const char *cmd,
607                             const char *tok, const char *to,
608                             struct Client *one, unsigned int who,
609                             const char *pattern, ...)
610 {
611   struct VarData vd;
612   struct Client *cptr;
613   struct MsgBuf *user_mb;
614   struct MsgBuf *serv_mb;
615
616   vd.vd_format = pattern;
617
618   /* Build buffer to send to users */
619   va_start(vd.vd_args, pattern);
620   user_mb = msgq_make(0, "%:#C %s %v", from, cmd, &vd);
621   va_end(vd.vd_args);
622
623   /* Build buffer to send to servers */
624   va_start(vd.vd_args, pattern);
625   serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd);
626   va_end(vd.vd_args);
627
628   /* send buffer along */
629   sentalong_marker++;
630   for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) {
631     if (!IsRegistered(cptr) || cli_from(cptr) == one || IsServer(cptr) ||
632         IsMe(cptr) || !match_it(from, cptr, to, who) || cli_fd(cli_from(cptr)) < 0 ||
633         sentalong[cli_fd(cli_from(cptr))] == sentalong_marker)
634       continue; /* skip it */
635     sentalong[cli_fd(cli_from(cptr))] = sentalong_marker;
636
637     if (MyConnect(cptr)) /* send right buffer */
638       send_buffer(cptr, user_mb, 0);
639     else
640       send_buffer(cptr, serv_mb, 0);
641   }
642
643   msgq_clean(user_mb);
644   msgq_clean(serv_mb);
645 }
646
647 /*
648  * Send a server notice to all users subscribing to the indicated <mask>
649  * except for <one>
650  */
651 void sendto_opmask_butone(struct Client *one, unsigned int mask,
652                           const char *pattern, ...)
653 {
654   va_list vl;
655
656   va_start(vl, pattern);
657   vsendto_opmask_butone(one, mask, pattern, vl);
658   va_end(vl);
659 }
660
661 /*
662  * Send a server notice to all users subscribing to the indicated <mask>
663  * except for <one> - Ratelimited 1 / 30sec
664  */
665 void sendto_opmask_butone_ratelimited(struct Client *one, unsigned int mask,
666                                       time_t *rate, const char *pattern, ...)
667 {
668   va_list vl;
669
670   if ((CurrentTime - *rate) < 30) 
671     return;
672   else 
673     *rate = CurrentTime;
674
675   va_start(vl, pattern);
676   vsendto_opmask_butone(one, mask, pattern, vl);
677   va_end(vl);
678     
679 }
680
681
682 /*
683  * Same as above, except called with a variable argument list
684  */
685 void vsendto_opmask_butone(struct Client *one, unsigned int mask,
686                            const char *pattern, va_list vl)
687 {
688   struct VarData vd;
689   struct MsgBuf *mb;
690   int i = 0; /* so that 1 points to opsarray[0] */
691   struct SLink *opslist;
692
693   while ((mask >>= 1))
694     i++;
695
696   if (!(opslist = opsarray[i]))
697     return;
698
699   /*
700    * build string; I don't want to bother with client nicknames, so I hope
701    * this is ok...
702    */
703   vd.vd_format = pattern;
704   vd.vd_args = vl;
705   mb = msgq_make(0, ":%s " MSG_NOTICE " * :*** Notice -- %v", cli_name(&me),
706                  &vd);
707
708   for (; opslist; opslist = opslist->next)
709     if (opslist->value.cptr != one)
710       send_buffer(opslist->value.cptr, mb, 0);
711
712   msgq_clean(mb);
713 }