Просмотр исходного кода

* Async dns now works for server connects
-Need to elimante dcc[].addr nad user dcc[].addru and inet_pton for cmd_dccstat


svn: 1435

Bryan Drewery 21 лет назад
Родитель
Сommit
667125ad15
10 измененных файлов с 114 добавлено и 26 удалено
  1. 1 1
      src/adns.h
  2. 2 2
      src/cmds.c
  3. 5 5
      src/dcc.c
  4. 5 3
      src/dcc.h
  5. 1 1
      src/dccutil.c
  6. 6 4
      src/mod/server.mod/server.c
  7. 68 10
      src/mod/server.mod/servmsg.c
  8. 17 0
      src/socket.c
  9. 1 0
      src/socket.h
  10. 8 0
      src/types.h

+ 1 - 1
src/adns.h

@@ -7,7 +7,7 @@
 
 
 #define DNS_PORT 53
 #define DNS_PORT 53
 
 
-typedef int (*dns_callback_t)(void *client_data, const char *query, char **result);
+typedef void (*dns_callback_t)(void *client_data, const char *query, char **result);
 
 
 int egg_dns_init(void);
 int egg_dns_init(void);
 //int egg_dns_shutdown(void);
 //int egg_dns_shutdown(void);

+ 2 - 2
src/cmds.c

@@ -3915,7 +3915,7 @@ static void cmd_crontab(int idx, char *par) {
 }
 }
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
 
 
-static int my_dns_callback(void *client_data, const char *host, char **ips)
+static void my_dns_callback(void *client_data, const char *host, char **ips)
 {
 {
   int idx = (int) client_data;
   int idx = (int) client_data;
 if (ips)
 if (ips)
@@ -3926,7 +3926,7 @@ sdprintf("CALLBACK WITH IDX: %d and ip[0]: %s (msgc: %d)", idx, ips[0], dcc[idx]
   else
   else
     dprintf(idx, "Failed to lookup via (%s): %s\n", dns_ip, host);
     dprintf(idx, "Failed to lookup via (%s): %s\n", dns_ip, host);
 
 
-  return 0;
+  return;
 }
 }
 
 
 static void cmd_dns(int idx, char *par)
 static void cmd_dns(int idx, char *par)

+ 5 - 5
src/dcc.c

@@ -485,7 +485,7 @@ display_dcc_bot(int idx, char *buf)
   buf[i++] = b_status(idx) & STAT_SENDINGU ? 'D' : 'd';
   buf[i++] = b_status(idx) & STAT_SENDINGU ? 'D' : 'd';
   buf[i++] = b_status(idx) & STAT_GETTINGU ? 'E' : 'e';
   buf[i++] = b_status(idx) & STAT_GETTINGU ? 'E' : 'e';
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-  if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].addr6[0])
+  if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].host6[0])
     buf[i++] = '6';
     buf[i++] = '6';
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   buf[i++] = 0;
   buf[i++] = 0;
@@ -1133,7 +1133,7 @@ display_dcc_chat(int idx, char *buf)
   if ((colori = coloridx(idx)))
   if ((colori = coloridx(idx)))
     buf[i++] = colori == 1 ? 'A' : 'M';
     buf[i++] = colori == 1 ? 'A' : 'M';
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-  if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].addr6[0])
+  if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].host6[0])
     buf[i++] = '6';
     buf[i++] = '6';
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   simple_sprintf(buf + i, "/%d", dcc[idx].u.chat->channel);
   simple_sprintf(buf + i, "/%d", dcc[idx].u.chat->channel);
@@ -1246,7 +1246,7 @@ dcc_telnet(int idx, char *buf, int ii)
   dcc[i].addr = ip;
   dcc[i].addr = ip;
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   if (sockprotocol(sock) == AF_INET6)
   if (sockprotocol(sock) == AF_INET6)
-    strcpy(dcc[i].addr6, s);
+    strcpy(dcc[i].host6, s);
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   dcc[i].port = port;
   dcc[i].port = port;
   dcc[i].timeval = now;
   dcc[i].timeval = now;
@@ -1273,8 +1273,8 @@ dcc_telnet_hostresolved(int i)
   char s2[UHOSTLEN + 20] = "";
   char s2[UHOSTLEN + 20] = "";
 
 
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-  if (sockprotocol(dcc[i].sock) == AF_INET6 && dcc[i].addr6[0])
-    strncpyz(dcc[i].host, dcc[i].addr6, UHOSTLEN);
+  if (sockprotocol(dcc[i].sock) == AF_INET6 && dcc[i].host6[0])
+    strncpyz(dcc[i].host, dcc[i].host6, UHOSTLEN);
   else
   else
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
     strncpyz(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);
     strncpyz(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);

