Index: asterisk/acl.c =================================================================== RCS file: /usr/cvsroot/asterisk/acl.c,v retrieving revision 1.48 diff -u -r1.48 acl.c --- asterisk/acl.c 10 Jul 2005 22:56:21 -0000 1.48 +++ asterisk/acl.c 11 Jul 2005 07:36:27 -0000 @@ -52,6 +52,10 @@ AST_MUTEX_DEFINE_STATIC(routeseq_lock); #endif +#ifdef __CYGWIN__ +#include "asterisk/win32.h" +#endif + struct ast_netsock { ASTOBJ_COMPONENTS(struct ast_netsock); struct sockaddr_in bindaddr; Index: asterisk/ast_expr.y =================================================================== RCS file: /usr/cvsroot/asterisk/ast_expr.y,v retrieving revision 1.16 diff -u -r1.16 ast_expr.y --- asterisk/ast_expr.y 22 Apr 2005 13:11:34 -0000 1.16 +++ asterisk/ast_expr.y 11 Jul 2005 07:36:27 -0000 @@ -24,6 +24,9 @@ #include "asterisk/ast_expr.h" #include "asterisk/logger.h" +#ifdef __CYGWIN__ +#include "asterisk/win32.h" +#endif #ifndef QUAD_MIN #ifdef LONG_LONG_MIN Index: asterisk/ast_expr2.y =================================================================== RCS file: /usr/cvsroot/asterisk/ast_expr2.y,v retrieving revision 1.4 diff -u -r1.4 ast_expr2.y --- asterisk/ast_expr2.y 24 Jun 2005 02:51:47 -0000 1.4 +++ asterisk/ast_expr2.y 11 Jul 2005 07:36:28 -0000 @@ -28,6 +28,9 @@ #include #include #include +#ifdef __CYGWIN__ +#include "asterisk/win32.h" +#endif #ifdef LONG_LONG_MIN #define QUAD_MIN LONG_LONG_MIN Index: asterisk/asterisk.c =================================================================== RCS file: /usr/cvsroot/asterisk/asterisk.c,v retrieving revision 1.167 diff -u -r1.167 asterisk.c --- asterisk/asterisk.c 8 Jul 2005 21:14:34 -0000 1.167 +++ asterisk/asterisk.c 11 Jul 2005 07:36:28 -0000 @@ -30,6 +30,10 @@ #include #include +#ifdef __CYGWIN__ +#include +#endif + #if defined(__FreeBSD__) || defined( __NetBSD__ ) || defined(SOLARIS) #include #endif @@ -81,10 +85,17 @@ ast_verbose( "Written by Mark Spencer \n"); \ ast_verbose( "=========================================================================\n") +#ifndef __CYGWIN__ +int option_nofork=0; +#else +int option_nofork=1; +inline void flockfile (FILE *stream) {}; +inline void funlockfile (FILE *stream) {}; +extern void setPriority(int priority); +#endif int option_verbose=0; int option_debug=0; int option_exec_includes=0; -int option_nofork=0; int option_quiet=0; int option_console=0; int option_highpriority=0; @@ -689,7 +700,7 @@ memset(&sched, 0, sizeof(sched)); /* We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing. */ -#ifdef __linux__ +#if defined(__linux__) || defined(__CYGWIN__) if (pri) { sched.sched_priority = 10; if (sched_setscheduler(0, SCHED_RR, &sched)) { @@ -784,8 +795,12 @@ } } if (option_console || option_remote) { +#ifndef __CYGWIN__ if (getenv("HOME")) snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); +#else + snprintf(filename, sizeof(filename), "%s/.asterisk_history", ast_config_AST_VAR_DIR); +#endif if (!ast_strlen_zero(filename)) ast_el_write_history(filename); if (el != NULL) @@ -876,11 +891,13 @@ else fputs(s + pos,stdout); fflush(stdout); +#ifndef __CYGWIN__ if (complete) { /* Wake up a poll()ing console */ if (option_console && consolethread != AST_PTHREADT_NULL) pthread_kill(consolethread, SIGURG); } +#endif } static int ast_all_zeros(char *s) @@ -1614,8 +1631,12 @@ fdprint(ast_consock, tmp); ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid); remotehostname = hostname; +#ifndef __CYGWIN__ if (getenv("HOME")) snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); +#else + snprintf(filename, sizeof(filename), "%s/.asterisk_history", ast_config_AST_VAR_DIR); +#endif if (el_hist == NULL || el == NULL) ast_el_initialize(); @@ -1766,9 +1787,11 @@ if (sscanf(v->value, "%d", &option_debug) != 1) { option_debug = ast_true(v->value); } +#ifndef __CYGWIN__ /* Disable forking (-f at startup) */ } else if (!strcasecmp(v->name, "nofork")) { option_nofork = ast_true(v->value); +#endif /* Run quietly (-q at startup ) */ } else if (!strcasecmp(v->name, "quiet")) { option_quiet = ast_true(v->value); @@ -1777,7 +1800,11 @@ option_console = ast_true(v->value); /* Run with highg priority if the O/S permits (-p at startup) */ } else if (!strcasecmp(v->name, "highpriority")) { +#ifndef __CYGWIN__ option_highpriority = ast_true(v->value); +#else + option_highpriority = atoi(v->value); +#endif /* Initialize RSA auth keys (IAX2) (-i at startup) */ } else if (!strcasecmp(v->name, "initcrypto")) { option_initcrypto = ast_true(v->value); @@ -1846,8 +1873,12 @@ callerid_init(); ast_utils_init(); tdd_init(); +#ifndef __CYGWIN__ if (getenv("HOME")) snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); +#else + snprintf(filename, sizeof(filename), "%s/.asterisk_history", ast_config_AST_VAR_DIR); +#endif /* Check if we're root */ /* if (geteuid()) { @@ -1921,12 +1952,14 @@ case 'V': show_version(); exit(0); +#ifndef __CYGWIN__ case 'U': runuser = optarg; break; case 'G': rungroup = optarg; break; +#endif case '?': exit(1); } @@ -1946,6 +1979,9 @@ ast_verbose("[ Reading Master Configuration ]"); ast_readconfig(); +#ifdef __CYGWIN__ + setPriority(option_highpriority); +#else if (set_priority(option_highpriority)) { exit(1); } @@ -1979,7 +2015,7 @@ if (option_verbose) ast_verbose("Running as user '%s'\n", runuser); } - +#endif term_init(); printf(term_end()); fflush(stdout); @@ -2032,6 +2068,7 @@ } else ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno)); +#ifndef __CYGWIN__ if (!option_verbose && !option_debug && !option_nofork && !option_console) { daemon(0,0); /* Blindly re-write pid file since we are forking */ @@ -2043,6 +2080,7 @@ } else ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno)); } +#endif /* Test recursive mutex locking. */ if (test_for_thread_safety()) @@ -2193,8 +2231,12 @@ } /* Do nothing */ for(;;) { /* apparently needed for the MACos */ +#ifndef __CYGWIN__ struct pollfd p = { -1 /* no descriptor */, 0, 0 }; poll(&p, 0, -1); +#else + sleep(10000); +#endif } return 0; } Index: asterisk/autoservice.c =================================================================== RCS file: /usr/cvsroot/asterisk/autoservice.c,v retrieving revision 1.13 diff -u -r1.13 autoservice.c --- asterisk/autoservice.c 6 Jun 2005 22:12:18 -0000 1.13 +++ asterisk/autoservice.c 11 Jul 2005 07:36:29 -0000 @@ -74,6 +74,9 @@ } ast_mutex_unlock(&autolock); +#ifdef __CYGWIN__ + pthread_testcancel(); +#endif /* if (!aslist) break; */ ms = 500; @@ -116,8 +119,12 @@ free(aslist); aslist = NULL; res = -1; +#ifndef __CYGWIN__ } else pthread_kill(asthread, SIGURG); +#else + } +#endif } } } @@ -147,8 +154,10 @@ if (!chan->_softhangup) res = 0; } +#ifndef __CYGWIN__ if (asthread != AST_PTHREADT_NULL) pthread_kill(asthread, SIGURG); +#endif ast_mutex_unlock(&autolock); /* Wait for it to un-block */ while(ast_test_flag(chan, AST_FLAG_BLOCKING)) Index: asterisk/channel.c =================================================================== RCS file: /usr/cvsroot/asterisk/channel.c,v retrieving revision 1.216 diff -u -r1.216 channel.c --- asterisk/channel.c 9 Jul 2005 20:37:59 -0000 1.216 +++ asterisk/channel.c 11 Jul 2005 07:36:30 -0000 @@ -509,7 +509,11 @@ #endif if (needqueue) { +#ifdef __CYGWIN__ + if (socketpair(AF_LOCAL, SOCK_STREAM, 0, tmp->alertpipe)) { +#else if (pipe(tmp->alertpipe)) { +#endif ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n"); free(tmp); return NULL; @@ -1146,6 +1150,11 @@ } res = poll(pfds, y, *ms); if (res < 0) { +#ifdef __CYGWIN__ + if (res == -11) { + goto calc_diff2; + } else +#endif /* Simulate a timeout if we were interrupted */ if (errno != EINTR) *ms = -1; @@ -1167,6 +1176,9 @@ } } } +#ifdef __CYGWIN__ +calc_diff2: +#endif if (*ms > 0) { long passed; gettimeofday(&now, NULL); @@ -1260,6 +1272,11 @@ if (res < 0) { for (x=0;x 0) { long diff; gettimeofday(&end, NULL); Index: asterisk/config.c =================================================================== RCS file: /usr/cvsroot/asterisk/config.c,v retrieving revision 1.73 diff -u -r1.73 config.c --- asterisk/config.c 10 Jul 2005 22:56:21 -0000 1.73 +++ asterisk/config.c 11 Jul 2005 07:36:30 -0000 @@ -669,7 +669,11 @@ } time(&t); ast_copy_string(date, ctime(&t), sizeof(date)); +#ifdef __CYGWIN__ + if ((f = fopen(fn, "w+"))) { +#else if ((f = fopen(fn, "w"))) { +#endif if ((option_verbose > 1) && !option_debug) ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn); fprintf(f, ";!\n"); @@ -1020,6 +1024,18 @@ ast_mutex_unlock(&config_lock); return 0; +} + +struct ast_config *new_config(void) +{ + + struct ast_config *tmp; + tmp = malloc(sizeof(struct ast_config)); + if (tmp) + memset(tmp, 0, sizeof(struct ast_config)); + else + ast_log(LOG_WARNING, "Out of memory\n"); + return tmp; } static char show_config_help[] = Index: asterisk/db.c =================================================================== RCS file: /usr/cvsroot/asterisk/db.c,v retrieving revision 1.19 diff -u -r1.19 db.c --- asterisk/db.c 6 Jun 2005 22:12:18 -0000 1.19 +++ asterisk/db.c 11 Jul 2005 07:36:31 -0000 @@ -41,6 +41,10 @@ #include "asterisk/manager.h" #include "db1-ast/include/db.h" +#ifdef __CYGWIN__ +#define dbopen __dbopen +#endif + static DB *astdb; AST_MUTEX_DEFINE_STATIC(dblock); Index: asterisk/logger.c =================================================================== RCS file: /usr/cvsroot/asterisk/logger.c,v retrieving revision 1.77 diff -u -r1.77 logger.c --- asterisk/logger.c 10 Jul 2005 22:56:21 -0000 1.77 +++ asterisk/logger.c 11 Jul 2005 07:36:31 -0000 @@ -152,10 +152,12 @@ static struct logchannel *make_logchannel(char *channel, char *components, int lineno) { struct logchannel *chan; +#ifndef __CYGWIN__ char *facility; #ifndef SOLARIS CODE *cptr; #endif +#endif if (ast_strlen_zero(channel)) return NULL; @@ -167,6 +169,7 @@ memset(chan, 0, sizeof(struct logchannel)); if (!strcasecmp(channel, "console")) { chan->type = LOGTYPE_CONSOLE; +#ifndef __CYGWIN__ } else if (!strncasecmp(channel, "syslog", 6)) { /* * syntax is: @@ -240,6 +243,7 @@ chan->type = LOGTYPE_SYSLOG; snprintf(chan->filename, sizeof(chan->filename), "%s", channel); openlog("asterisk", LOG_PID, chan->facility); +#endif /* Cygwin */ } else { if (channel[0] == '/') { if(!ast_strlen_zero(hostname)) { Index: asterisk/manager.c =================================================================== RCS file: /usr/cvsroot/asterisk/manager.c,v retrieving revision 1.102 diff -u -r1.102 manager.c --- asterisk/manager.c 10 Jul 2005 22:56:21 -0000 1.102 +++ asterisk/manager.c 11 Jul 2005 07:36:32 -0000 @@ -45,6 +45,9 @@ #include "asterisk/md5.h" #include "asterisk/acl.h" #include "asterisk/utils.h" +#ifdef __CYGWIN__ +#include "asterisk/win32.h" +#endif struct fast_originate_helper { @@ -1336,11 +1339,26 @@ int arg = 1; int flags; pthread_attr_t attr; +#ifdef __CYGWIN__ + int ps; + struct pollfd fds[1]; +#endif pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); for (;;) { +#ifdef __CYGWIN__ + fds[0].fd = asock; + fds[0].events= POLLIN; + ps = poll(fds, 1, -1); + if (ps < 0) { + if (errno != EINTR) + if (option_verbose > 4) + ast_log(LOG_WARNING, "manager poll returned error: %s\n", strerror(errno)); + continue; + } +#endif sinlen = sizeof(sin); as = accept(asock, (struct sockaddr *)&sin, &sinlen); if (as < 0) { Index: asterisk/poll.c =================================================================== RCS file: /usr/cvsroot/asterisk/poll.c,v retrieving revision 1.2 diff -u -r1.2 poll.c --- asterisk/poll.c 21 Apr 2005 06:02:43 -0000 1.2 +++ asterisk/poll.c 11 Jul 2005 07:36:32 -0000 @@ -78,6 +78,11 @@ #include /* string functions */ #include "asterisk/poll-compat.h" /* this package */ +#ifdef __CYGWIN__ +#include +#include +#include +#endif /*---------------------------------------------------------------------------*\ Macros @@ -301,6 +306,15 @@ map_select_results (pArray, n_fds, &read_descs, &write_descs, &except_descs); } +#ifdef __CYGWIN__ + if (ready_descriptors < 0) { + if ((errno != EINTR) && (errno != EINVAL) && (errno != EBADF)) { + if (option_verbose > 4) + ast_log(LOG_WARNING, "poll(%d) n(%d) bad error %d\r\n", pArray->fd, n_fds, errno); + return -11; + } + } +#endif return ready_descriptors; } Index: asterisk/rtp.c =================================================================== RCS file: /usr/cvsroot/asterisk/rtp.c,v retrieving revision 1.136 diff -u -r1.136 rtp.c --- asterisk/rtp.c 18 Jun 2005 17:13:01 -0000 1.136 +++ asterisk/rtp.c 11 Jul 2005 07:36:33 -0000 @@ -42,6 +42,9 @@ #include "asterisk/utils.h" #include "asterisk/cli.h" #include "asterisk/unaligned.h" +#ifdef __CYGWIN__ +#include "asterisk/win32.h" +#endif #define MAX_TIMESTAMP_SKEW 640 Index: asterisk/utils.c =================================================================== RCS file: /usr/cvsroot/asterisk/utils.c,v retrieving revision 1.53 diff -u -r1.53 utils.c --- asterisk/utils.c 24 Jun 2005 22:45:15 -0000 1.53 +++ asterisk/utils.c 11 Jul 2005 07:36:33 -0000 @@ -32,6 +32,9 @@ #include "asterisk/io.h" #include "asterisk/logger.h" #include "asterisk/md5.h" +#if defined(__CYGWIN__) +#include "asterisk/win32.h" +#endif #define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */ #include "asterisk/strings.h" @@ -45,7 +48,7 @@ static char base64[64]; static char b2a[256]; -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) || defined(__CYGWIN__) /* duh? ERANGE value copied from web... */ #define ERANGE 34 Index: asterisk/include/asterisk.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk.h,v retrieving revision 1.8 diff -u -r1.8 asterisk.h --- asterisk/include/asterisk.h 5 Jul 2005 22:11:43 -0000 1.8 +++ asterisk/include/asterisk.h 11 Jul 2005 07:36:33 -0000 @@ -54,6 +54,11 @@ extern int dnsmgr_init(void); extern void dnsmgr_reload(void); +#ifdef __CYGWIN__ +#include +#include +#endif + /*! * \brief Register the version of a source code file with the core. * \param file the source file name Index: asterisk/include/asterisk/config.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/config.h,v retrieving revision 1.21 diff -u -r1.21 config.h --- asterisk/include/asterisk/config.h 24 Jun 2005 22:45:15 -0000 1.21 +++ asterisk/include/asterisk/config.h 11 Jul 2005 07:36:34 -0000 @@ -182,6 +182,7 @@ struct ast_variable *ast_variable_new(const char *name, const char *value); void ast_variable_append(struct ast_category *category, struct ast_variable *variable); int ast_variable_delete(struct ast_config *cfg, char *category, char *variable, char *value); +struct ast_config *new_config(void); int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator); Index: asterisk/include/asterisk/endian.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/endian.h,v retrieving revision 1.3 diff -u -r1.3 endian.h --- asterisk/include/asterisk/endian.h 7 May 2005 06:01:30 -0000 1.3 +++ asterisk/include/asterisk/endian.h 11 Jul 2005 07:36:34 -0000 @@ -27,7 +27,7 @@ #ifndef __BYTE_ORDER #ifdef __linux__ #include -#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__CYGWIN__) #if defined(__OpenBSD__) #include #endif /* __OpenBSD__ */ Index: asterisk/include/asterisk/lock.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/lock.h,v retrieving revision 1.31 diff -u -r1.31 lock.h --- asterisk/include/asterisk/lock.h 23 Jun 2005 01:17:00 -0000 1.31 +++ asterisk/include/asterisk/lock.h 11 Jul 2005 07:36:34 -0000 @@ -42,7 +42,11 @@ and will not run without them. */ #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP #define PTHREAD_MUTEX_INIT_VALUE PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +#ifdef PTHREAD_MUTEX_RECURSIVE_NP #define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE_NP +#else +#define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE +#endif #else #define PTHREAD_MUTEX_INIT_VALUE PTHREAD_MUTEX_INITIALIZER #define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE Index: asterisk/include/asterisk/res_odbc.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/res_odbc.h,v retrieving revision 1.4 diff -u -r1.4 res_odbc.h --- asterisk/include/asterisk/res_odbc.h 17 Feb 2005 16:31:08 -0000 1.4 +++ asterisk/include/asterisk/res_odbc.h 11 Jul 2005 07:36:34 -0000 @@ -12,10 +12,16 @@ #ifndef _RES_ODBC_H #define _RES_ODBC_H +#ifdef __CYGWIN__ +#include +#include +#include +#include +#else #include #include #include - +#endif Index: asterisk/stdtime/private.h =================================================================== RCS file: /usr/cvsroot/asterisk/stdtime/private.h,v retrieving revision 1.1 diff -u -r1.1 private.h --- asterisk/stdtime/private.h 13 Sep 2003 20:51:48 -0000 1.1 +++ asterisk/stdtime/private.h 11 Jul 2005 07:36:34 -0000 @@ -10,8 +10,10 @@ /* Stuff moved from Makefile.inc to reduce clutter */ #ifndef TM_GMTOFF +#ifndef __CYGWIN__ #define TM_GMTOFF tm_gmtoff #define TM_ZONE tm_zone +#endif #define STD_INSPIRED 1 #define PCTS 1 #define HAVE_LONG_DOUBLE 1