ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/user.c (file contents):
Revision 5562 by michael, Sat Feb 14 20:03:35 2015 UTC vs.
Revision 7049 by michael, Sun Jan 10 12:41:01 2016 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2015 ircd-hybrid development team
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
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
# Line 19 | Line 19
19   *  USA
20   */
21  
22 < /*! \file s_user.c
22 > /*! \file user.c
23   * \brief User related functions.
24   * \version $Id$
25   */
# Line 31 | Line 31
31   #include "channel_mode.h"
32   #include "client.h"
33   #include "hash.h"
34 + #include "id.h"
35   #include "irc_string.h"
36   #include "ircd.h"
37   #include "listener.h"
# Line 47 | Line 48
48   #include "misc.h"
49   #include "parse.h"
50   #include "watch.h"
51 + #include "isupport.h"
52  
53   static char umode_buffer[IRCD_BUFSIZE];
52 static const char *uid_get(void);
53
54 /* Used for building up the isupport string,
55 * used with init_isupport, add_isupport, delete_isupport
56 */
57 struct Isupport
58 {
59  dlink_node node;
60  char *name;
61  char *options;
62  int number;
63 };
64
65 static dlink_list support_list;
66 static dlink_list support_list_lines;
54  
55   const struct user_modes *umode_map[256];
56   const struct user_modes  umode_tab[] =
# Line 100 | Line 87 | const struct user_modes  umode_tab[] =
87   };
88  
89   void
90 < user_usermodes_init(void)
90 > user_modes_init(void)
91   {
92    char *umode_buffer_ptr = umode_buffer;
93  
# Line 162 | Line 149 | show_lusers(struct Client *source_p)
149      Count.max_loc_con = Count.local + Count.myserver;
150   }
151  
165 /* show_isupport()
166 *
167 * inputs       - pointer to client
168 * output       - NONE
169 * side effects - display to client what we support (for them)
170 */
171 void
172 show_isupport(struct Client *source_p)
173 {
174  const dlink_node *node = NULL;
175
176  DLINK_FOREACH(node, support_list_lines.head)
177    sendto_one_numeric(source_p, &me, RPL_ISUPPORT, node->data);
178 }
179
180
152   /* report_and_set_user_flags()
153   *
154   * inputs       - pointer to source_p
# Line 191 | Line 162 | report_and_set_user_flags(struct Client
162   {
163    /* If this user is being spoofed, tell them so */
164    if (IsConfDoSpoofIp(conf))
165 <    sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
165 >    sendto_one_notice(source_p, &me, ":*** Spoofing your IP");
166  
167    /* If this user is in the exception class, set it "E lined" */
168    if (IsConfExemptKline(conf))
169    {
170 <    SetExemptKline(source_p);
171 <    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
170 >    AddFlag(source_p, FLAGS_EXEMPTKLINE);
171 >    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines");
172    }
173  
174 <  /*
204 <   * The else here is to make sure that G line exempt users
205 <   * do not get noticed twice.
206 <   */
207 <  else if (IsConfExemptGline(conf))
174 >  if (IsConfExemptXline(conf))
175    {
176 <    SetExemptGline(source_p);
177 <    sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
176 >    AddFlag(source_p, FLAGS_EXEMPTXLINE);
177 >    sendto_one_notice(source_p, &me, ":*** You are exempt from X lines");
178    }
179  
180    if (IsConfExemptResv(conf))
181    {
182 <    SetExemptResv(source_p);
183 <    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
182 >    AddFlag(source_p, FLAGS_EXEMPTRESV);
183 >    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs");
184    }
185  
186    /* If this user is exempt from user limits set it "F lined" */
187    if (IsConfExemptLimits(conf))
188    {
189 <    SetExemptLimits(source_p);
190 <    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
189 >    AddFlag(source_p, FLAGS_NOLIMIT);
190 >    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits");
191    }
192  
193    if (IsConfCanFlood(conf))
194    {
195 <    SetCanFlood(source_p);
196 <    sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
230 <                      "protection, aren't you fearsome.");
195 >    AddFlag(source_p, FLAGS_CANFLOOD);
196 >    sendto_one_notice(source_p, &me, ":*** You are exempt from flood protection");
197    }
198   }
199  
# Line 245 | Line 211 | introduce_client(struct Client *source_p
211    dlink_node *node = NULL;
212    char ubuf[IRCD_BUFSIZE] = "";
213  
214 <  if (MyClient(source_p))
214 >  if (MyConnect(source_p))
215      send_umode(source_p, source_p, 0, ubuf);
216    else
217      send_umode(NULL, source_p, 0, ubuf);
# Line 265 | Line 231 | introduce_client(struct Client *source_p
231      if (server == source_p->from)
232        continue;
233  
234 <    if (IsCapable(server, CAP_SVS))
235 <      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
236 <                 source_p->servptr->id,
237 <                 source_p->name, source_p->hopcount+1,
238 <                 (unsigned long)source_p->tsinfo,
239 <                 ubuf, source_p->username, source_p->host,
240 <                 source_p->sockhost, source_p->id,
241 <                 source_p->account,
276 <                 source_p->info);
277 <    else
278 <      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
279 <                 source_p->servptr->id,
280 <                 source_p->name, source_p->hopcount+1,
281 <                 (unsigned long)source_p->tsinfo,
282 <                 ubuf, source_p->username, source_p->host,
283 <                 source_p->sockhost, source_p->id, source_p->info);
234 >    sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s :%s",
235 >               source_p->servptr->id,
236 >               source_p->name, source_p->hopcount+1,
237 >               source_p->tsinfo,
238 >               ubuf, source_p->username, source_p->host,
239 >               source_p->sockhost, source_p->id,
240 >               source_p->account,
241 >               source_p->info);
242  
243      if (!EmptyString(source_p->certfp))
244        sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
# Line 296 | Line 254 | introduce_client(struct Client *source_p
254   static void
255   user_welcome(struct Client *source_p)
256   {
299 #if defined(__TIME__) && defined(__DATE__)
257    static const char built_date[] = __DATE__ " at " __TIME__;
301 #else
302  static const char built_date[] = "unknown";
303 #endif
258  
259   #ifdef HAVE_LIBCRYPTO
260    if (HasFlag(source_p, FLAGS_SSL))
# Line 314 | Line 268 | user_welcome(struct Client *source_p)
268    sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
269                       source_p->name);
270    sendto_one_numeric(source_p, &me, RPL_YOURHOST,
271 <                     get_listener_name(source_p->connection->listener), ircd_version);
271 >                     listener_get_name(source_p->connection->listener), ircd_version);
272    sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
273    sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
320  show_isupport(source_p);
321  sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
274  
275 +  isupport_show(source_p);
276    show_lusers(source_p);
277    motd_signon(source_p);
278   }
# Line 335 | Line 288 | check_xline(struct Client *source_p)
288   {
289    struct MaskItem *conf = NULL;
290  
291 +  if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
292 +    return 0;
293 +
294    if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
295    {
296      ++conf->count;
# Line 365 | Line 321 | register_local_user(struct Client *sourc
321  
322    assert(source_p == source_p->from);
323    assert(MyConnect(source_p));
324 +  assert(IsUnknown(source_p));
325    assert(!source_p->connection->registration);
326  
327    if (ConfigGeneral.ping_cookie)
328    {
329 <    if (!IsPingSent(source_p) && !source_p->connection->random_ping)
329 >    if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
330      {
331        do
332          source_p->connection->random_ping = genrand_int32();
333        while (!source_p->connection->random_ping);
334  
335        sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
336 <      SetPingSent(source_p);
336 >      AddFlag(source_p, FLAGS_PINGSENT);
337        return;
338      }
339  
340 <    if (!HasPingCookie(source_p))
340 >    if (!HasFlag(source_p, FLAGS_PING_COOKIE))
341        return;
342    }
343  
# Line 400 | Line 357 | register_local_user(struct Client *sourc
357  
358    conf = source_p->connection->confs.head->data;
359  
360 <  if (!IsGotId(source_p))
360 >  if (!HasFlag(source_p, FLAGS_GOTID))
361    {
362      char username[USERLEN + 1] = "";
406    const char *p = username;
363      unsigned int i = 0;
364  
365      if (IsNeedIdentd(conf))
# Line 420 | Line 376 | register_local_user(struct Client *sourc
376      if (!IsNoTilde(conf))
377        source_p->username[i++] = '~';
378  
379 <    for (; *p && i < USERLEN; ++p)
379 >    for (const char *p = username; *p && i < USERLEN; ++p)
380        source_p->username[i++] = *p;
381  
382      source_p->username[i] = '\0';
# Line 462 | Line 418 | register_local_user(struct Client *sourc
418     *   -Taner
419     */
420    if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
421 <      (Count.local >= GlobalSetOptions.maxclients && !IsExemptLimits(source_p)))
421 >      (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
422    {
423      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
424                           "Too many clients, rejecting %s[%s].",
# Line 512 | Line 468 | register_local_user(struct Client *sourc
468      Count.max_loc = Count.local;
469  
470      if (!(Count.max_loc % 10))
471 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
471 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
472                             "New maximum local client connections: %u",
473                             Count.max_loc);
474    }
# Line 532 | Line 488 | register_local_user(struct Client *sourc
488                    &unknown_list, &local_client_list);
489  
490    user_welcome(source_p);
491 <  add_user_host(source_p->username, source_p->host, 0);
492 <  SetUserHost(source_p);
491 >  userhost_add(source_p->username, source_p->host, 0);
492 >  AddFlag(source_p, FLAGS_USERHOST);
493  
494    introduce_client(source_p);
495   }
# Line 583 | Line 539 | register_remote_user(struct Client *sour
539    SetClient(source_p);
540    dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
541    dlinkAdd(source_p, &source_p->node, &global_client_list);
542 <  add_user_host(source_p->username, source_p->host, 1);
543 <  SetUserHost(source_p);
542 >  userhost_add(source_p->username, source_p->host, 1);
543 >  AddFlag(source_p, FLAGS_USERHOST);
544  
545    if (HasFlag(source_p->servptr, FLAGS_EOB))
546 <  {
547 <    if (strcmp(source_p->sockhost, "0")) /* XXX: TBR */
548 <      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
549 <                           "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
550 <                           source_p->servptr->name,
595 <                           source_p->name, source_p->username, source_p->host,
596 <                           source_p->sockhost, source_p->info, source_p->id);
597 <    else
598 <      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
599 <                           "Client connecting at %s: %s (%s@%s) [%s] <%s>",
600 <                           source_p->servptr->name,
601 <                           source_p->name, source_p->username, source_p->host,
602 <                           source_p->info, source_p->id);
603 <  }
546 >    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
547 >                         "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
548 >                         source_p->servptr->name,
549 >                         source_p->name, source_p->username, source_p->host,
550 >                         source_p->sockhost, source_p->info, source_p->id);
551  
552    introduce_client(source_p);
553   }
# Line 645 | Line 592 | valid_hostname(const char *hostname)
592   int
593   valid_username(const char *username, const int local)
594   {
648  unsigned int dots = 0;
595    const char *p = username;
596  
597    assert(p);
# Line 663 | Line 609 | valid_username(const char *username, con
609  
610    if (local)
611    {
612 +    unsigned int dots = 0;
613 +
614      while (*++p)
615      {
616        if (*p == '.' && ConfigGeneral.dots_in_ident)
# Line 720 | Line 668 | valid_nickname(const char *nickname, con
668   * inputs       - client_p
669   *              - source_p
670   *              - int old
723 *              - sendmask mask of modes to send
671   *              - suplied umode_buf
672   * output       - NONE
673   */
# Line 807 | Line 754 | user_set_hostmask(struct Client *target_
754    }
755  
756    if (ConfigGeneral.cycle_on_host_change)
757 <    sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
757 >    sendto_common_channels_local(target_p, 0, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname",
758                                   target_p->name, target_p->username, target_p->host);
759  
760 <  if (IsUserHostIp(target_p))
761 <    delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
760 >  sendto_common_channels_local(target_p, 0, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s",
761 >                               target_p->name, target_p->username,
762 >                               target_p->host, target_p->username, hostname);
763 >
764 >  if (HasFlag(target_p, FLAGS_USERHOST))
765 >    userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
766  
767    strlcpy(target_p->host, hostname, sizeof(target_p->host));
768  
769 <  add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
770 <  SetUserHost(target_p);
769 >  userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
770 >  AddFlag(target_p, FLAGS_USERHOST);
771  
772 <  if (MyClient(target_p))
772 >  if (MyConnect(target_p))
773    {
774      sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host);
775      clear_ban_cache_client(target_p);
# Line 829 | Line 780 | user_set_hostmask(struct Client *target_
780  
781    DLINK_FOREACH(node, target_p->channel.head)
782    {
783 <    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
783 >    char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1];
784 >    char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = "";
785      char *p = modebuf;
786      int len = 0;
787      const struct Membership *member = node->data;
# Line 854 | Line 806 | user_set_hostmask(struct Client *target_
806  
807      *p = '\0';
808  
809 <
810 <    sendto_channel_local_butone(target_p, CAP_EXTENDED_JOIN, 0, member->chptr, ":%s!%s@%s JOIN %s %s :%s",
811 <                                target_p->name, target_p->username,
812 <                                target_p->host, member->chptr->name,
813 <                                (!IsDigit(target_p->account[0]) && target_p->account[0] != '*') ? target_p->account : "*",
814 <                                target_p->info);
815 <    sendto_channel_local_butone(target_p, 0, CAP_EXTENDED_JOIN, member->chptr, ":%s!%s@%s JOIN :%s",
864 <                                target_p->name, target_p->username,
865 <                                target_p->host, member->chptr->name);
809 >    sendto_channel_local(target_p, member->chptr, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s",
810 >                         target_p->name, target_p->username,
811 >                         target_p->host, member->chptr->name,
812 >                         target_p->account, target_p->info);
813 >    sendto_channel_local(target_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s",
814 >                         target_p->name, target_p->username,
815 >                         target_p->host, member->chptr->name);
816  
817      if (nickbuf[0])
818 <      sendto_channel_local_butone(target_p, 0, 0, member->chptr, ":%s MODE %s +%s %s",
819 <                                  target_p->servptr->name, member->chptr->name,
820 <                                  modebuf, nickbuf);
871 <
818 >      sendto_channel_local(target_p, member->chptr, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s",
819 >                           target_p->servptr->name, member->chptr->name,
820 >                           modebuf, nickbuf);
821    }
822  
823    if (target_p->away[0])
824 <    sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY,
824 >    sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY, CAP_CHGHOST,
825                                   ":%s!%s@%s AWAY :%s",
826                                   target_p->name, target_p->username,
827                                   target_p->host, target_p->away);
828   }
880
881 /*! \brief Blindly opers up given source_p, using conf info.
882 *         All checks on passwords have already been done.
883 * \param source_p Pointer to given client to oper
884 */
885 void
886 oper_up(struct Client *source_p)
887 {
888  const unsigned int old = source_p->umodes;
889  const struct MaskItem *const conf = source_p->connection->confs.head->data;
890
891  assert(source_p->connection->confs.head);
892
893  ++Count.oper;
894  SetOper(source_p);
895
896  if (conf->modes)
897    AddUMode(source_p, conf->modes);
898  else if (ConfigGeneral.oper_umodes)
899    AddUMode(source_p, ConfigGeneral.oper_umodes);
900
901  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
902    ++Count.invisi;
903  if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
904    --Count.invisi;
905
906  assert(dlinkFind(&oper_list, source_p) == NULL);
907  dlinkAdd(source_p, make_dlink_node(), &oper_list);
908
909  AddOFlag(source_p, conf->port);
910
911  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
912    AddUMode(source_p, UMODE_ADMIN);
913
914  if (!EmptyString(conf->whois))
915  {
916    client_attach_svstag(source_p, RPL_WHOISOPERATOR, "+", conf->whois);
917    sendto_server(source_p, 0, 0, ":%s SVSTAG %s %lu %u + :%s",
918                  me.id, source_p->id, (unsigned long)source_p->tsinfo,
919                  RPL_WHOISOPERATOR, conf->whois);
920  }
921
922  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
923                       get_oper_name(source_p));
924  sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
925                me.id, get_oper_name(source_p));
926  send_umode_out(source_p, old);
927  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
928 }
929
930 static char new_uid[TOTALSIDUID + 1];  /* Allow for \0 */
931
932 int
933 valid_sid(const char *sid)
934 {
935  if (strlen(sid) == IRC_MAXSID)
936    if (IsDigit(*sid))
937      if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
938        return 1;
939
940  return 0;
941 }
942
943 /*
944 * init_uid()
945 *
946 * inputs       - NONE
947 * output       - NONE
948 * side effects - new_uid is filled in with server id portion (sid)
949 *                (first 3 bytes) or defaulted to 'A'.
950 *                Rest is filled in with 'A'
951 */
952 void
953 init_uid(void)
954 {
955  memset(new_uid, 0, sizeof(new_uid));
956
957  if (!EmptyString(ConfigServerInfo.sid))
958    strlcpy(new_uid, ConfigServerInfo.sid, sizeof(new_uid));
959
960  for (unsigned int i = 0; i < IRC_MAXSID; ++i)
961    if (new_uid[i] == '\0')
962      new_uid[i] = 'A';
963
964  /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
965  memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
966 }
967
968 /*
969 * add_one_to_uid
970 *
971 * inputs       - index number into new_uid
972 * output       - NONE
973 * side effects - new_uid is incremented by one
974 *                note this is a recursive function
975 */
976 static void
977 add_one_to_uid(unsigned int i)
978 {
979  if (i != IRC_MAXSID)  /* Not reached server SID portion yet? */
980  {
981    if (new_uid[i] == 'Z')
982      new_uid[i] = '0';
983    else if (new_uid[i] == '9')
984    {
985      new_uid[i] = 'A';
986      add_one_to_uid(i - 1);
987    }
988    else
989      ++new_uid[i];
990  }
991  else
992  {
993    /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
994    if (new_uid[i] == 'Z')
995      memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
996    else
997      ++new_uid[i];
998  }
999 }
1000
1001 /*
1002 * uid_get
1003 *
1004 * inputs       - struct Client *
1005 * output       - new UID is returned to caller
1006 * side effects - new_uid is incremented by one.
1007 */
1008 static const char *
1009 uid_get(void)
1010 {
1011  add_one_to_uid(TOTALSIDUID - 1);  /* Index from 0 */
1012  return new_uid;
1013 }
1014
1015 /*
1016 * init_isupport()
1017 *
1018 * input        - NONE
1019 * output       - NONE
1020 * side effects - Must be called before isupport is enabled
1021 */
1022 void
1023 init_isupport(void)
1024 {
1025  add_isupport("CALLERID", NULL, -1);
1026  add_isupport("CASEMAPPING", "rfc1459", -1);
1027  add_isupport("DEAF", "D", -1);
1028  add_isupport("KICKLEN", NULL, KICKLEN);
1029  add_isupport("MODES", NULL, MAXMODEPARAMS);
1030  add_isupport("PREFIX", "(ohv)@%+", -1);
1031  add_isupport("STATUSMSG", "@%+", -1);
1032  add_isupport("EXCEPTS", NULL, -1);
1033  add_isupport("INVEX", NULL, -1);
1034 }
1035
1036 /*
1037 * add_isupport()
1038 *
1039 * input        - name of supported function
1040 *              - options if any
1041 *              - number if any
1042 * output       - NONE
1043 * side effects - Each supported item must call this when activated
1044 */
1045 void
1046 add_isupport(const char *name, const char *options, int n)
1047 {
1048  dlink_node *node = NULL;
1049  struct Isupport *support = NULL;
1050
1051  DLINK_FOREACH(node, support_list.head)
1052  {
1053    support = node->data;
1054    if (irccmp(support->name, name) == 0)
1055    {
1056      MyFree(support->name);
1057      MyFree(support->options);
1058      break;
1059    }
1060  }
1061
1062  if (node == NULL)
1063  {
1064    support = MyCalloc(sizeof(*support));
1065    dlinkAddTail(support, &support->node, &support_list);
1066  }
1067
1068  support->name = xstrdup(name);
1069  if (options)
1070    support->options = xstrdup(options);
1071  support->number = n;
1072
1073  rebuild_isupport_message_line();
1074 }
1075
1076 /*
1077 * delete_isupport()
1078 *
1079 * input        - name of supported function
1080 * output       - NONE
1081 * side effects - Each supported item must call this when deactivated
1082 */
1083 void
1084 delete_isupport(const char *name)
1085 {
1086  dlink_node *node = NULL;
1087
1088  DLINK_FOREACH(node, support_list.head)
1089  {
1090    struct Isupport *support = node->data;
1091
1092    if (irccmp(support->name, name) == 0)
1093    {
1094      dlinkDelete(node, &support_list);
1095      MyFree(support->name);
1096      MyFree(support->options);
1097      MyFree(support);
1098      break;
1099    }
1100  }
1101
1102  rebuild_isupport_message_line();
1103 }
1104
1105 /*
1106 * rebuild_isupport_message_line
1107 *
1108 * input        - NONE
1109 * output       - NONE
1110 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1111 */
1112 void
1113 rebuild_isupport_message_line(void)
1114 {
1115  char isupportbuffer[IRCD_BUFSIZE];
1116  char *p = isupportbuffer;
1117  dlink_node *node = NULL, *node_next = NULL;
1118  int n = 0;
1119  int tokens = 0;
1120  size_t len = 0;
1121  size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1122
1123  DLINK_FOREACH_SAFE(node, node_next, support_list_lines.head)
1124  {
1125    dlinkDelete(node, &support_list_lines);
1126    MyFree(node->data);
1127    free_dlink_node(node);
1128  }
1129
1130  DLINK_FOREACH(node, support_list.head)
1131  {
1132    struct Isupport *support = node->data;
1133
1134    p += (n = sprintf(p, "%s", support->name));
1135    len += n;
1136
1137    if (support->options)
1138    {
1139      p += (n = sprintf(p, "=%s", support->options));
1140      len += n;
1141    }
1142
1143    if (support->number > 0)
1144    {
1145      p += (n = sprintf(p, "=%d", support->number));
1146      len += n;
1147    }
1148
1149    *p++ = ' ';
1150    len++;
1151    *p = '\0';
1152
1153    if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1154    { /* arbritrary for now */
1155      if (*--p == ' ')
1156        *p = '\0';
1157
1158      dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1159      p = isupportbuffer;
1160      len = 0;
1161      n = tokens = 0;
1162    }
1163  }
1164
1165  if (len)
1166  {
1167    if (*--p == ' ')
1168      *p = '\0';
1169    dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1170  }
1171 }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)