+ 5 - 3
src/dcc.h

@@ -39,9 +39,11 @@ struct dcc_t {
     int ident_sock;
     int ident_sock;
     int dns_id;
     int dns_id;
     void *other;
     void *other;
+    char buf[101];
   } u;                          /* Special use depending on type        */
   } u;                          /* Special use depending on type        */
 
 
   in_addr_t addr;                      /* IP address in host byte order         */
   in_addr_t addr;                      /* IP address in host byte order         */
+  addr_t addru;
   time_t simultime;             /* the time when the simul dcc is initiated, expires after a number of seconds */
   time_t simultime;             /* the time when the simul dcc is initiated, expires after a number of seconds */
   time_t timeval;               /* Use for any timing stuff
   time_t timeval;               /* Use for any timing stuff
                                    - this is used for timeout checking  */
                                    - this is used for timeout checking  */
@@ -54,14 +56,14 @@ struct dcc_t {
   int msgc;			/* forward the output back to irc? */
   int msgc;			/* forward the output back to irc? */
   int whowas;
   int whowas;
   port_t port;
   port_t port;
-#ifdef USE_IPV6
-  char addr6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
-#endif /* USE_IPV6 */
   char simulbot[NICKLEN];       /* used for hub->leaf cmd simulation, holds bot that results should be sent to */
   char simulbot[NICKLEN];       /* used for hub->leaf cmd simulation, holds bot that results should be sent to */
   char hash[MD5_HASH_LENGTH + 1];                /* used for dcc authing */
   char hash[MD5_HASH_LENGTH + 1];                /* used for dcc authing */
   char nick[NICKLEN];
   char nick[NICKLEN];
   char whois[UHOSTLEN];
   char whois[UHOSTLEN];
   char host[UHOSTLEN];
   char host[UHOSTLEN];
+#ifdef USE_IPV6
+  char host6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
+#endif /* USE_IPV6 */
 };
 };
 
 
 
 

+ 1 - 1
src/dccutil.c

