Move special line-handling to src/
authorJelmer Vernooij <jelmer@samba.org>
Wed, 8 Apr 2009 20:42:01 +0000 (22:42 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 8 Apr 2009 20:42:01 +0000 (22:42 +0200)
1  2 
libirc/connection.c
libirc/connection.h
src/network.c

index f22567002884af0b7d77a9f8802ab147e082528a,df2e3fb10c8e596db41e4240925a4e39cc00d26c..c2e641848b2ac268f592332102ff8c290d480959
@@@ -212,49 -211,30 +212,29 @@@ static gboolean network_send_line_direc
  /**
   * Send a line to the network.
   * @param s Network to send to.
 + * @param c Client the line was sent by originally.
   * @param ol Line to send to the network
-  * @param is_private Whether the line should not be broadcast to other clients
   */
 -gboolean network_send_line(struct irc_network *s, const struct irc_line *ol)
 +gboolean network_send_line(struct irc_network *s, struct irc_client *c, 
-                                                  const struct irc_line *ol, gboolean is_private)
++                                                 const struct irc_line *ol)
  {
        struct irc_line l;
--      char *tmp = NULL;
  
        g_assert(ol);
        g_assert(s);
        l = *ol;
  
        if (l.origin == NULL && s->external_state != NULL) {
--              tmp = l.origin = g_strdup(s->external_state->me.hostmask);
++              l.origin = s->external_state->me.hostmask;
        }
  
        if (l.origin != NULL) {
                if (!s->callbacks->process_to_server(s, &l)) {
--                      g_free(tmp);
                        return TRUE;
                }
 -              g_free(tmp);
        }
  
-       g_assert(l.args[0] != NULL);
-       /* Also write this message to all other clients currently connected */
-       if (!is_private && 
-          (!g_strcasecmp(l.args[0], "PRIVMSG") || 
-               !g_strcasecmp(l.args[0], "NOTICE"))) {
-               g_assert(l.origin);
-               if (s->global->config->report_time == REPORT_TIME_ALWAYS)
-                       line_prefix_time(&l, time(NULL)+s->global->config->report_time_offset);
-               clients_send(s->clients, &l, c);
-       }
-       g_free(tmp);
-       redirect_record(&s->queries, s, c, ol);
 -      return network_send_line_direct(s, ol);
 +      return network_send_line_direct(s, c, ol);
  }
  
  /**
@@@ -360,7 -340,7 +340,7 @@@ gboolean network_send_args(struct irc_n
        l = virc_parse_line(NULL, ap);
        va_end(ap);
  
-       ret = network_send_line(s, NULL, l, TRUE);
 -      ret = network_send_line(s, l);
++      ret = network_send_line(s, NULL, l);
  
        free_line(l);
  
index 850095f9576869bd9def1f844063d2aae030bbfe,0384854469371b662adff99cd599c62216e4639c..a717db4eaae1da7425f7d9c59ee5ae8fd413b5f4
@@@ -158,7 -158,7 +158,7 @@@ G_MODULE_EXPORT struct irc_network *irc
  G_MODULE_EXPORT gboolean connect_network(struct irc_network *);
  G_MODULE_EXPORT void irc_network_select_next_server(struct irc_network *n);
  G_MODULE_EXPORT gboolean disconnect_network(struct irc_network *s);
- G_MODULE_EXPORT gboolean network_send_line(struct irc_network *s, struct irc_client *c, const struct irc_line *, gboolean);
 -G_MODULE_EXPORT gboolean network_send_line(struct irc_network *s, const struct irc_line *);
++G_MODULE_EXPORT gboolean network_send_line(struct irc_network *s, struct irc_client *c, const struct irc_line *);
  G_MODULE_EXPORT gboolean network_send_args(struct irc_network *s, ...);
  G_MODULE_EXPORT void register_virtual_network(struct virtual_network_ops *);
  G_MODULE_EXPORT struct virtual_network_ops *find_virtual_network(const char *name);
diff --cc src/network.c
index 7e089ed9c19d921d9389b9e65dc797a095d38763,1c942ca49687732a9052c8272febdff98b95ef93..36b2b7a4495961e130f81fa497d88e80976c5a87
@@@ -167,7 -167,7 +167,7 @@@ static gboolean process_from_server(str
  
                for (i = 0; nc->autocmd && nc->autocmd[i]; i++) {
                        struct irc_line *l = irc_parse_line(nc->autocmd[i]);
-                       network_send_line(n, NULL, l, FALSE);
 -                      network_send_line(n, l);
++                      network_send_line(n, NULL, l);
                        free_line(l);
                }
  
@@@ -528,9 -527,21 +527,24 @@@ void fini_networks(struct global *globa
   * @param c Client that originally sent the line
   * @param is_private Whether the line should not be broadcast to other clients
   */
--gboolean network_forward_line(struct irc_network *s, struct irc_client *c, const struct irc_line *l, 
--                                                        gboolean is_private)
++gboolean network_forward_line(struct irc_network *s, struct irc_client *c, 
++                                                        const struct irc_line *l, gboolean is_private)
  {
-       return network_send_line(s, c, l, is_private);
- }
+       /* Also write this message to all other clients currently connected */
+       if (!is_private && 
+          (!g_strcasecmp(l->args[0], "PRIVMSG") || 
+               !g_strcasecmp(l->args[0], "NOTICE"))) {
 -              g_assert(l->origin != NULL);
++              struct irc_line *nl = linedup(l);
++              g_free(nl->origin); 
++              nl->origin = g_strdup(s->external_state->me.hostmask);
+               if (s->global->config->report_time == REPORT_TIME_ALWAYS)
 -                      line_prefix_time(l, time(NULL)+s->global->config->report_time_offset);
++                      line_prefix_time(nl, time(NULL)+s->global->config->report_time_offset);
 -              clients_send(s->clients, l, c);
++              clients_send(s->clients, nl, c);
++              free_line(nl);
+       }
  
 -      return network_send_line(s, l);
+       redirect_record(&s->queries, s, c, l);
++      return network_send_line(s, NULL, l);
+ }