[Freeswitch-svn] [commit] r4167 - in freeswitch/trunk: libs/udns src/mod/applications/mod_enum
Freeswitch SVN
mikej at freeswitch.org
Thu Feb 8 14:23:36 EST 2007
Author: mikej
Date: Thu Feb 8 14:23:36 2007
New Revision: 4167
Modified:
freeswitch/trunk/libs/udns/udns.h
freeswitch/trunk/libs/udns/udns_dn.c
freeswitch/trunk/libs/udns/udns_parse.c
freeswitch/trunk/libs/udns/udns_resolver.c
freeswitch/trunk/libs/udns/udns_rr_txt.c
freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
Log:
fix warnings and some windows compatibility issues in enum/udns
Modified: freeswitch/trunk/libs/udns/udns.h
==============================================================================
--- freeswitch/trunk/libs/udns/udns.h (original)
+++ freeswitch/trunk/libs/udns/udns.h Thu Feb 8 14:23:36 2007
@@ -58,6 +58,13 @@
/**************************************************************************/
/**************** Common definitions **************************************/
+#ifdef WIN32
+#include "winsock2.h"
+typedef SOCKET dns_socket;
+#else
+typedef int dns_socket
+#endif
+
UDNS_API const char *
dns_version(void);
@@ -352,7 +359,7 @@
/* initialize default resolver context and open it if do_open is true.
* <0 on failure. */
-UDNS_API int
+UDNS_API dns_socket
dns_init(int do_open);
/* return new resolver context with the same settings as copy */
@@ -408,11 +415,11 @@
dns_set_dbgfn(struct dns_ctx *ctx, dns_dbgfn *dbgfn);
/* open and return UDP socket */
-UDNS_API int
+UDNS_API dns_socket
dns_open(struct dns_ctx *ctx);
/* return UDP socket or -1 if not open */
-UDNS_API int
+UDNS_API dns_socket
dns_sock(const struct dns_ctx *ctx);
/* close the UDP socket */
Modified: freeswitch/trunk/libs/udns/udns_dn.c
==============================================================================
--- freeswitch/trunk/libs/udns/udns_dn.c (original)
+++ freeswitch/trunk/libs/udns/udns_dn.c Thu Feb 8 14:23:36 2007
@@ -82,7 +82,7 @@
while(np < ne) {
if (*np == '.') { /* label delimiter */
- c = dp - llab; /* length of the label */
+ c = (unsigned)(dp - llab); /* length of the label */
if (!c) { /* empty label */
if (np == (dnscc_t *)name && np + 1 == ne) {
/* special case for root dn, aka `.' */
@@ -131,7 +131,7 @@
*dp++ = (dnsc_t)c; /* place next out byte */
}
- if ((c = dp - llab) > DNS_MAXLABEL)
+ if ((c = (unsigned)(dp - llab)) > DNS_MAXLABEL)
return -1; /* label too long */
if ((llab[-1] = (dnsc_t)c) != 0) {
*dp++ = 0;
@@ -141,7 +141,7 @@
else if (isabs)
*isabs = 1;
- return dp - dn;
+ return (int)(dp - dn);
}
dnscc_t dns_inaddr_arpa_dn[14] = "\07in-addr\04arpa";
@@ -169,7 +169,7 @@
if (p > dne) return 0;
*p = n + '0';
}
- *dn = p - dn;
+ *dn = (dnsc_t)(p - dn);
dn = p + 1;
}
return dn;
@@ -187,7 +187,7 @@
l = dns_dnlen(tdn);
if (p + l > dne) return dnsiz >= DNS_MAXDN ? -1 : 0;
memcpy(p, tdn, l);
- return (p + l) - dn;
+ return (int)((p + l) - dn);
}
int dns_a4ptodn(const struct in_addr *addr, const char *tname,
@@ -232,7 +232,7 @@
l = dns_dnlen(tdn);
if (p + l > dne) return dnsiz >= DNS_MAXDN ? -1 : 0;
memcpy(p, tdn, l);
- return (p + l) - dn;
+ return (int)((p + l) - dn);
}
int dns_a6ptodn(const struct in6_addr *addr, const char *tname,
@@ -331,7 +331,7 @@
}
if (np >= ne) goto toolong;
*np++ = '\0';
- return np - name;
+ return (int)(np - name);
toolong:
return namesiz >= DNS_MAXNAME ? -1 : 0;
}
Modified: freeswitch/trunk/libs/udns/udns_parse.c
==============================================================================
--- freeswitch/trunk/libs/udns/udns_parse.c (original)
+++ freeswitch/trunk/libs/udns/udns_parse.c Thu Feb 8 14:23:36 2007
@@ -60,7 +60,7 @@
*dp++ = 0;
/* return next pos: either after the first jump or current */
*cur = jump ? jump : pp;
- return dp - dn;
+ return (int)(dp - dn);
}
if (c & 192) { /* jump */
if (pp >= end) /* eop instead of jump pos */
Modified: freeswitch/trunk/libs/udns/udns_resolver.c
==============================================================================
--- freeswitch/trunk/libs/udns/udns_resolver.c (original)
+++ freeswitch/trunk/libs/udns/udns_resolver.c Thu Feb 8 14:23:36 2007
@@ -22,6 +22,18 @@
*/
#ifdef WIN32
+#ifdef _MSC_VER
+#if (_MSC_VER >= 1400) // VC8+
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+#ifndef _CRT_NONSTDC_NO_DEPRECATE
+#define _CRT_NONSTDC_NO_DEPRECATE
+#endif
+#endif // VC8+
+#include "inet_pton.h"
+#include "process.h"
+#endif
# include <winsock2.h> /* includes <windows.h> */
# include <ws2tcpip.h> /* needed for struct in6_addr */
# include <iphlpapi.h> /* for dns server addresses etc */
@@ -187,7 +199,7 @@
/* dynamic data */
unsigned short dnsc_nextid; /* next queue ID to use */
- int dnsc_udpsock; /* UDP socket */
+ dns_socket dnsc_udpsock; /* UDP socket */
struct dns_qlink dnsc_qactive; /* active list sorted by deadline */
int dnsc_nactive; /* number entries in dnsc_qactive */
dnsc_t *dnsc_pbuf; /* packet buffer (udpbuf size) */
@@ -225,7 +237,14 @@
#define SETCTXFRESH(ctx) SETCTXINITED(ctx); assert(!CTXOPEN(ctx))
#define SETCTXINACTIVE(ctx) SETCTXINITED(ctx); assert(qlist_empty(&ctx->dnsc_qactive))
#define SETCTXOPEN(ctx) SETCTXINITED(ctx); assert(CTXOPEN(ctx))
+#ifdef WIN32
+#define CTXOPEN(ctx) (ctx->dnsc_udpsock != INVALID_SOCKET )
+#else
#define CTXOPEN(ctx) (ctx->dnsc_udpsock >= 0)
+#ifndef INVALID_SOCKET
+#define INVALID_SOCKET -1
+#endif
+#endif
#if defined(NDEBUG) || !defined(DEBUG)
#define dns_assert_ctx(ctx)
@@ -321,7 +340,7 @@
}
static void dns_set_opts_internal(struct dns_ctx *ctx, const char *opts) {
- unsigned i, v;
+ size_t i, v;
for(;;) {
while(ISSPACE(*opts)) ++opts;
if (!*opts) break;
@@ -337,7 +356,7 @@
while (*opts >= '0' && *opts <= '9');
if (dns_opts[i].min && v < dns_opts[i].min) v = dns_opts[i].min;
else if (v > dns_opts[i].max) v = dns_opts[i].max;
- dns_ctxopt(ctx, dns_opts[i].offset) = v;
+ dns_ctxopt(ctx, dns_opts[i].offset) = (unsigned)v;
break;
}
while(*opts && !ISSPACE(*opts)) ++opts;
@@ -420,7 +439,7 @@
else if (!now || q->dnsq_deadline <= now)
deadline = 0, timeout = 0;
else
- deadline = q->dnsq_deadline, timeout = deadline - now;
+ deadline = q->dnsq_deadline, timeout = (int)(deadline - now);
if (ctx->dnsc_utmexp == deadline)
return;
ctx->dnsc_utmfn(ctx, timeout, ctx->dnsc_utmctx);
@@ -608,10 +627,10 @@
static void dns_firstid(struct dns_ctx *ctx) {
struct timeval tv;
gettimeofday(&tv, NULL);
- ctx->dnsc_nextid = (tv.tv_usec ^ getpid()) & 0xffff;
+ ctx->dnsc_nextid = (unsigned short)((tv.tv_usec ^ getpid()) & 0xffff);
}
-int dns_init(int do_open) {
+dns_socket dns_init(int do_open) {
struct dns_ctx *ctx = &dns_defctx;
assert(!CTXINITED(ctx));
memset(ctx, 0, sizeof(*ctx));
@@ -620,7 +639,7 @@
ctx->dnsc_ndots = 1;
ctx->dnsc_udpbuf = DNS_EDNS0PACKET;
ctx->dnsc_port = DNS_PORT;
- ctx->dnsc_udpsock = -1;
+ ctx->dnsc_udpsock = INVALID_SOCKET;
qlist_init(&ctx->dnsc_qactive);
if (dns_init_internal(ctx) != 0)
return -1;
@@ -637,7 +656,7 @@
if (!n)
return NULL;
*n = *ctx;
- n->dnsc_udpsock = -1;
+ n->dnsc_udpsock = INVALID_SOCKET;
qlist_init(&n->dnsc_qactive);
n->dnsc_nactive = 0;
n->dnsc_pbuf = NULL;
@@ -665,8 +684,8 @@
memset(ctx, 0, sizeof(*ctx));
}
-int dns_open(struct dns_ctx *ctx) {
- int sock;
+dns_socket dns_open(struct dns_ctx *ctx) {
+ dns_socket sock;
unsigned i;
int port;
union sockaddr_ns *sns;
@@ -768,12 +787,12 @@
SETCTXINITED(ctx);
if (ctx->dnsc_udpsock < 0) return;
closesocket(ctx->dnsc_udpsock);
- ctx->dnsc_udpsock = -1;
+ ctx->dnsc_udpsock = INVALID_SOCKET;
free(ctx->dnsc_pbuf);
ctx->dnsc_pbuf = NULL;
}
-int dns_sock(const struct dns_ctx *ctx) {
+dns_socket dns_sock(const struct dns_ctx *ctx) {
SETCTXINITED(ctx);
return ctx->dnsc_udpsock;
}
@@ -983,7 +1002,7 @@
q->dnsq_buf[DNS_H_ARCNT2] = 1;
}
assert(p <= q->dnsq_buf + DNS_QBUF);
- q->dnsq_len = p - q->dnsq_buf;
+ q->dnsq_len = (unsigned)(p - q->dnsq_buf);
qlist_add_head(q, &ctx->dnsc_qactive);
++ctx->dnsc_nactive;
@@ -1248,7 +1267,7 @@
dns_request_utm(ctx, now);
if (!q)
return maxwait;
- w = q->dnsq_deadline - now;
+ w = (int)(q->dnsq_deadline - now);
return maxwait < 0 || maxwait > w ? w : maxwait;
}
@@ -1306,7 +1325,7 @@
tv.tv_sec = n;
tv.tv_usec = 0;
FD_SET(ctx->dnsc_udpsock, &rfd);
- n = select(ctx->dnsc_udpsock + 1, &rfd, NULL, NULL, &tv);
+ n = select((int)(ctx->dnsc_udpsock + 1), &rfd, NULL, NULL, &tv);
#endif
now = time(NULL);
if (n > 0)
Modified: freeswitch/trunk/libs/udns/udns_rr_txt.c
==============================================================================
--- freeswitch/trunk/libs/udns/udns_rr_txt.c (original)
+++ freeswitch/trunk/libs/udns/udns_rr_txt.c Thu Feb 8 14:23:36 2007
@@ -75,7 +75,7 @@
sp += l;
cp += l;
}
- ret->dnstxt_txt[r].len = sp - ret->dnstxt_txt[r].txt;
+ ret->dnstxt_txt[r].len = (int)(sp - ret->dnstxt_txt[r].txt);
*sp++ = '\0';
}
dns_stdrr_finish((struct dns_rr_null *)ret, (char*)sp, &p);
Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c Thu Feb 8 14:23:36 2007
@@ -423,7 +423,8 @@
char *name = NULL;
enum_query_t query = {0};
enum dns_type l_qtyp = DNS_T_NAPTR;
- int i = 0, fd = -1, abs = 0;
+ int i = 0, abs = 0;
+ dns_socket fd = (dns_socket)-1;
fd_set fds;
struct timeval tv = {0};
time_t now = 0;
@@ -484,7 +485,7 @@
#endif
tv.tv_sec = i;
tv.tv_usec = 0;
- i = select(fd+1, &fds, 0, 0, &tv);
+ i = select((int)(fd+1), &fds, 0, 0, &tv);
now = time(NULL);
if (i > 0) dns_ioevent(nctx, now);
}
@@ -500,7 +501,7 @@
if (fd > -1) {
closesocket(fd);
- fd = -1;
+ fd = (dns_socket)-1;
}
if (nctx) {
More information about the Freeswitch-svn
mailing list