@@ -691,7 +691,7 @@ port_t listen_all(port_t lport, bool off)
       } else {
       } else {
         idx = new_dcc(&DCC_TELNET, 0);
         idx = new_dcc(&DCC_TELNET, 0);
         dcc[idx].addr = 0L;
         dcc[idx].addr = 0L;
-        strcpy(dcc[idx].addr6, myipstr(6));
+        strcpy(dcc[idx].host6, myipstr(6));
         dcc[idx].port = port;
         dcc[idx].port = port;
         dcc[idx].sock = i6;
         dcc[idx].sock = i6;
         dcc[idx].timeval = now;
         dcc[idx].timeval = now;

+ 6 - 4
src/mod/server.mod/server.c

@@ -20,6 +20,8 @@
 #include "src/net.h"
 #include "src/net.h"
 #include "src/auth.h"
 #include "src/auth.h"
 #include "src/dns.h"
 #include "src/dns.h"
+#include "src/adns.h"
+#include "src/socket.h"
 #include "src/egg_timer.h"
 #include "src/egg_timer.h"
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/irc.mod/irc.h"
 #include "src/mod/irc.mod/irc.h"
@@ -873,8 +875,8 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
 #ifdef USE_IPV6
 #ifdef USE_IPV6
     if (hostprotocol(ip) == AF_INET6 && sockprotocol(dcc[i].sock) == AF_INET6) {
     if (hostprotocol(ip) == AF_INET6 && sockprotocol(dcc[i].sock) == AF_INET6) {
       debug1("ipv6 addr: %s",ip);
       debug1("ipv6 addr: %s",ip);
-      strcpy(dcc[i].addr6,ip);
-      debug1("ipv6 addr: %s",dcc[i].addr6);
+      strcpy(dcc[i].host6,ip);
+      debug1("ipv6 addr: %s",dcc[i].host6);
     } else
     } else
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
       dcc[i].addr = my_atoul(ip);
       dcc[i].addr = my_atoul(ip);
@@ -911,14 +913,14 @@ static void dcc_chat_hostresolved(int i)
   egg_snprintf(buf, sizeof buf, "%d", dcc[i].port);
   egg_snprintf(buf, sizeof buf, "%d", dcc[i].port);
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   if (sockprotocol(dcc[i].sock) == AF_INET6) {
   if (sockprotocol(dcc[i].sock) == AF_INET6) {
-    strcpy(ip, dcc[i].addr6); /* safe, addr6 is 121 */
+    strcpy(ip, dcc[i].host6); /* safe, host6 is 121 */
   } else
   } else
 #endif /* !USE_IPV6 */
 #endif /* !USE_IPV6 */
   egg_snprintf(ip, sizeof ip, "%lu", iptolong(htonl(dcc[i].addr)));
   egg_snprintf(ip, sizeof ip, "%lu", iptolong(htonl(dcc[i].addr)));
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   if (sockprotocol(dcc[i].sock) == AF_INET6) {
   if (sockprotocol(dcc[i].sock) == AF_INET6) {
 #  ifdef IPV6_DEBUG
 #  ifdef IPV6_DEBUG
-    debug2("af_inet6 %s / %s", dcc[i].addr6, ip);
+    debug2("af_inet6 %s / %s", dcc[i].host6, ip);
 #  endif /* IPV6_DEBUG */
 #  endif /* IPV6_DEBUG */
     dcc[i].sock = getsock(0, AF_INET6);
     dcc[i].sock = getsock(0, AF_INET6);
   } else {
   } else {

+ 68 - 10
src/mod/server.mod/servmsg.c

@@ -1320,8 +1320,9 @@ static cmd_t my_raw_binds[] =
   {NULL,	NULL,	NULL,				NULL}
   {NULL,	NULL,	NULL,				NULL}
 };
 };
 
 
-static void server_resolve_success(int);
-static void server_resolve_failure(int);
+//static void server_resolve_success(int);
+//static void server_resolve_failure(int);
+static void server_dns_callback(void *, const char *, char **);
 
 
 /* Hook up to a server
 /* Hook up to a server
  */
  */
@@ -1352,7 +1353,7 @@ static void connect_server(void)
  
  
     trying_server = now;
     trying_server = now;
 
 
-    newidx = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
+    newidx = new_dcc(&SERVER_SOCKET, sizeof(struct dns_info));
     if (newidx < 0) {
     if (newidx < 0) {
       putlog(LOG_SERV, "*", "NO MORE DCC CONNECTIONS -- Can't create server connection.");
       putlog(LOG_SERV, "*", "NO MORE DCC CONNECTIONS -- Can't create server connection.");
       trying_server = 0;
       trying_server = 0;
@@ -1374,7 +1375,9 @@ static void connect_server(void)
 
 
     dcc[newidx].timeval = now;
     dcc[newidx].timeval = now;
     dcc[newidx].sock = -1;
     dcc[newidx].sock = -1;
-    dcc[newidx].u.dns->host = (char *) calloc(1, strlen(botserver) + 1);
+    strcpy(dcc[newidx].u.buf, pass);
+
+/*    dcc[newidx].u.dns->host = (char *) calloc(1, strlen(botserver) + 1);
     strcpy(dcc[newidx].u.dns->host, botserver);
     strcpy(dcc[newidx].u.dns->host, botserver);
     dcc[newidx].u.dns->cbuf = (char *) calloc(1, strlen(pass) + 1);
     dcc[newidx].u.dns->cbuf = (char *) calloc(1, strlen(pass) + 1);
     strcpy(dcc[newidx].u.dns->cbuf, pass);
     strcpy(dcc[newidx].u.dns->cbuf, pass);
@@ -1382,21 +1385,75 @@ static void connect_server(void)
     dcc[newidx].u.dns->dns_failure = server_resolve_failure;
     dcc[newidx].u.dns->dns_failure = server_resolve_failure;
     dcc[newidx].u.dns->dns_type = RES_IPBYHOST;
     dcc[newidx].u.dns->dns_type = RES_IPBYHOST;
     dcc[newidx].u.dns->type = &SERVER_SOCKET;
     dcc[newidx].u.dns->type = &SERVER_SOCKET;
-
+*/
 
 
     cycle_time = 15;		/* wait 15 seconds before attempting next server connect */
     cycle_time = 15;		/* wait 15 seconds before attempting next server connect */
 
 
     /* I'm resolving... don't start another server connect request */
     /* I'm resolving... don't start another server connect request */
     resolvserv = 1;
     resolvserv = 1;
     /* Resolve the hostname. */
     /* Resolve the hostname. */
-#ifdef USE_IPV6
-    server_resolve_success(newidx);
-#else
-    dcc_dnsipbyhost(botserver);
-#endif /* USE_IPV6 */
+    egg_dns_lookup(botserver, 20, server_dns_callback, (void *) newidx);
+    /* wait for async reply */
+  }
+}
+
+static void server_dns_callback(void *client_data, const char *host, char **ips)
+{
+  int idx = (int) client_data;
+
+  resolvserv = 0;
+
+  if (!ips) {
+    putlog(LOG_SERV, "*", "Failed connect to %s (DNS lookup failed)", host);
+    trying_server = 0;
+    lostdcc(idx);
+    return;
+  }
+
+  addr_t addr;
+
+  get_addr(ips[0], &addr);
+ 
+  if (addr.family == AF_INET)
+    dcc[idx].addr = htonl(addr.u.addr.s_addr);
+
+  strcpy(serverpass, dcc[idx].u.buf);
+//  changeover_dcc(idx, &SERVER_SOCKET, 0);
+  identd_open();
+
+  serv = open_telnet(ips[0], dcc[idx].port);
+
+
+//#ifdef USE_IPV6
+//  serv = open_telnet(dcc[idx].host, dcc[idx].port);
+//#else
+//  serv = open_telnet(iptostr(htonl(dcc[idx].addr)), dcc[idx].port);
+//#endif /* USE_IPV6 */
+
+  if (serv < 0) {
+    putlog(LOG_SERV, "*", "Failed connect to %s (%s)", dcc[idx].host, strerror(errno));
+    trying_server = 0;
+    lostdcc(idx);
+  } else {
+    int i = 1;
+
+    /* set these now so if we fail disconnect_server() can cleanup right. */
+    dcc[idx].sock = serv;
+    servidx = idx;
+    setsockopt(serv, 6, TCP_NODELAY, &i, sizeof(int));
+    /* Queue standard login */
+    dcc[idx].timeval = now;
+    SERVER_SOCKET.timeout_val = &server_timeout;
+    /* Another server may have truncated it, so use the original */
+    strcpy(botname, origbotname);
+    /* Start alternate nicks from the beginning */
+    altnick_char = 0;
+
+    /* Wait for async connect now */
   }
   }
 }
 }
 
 
+#ifdef NO
 static void server_resolve_failure(int idx)
 static void server_resolve_failure(int idx)
 {
 {
   putlog(LOG_SERV, "*", "Failed connect to %s (DNS lookup failed)", dcc[idx].host);
   putlog(LOG_SERV, "*", "Failed connect to %s (DNS lookup failed)", dcc[idx].host);
@@ -1439,4 +1496,5 @@ static void server_resolve_success(int idx)
     /* Wait for async result now */
     /* Wait for async result now */
   }
   }
 }
 }
+#endif /* NO */
 #endif /* LEAF */
 #endif /* LEAF */

+ 17 - 0
src/socket.c

@@ -237,3 +237,20 @@ int socket_ipv6_to_dots(const char *ip, char *dots)
 #endif
 #endif
 }
 }
 
 
+int get_addr(const char *ip, addr_t *addr)
+{
+  if (inet_pton(AF_INET, ip, &addr->u.addr) > 0) {
+    addr->family = AF_INET;
+    return AF_INET;
+  }
+
+#ifdef USE_IPV6
+  if (inet_pton(AF_INET6, ip, &addr->u.addr6) > 0) {
+    addr->family = AF_INET6;
+    return AF_INET6;
+  }
+#endif /* USE_IPV6 */
+
+  return 0;
+}
+

+ 1 - 0
src/socket.h

@@ -10,6 +10,7 @@
 #define SOCKET_TCP      16
 #define SOCKET_TCP      16
 #define SOCKET_UDP      32
 #define SOCKET_UDP      32
 
 
+int get_addr(const char *, addr_t *);
 
 
 /* can be static if ever combined with net.h or a more integrated 1.9 is used ... */
 /* can be static if ever combined with net.h or a more integrated 1.9 is used ... */
 typedef struct {
 typedef struct {

+ 8 - 0
src/types.h

@@ -39,4 +39,12 @@ typedef u_int32_t 		dword;
 /* port */
 /* port */
 typedef in_port_t		port_t;
 typedef in_port_t		port_t;
 
 
+typedef struct {
+  int family;
+  union {
+    struct in_addr addr;
+    struct in6_addr addr6;
+  } u;
+} addr_t;
+
 #endif /* !_TYPES_H */
 #endif /* !_TYPES_H */