From: <do...@us...> - 2007-12-20 05:16:34
|
Revision: 1320 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1320&view=rev Author: dohpaz Date: 2007-12-19 21:16:37 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Merge assorted changesets from /branches/team/elbunce: 1234 Add --enable-debug-iax option to enable libiax2 DEBUG_SUPPORT. Make ALL code enabled by DEBUG_SUPPORT in libiax2 pay attention to the current debug setting. Added an iaxclient public API iaxc_debug_iax_set to control the IAX protocol debugging state. 1277 Remove meaningless message. 1285 Add iax_seed_random() and iax_random() that will use the best random number generation I can find on a particular platform. Fall back to rand() in desperation. Lower 12 bits of rand() are not very random on many platforms, one should NEVER do a straight modulus of it's return value. Add myself to contributors for various files I've contributed to. 1298 Use consistant registration timeout. 1302 Add iaxc_register_ex() API to support passing a registration refresh time. 1304 Start register refresh up to 3 seconds before expiration, allow time for resend. 1318 Merge up to trunk of r1317. (Mostly resolving merge conflicts). 1319 Better conditionalize some debug output. Modified Paths: -------------- trunk/AUTHORS trunk/Doxyfile trunk/configure.ac trunk/doc/src/mainpage.dox trunk/lib/Makefile.am trunk/lib/audio_encode.c trunk/lib/audio_portaudio.c trunk/lib/iaxclient.h trunk/lib/iaxclient_lib.c trunk/lib/libiax2/src/iax-client.h trunk/lib/libiax2/src/iax.c trunk/lib/video.c Modified: trunk/AUTHORS =================================================================== --- trunk/AUTHORS 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/AUTHORS 2007-12-20 05:16:37 UTC (rev 1320) @@ -9,7 +9,7 @@ Steve Underwood <st...@co...> [PLC implementation from spandsp] Jean-Denis Girard <jd....@sy...> [URL Receive implementation] Panfilov Dmitry <di...@bd...> [Basic ALSA-native audio driver] -Erik Bunce <kd...@bu...> [Assorted fixes/tweaks, Documentation] +Erik Bunce <kd...@bu...> [Assorted fixes/tweaks/features, Documentation] Mihai Balea <mihai at hates dot ms> Bill Welch <welch1820 at gmail dot com> [Project files for several MS development environments] Peter Grayson <jpg...@gm...> Modified: trunk/Doxyfile =================================================================== --- trunk/Doxyfile 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/Doxyfile 2007-12-20 05:16:37 UTC (rev 1320) @@ -200,7 +200,7 @@ ENABLE_PREPROCESSING = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES -SEARCH_INCLUDES = YES +SEARCH_INCLUDES = NO INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS \ Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/configure.ac 2007-12-20 05:16:37 UTC (rev 1320) @@ -46,6 +46,7 @@ AC_TYPE_SIZE_T AC_CHECK_FUNCS([vsnprintf _vsnprintf]) +AC_CHECK_FUNCS([srandomdev srandom srand48 random lrand48]) ACX_PTHREAD @@ -75,6 +76,12 @@ [Don't use local iax library])],, [enable_local_iax="yes"]) +AC_ARG_ENABLE(debug-iax, + [AS_HELP_STRING([--enable-debug-iax], + [Enable debug support in local iax library])], + enable_debug_iax2=$enableval, + enable_debug_iax2="no") + AC_ARG_ENABLE(speex_preprocess, [AS_HELP_STRING([--disable-speex-preprocess], [Turn off speex preprocessing])],, @@ -378,6 +385,7 @@ AM_CONDITIONAL(USE_CODEC_GSM, test x$has_gsm = xyes && test ! x$with_gsm = xno) AM_CONDITIONAL(USE_LOCAL_GSM, test x$enable_local_gsm = xyes) AM_CONDITIONAL(USE_LOCAL_IAX2, test x$enable_local_iax2 = xyes) +AM_CONDITIONAL(USE_DEBUG_IAX2, test x$enable_debug_iax2 = xyes) AM_CONDITIONAL(USE_LOCAL_ILBC, test x$enable_local_ilbc = xyes) AM_CONDITIONAL(LINUX, test x$OSTYPE = xLINUX) AM_CONDITIONAL(WIN32, test x$OSTYPE = xWIN32) Modified: trunk/doc/src/mainpage.dox =================================================================== --- trunk/doc/src/mainpage.dox 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/doc/src/mainpage.dox 2007-12-20 05:16:37 UTC (rev 1320) @@ -1,8 +1,7 @@ /*! \mainpage <A href="http://iaxclient.sourceforge.net/">IAXClient</A> is an Open Source library to implement the IAX protocol used by -<A href="http://www.asterisk.org/">The Asterisk Software PBX</A>. -It is licensed under the the LGPL \ref License.<BR> +<A href="http://www.asterisk.org/">The Asterisk Software PBX</A> and is licensed under the the LGPL \ref License.<BR> Although asterisk supports other VOIP protocols (including SIP, and with patches, H.323), IAX's simple, lightweight nature gives it several advantages, particularly in that it can operate easily through NAT and packet firewalls, and it is easily extensible and simple to understand. Modified: trunk/lib/Makefile.am =================================================================== --- trunk/lib/Makefile.am 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/Makefile.am 2007-12-20 05:16:37 UTC (rev 1320) @@ -65,7 +65,9 @@ if USE_LOCAL_IAX2 SRCS += $(SRCS_IAX2) -# AM_CFLAGS += -DDEBUG_SUPPORT +if USE_DEBUG_IAX2 +AM_CFLAGS += -DDEBUG_SUPPORT +endif USE_DEBUG_IAX2 endif USE_LOCAL_IAX2 if USE_LOCAL_ILBC Modified: trunk/lib/audio_encode.c =================================================================== --- trunk/lib/audio_encode.c 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/audio_encode.c 2007-12-20 05:16:37 UTC (rev 1320) @@ -327,7 +327,7 @@ if(iax_send_voice(call->session,format, outbuf, sizeof(outbuf) - outsize, samples-insize) == -1) { - puts("Failed to send voice!"); + fprintf(stderr, "Failed to send voice! %s\n", iax_errstr); return -1; } Modified: trunk/lib/audio_portaudio.c =================================================================== --- trunk/lib/audio_portaudio.c 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/audio_portaudio.c 2007-12-20 05:16:37 UTC (rev 1320) @@ -9,6 +9,7 @@ * Steve Kann <st...@st...> * Michael Van Donselaar <mv...@va...> * Shawn Lawrence <sha...@te...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. Modified: trunk/lib/iaxclient.h =================================================================== --- trunk/lib/iaxclient.h 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/iaxclient.h 2007-12-20 05:16:37 UTC (rev 1320) @@ -751,6 +751,17 @@ EXPORT int iaxc_register(const char * user, const char * pass, const char * host); /*! + Registers the IAXClient instance with an IAX server + \param user The username to register as + \param pass The password to register with + \param host The address of the host/peer to register with + \param refresh The registration refresh period + + \return The registration id number upon success; -1 otherwise. +*/ +EXPORT int iaxc_register_ex(const char * user, const char * pass, const char * host, int refresh); + +/*! Respond to incoming call \a callNo as busy. */ EXPORT void iaxc_send_busy_on_incoming_call(int callNo); @@ -1357,6 +1368,12 @@ */ EXPORT int iaxc_push_video(void *data, unsigned int size, int fragment); +/*! + Sets the IAX debug set to \a enable. + \param enable If non-zero enable iax protocol debugging +*/ +EXPORT int iaxc_debug_iax_set(int enable); + #ifdef __cplusplus } #endif Modified: trunk/lib/iaxclient_lib.c =================================================================== --- trunk/lib/iaxclient_lib.c 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/iaxclient_lib.c 2007-12-20 05:16:37 UTC (rev 1320) @@ -13,6 +13,7 @@ * Mihai Balea <mihai AT hates DOT ms> * Peter Grayson <jpg...@gm...> * Bill Cholewka <bc...@gm...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. @@ -744,9 +745,9 @@ for ( cur = registrations; cur != NULL; cur = cur->next ) { - // If there is less than one second before the registration is about + // If there is less than three seconds before the registration is about // to expire, renew it. - if ( iaxci_usecdiff(&now, &cur->last) > cur->refresh - 1 * 1000 *1000 ) + if ( iaxci_usecdiff(&now, &cur->last) > (cur->refresh - 3) * 1000 *1000 ) { if ( cur->session != NULL ) { @@ -758,7 +759,7 @@ iaxci_usermsg(IAXC_ERROR, "Can't make new registration session"); return; } - iax_register(cur->session, cur->host, cur->user, cur->pass, 60); + iax_register(cur->session, cur->host, cur->user, cur->pass, cur->refresh); cur->last = now; } } @@ -1240,6 +1241,11 @@ EXPORT int iaxc_register(const char * user, const char * pass, const char * host) { + iaxc_register_ex(user, pass, host, 60); +} + +EXPORT int iaxc_register_ex(const char * user, const char * pass, const char * host, int refresh) +{ struct iaxc_registration *newreg; newreg = (struct iaxc_registration *)malloc(sizeof (struct iaxc_registration)); @@ -1259,14 +1265,14 @@ } gettimeofday(&newreg->last,NULL); - newreg->refresh = 60*1000*1000; /* 60 seconds, in usecs */ + newreg->refresh = refresh; strncpy(newreg->host, host, 256); strncpy(newreg->user, user, 256); strncpy(newreg->pass, pass, 256); - /* send out the initial registration timeout 300 seconds */ - iax_register(newreg->session, host, user, pass, 300); + /* send out the initial registration with refresh seconds */ + iax_register(newreg->session, host, user, pass, refresh); /* add it to the list; */ newreg->id = ++next_registration_id; @@ -1961,3 +1967,13 @@ return 0; } +int iaxc_debug_iax_set(int enable) +{ +#ifdef DEBUG_SUPPORT + if (enable) + iax_enable_debug(); + else + iax_disable_debug(); +#endif +} + Modified: trunk/lib/libiax2/src/iax-client.h =================================================================== --- trunk/lib/libiax2/src/iax-client.h 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/libiax2/src/iax-client.h 2007-12-20 05:16:37 UTC (rev 1320) @@ -245,6 +245,10 @@ /* Fine tune jitterbuffer */ extern void iax_set_jb_target_extra( long value ); +/* Portable 'decent' random number generation */ +void iax_seed_random(); +int iax_random(); + #if defined(__cplusplus) } #endif Modified: trunk/lib/libiax2/src/iax.c =================================================================== --- trunk/lib/libiax2/src/iax.c 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/libiax2/src/iax.c 2007-12-20 05:16:37 UTC (rev 1320) @@ -276,7 +276,30 @@ s->sendto = ptr; } +void iax_seed_random() +{ +#if defined(HAVE_SRANDOMDEV) + srandomdev(); +#elif defined(HAVE_SRANDOM) + srandom((unsigned int)time(0)); +#elif define(HAVE_SRAND48) + srand48((long int)time(0)); +#else + srand((unsigned int)time(0)); +#endif +} +int iax_random() +{ +#if defined(HAVE_RANDOM) + return (int)random(); +#elif defined(HAVE_LRAND48) + return (int)lrand48(); +#else + return rand(); +#endif +} + /* This is a little strange, but to debug you call DEBU(G "Hello World!\n"); */ #if defined(WIN32) || defined(_WIN32_WCE) #define G __FILE__, __LINE__, @@ -286,7 +309,7 @@ #define DEBU __debug #if defined(WIN32) || defined(_WIN32_WCE) -static int __debug(char *file, int lineno, char *fmt, ...) +static int __debug(const char *file, int lineno, const char *fmt, ...) { va_list args; va_start(args, fmt); @@ -298,7 +321,7 @@ return 0; } #else -static int __debug(char *file, int lineno, char *func, char *fmt, ...) +static int __debug(const char *file, int lineno, const char *func, const char *fmt, ...) { va_list args; va_start(args, fmt); @@ -341,15 +364,12 @@ static struct iax_sched *schedq = NULL; static struct iax_session *sessions = NULL; static int callnums = 1; -static int transfer_id = 1; /* for attended transfer */ - unsigned int iax_session_get_capability(struct iax_session *s) { return s->capability; } - static int inaddrcmp(struct sockaddr_in *sin1, struct sockaddr_in *sin2) { return (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) || (sin1->sin_port != sin2->sin_port); @@ -831,10 +851,9 @@ if (ntohs(h->scallno) & IAX_FLAG_FULL) iax_showframe(f, NULL, 0, f->transfer ? - &(f->session->transfer) : - &(f->session->peeraddr), - f->datalen - - sizeof(struct ast_iax2_full_hdr)); + &(f->session->transfer) : + &(f->session->peeraddr), + f->datalen - sizeof(struct ast_iax2_full_hdr)); } #endif /* Send the frame raw */ @@ -1005,9 +1024,8 @@ DEBU(G "Started on port %d\n", portno); } - srand((unsigned int)time(0)); - callnums = rand() % 32767 + 1; - transfer_id = rand() % 32767 + 1; + iax_seed_random(); + callnums = 1 + (int)(32767.0 * (iax_random() / (RAND_MAX + 1.0))); return portno; } @@ -1400,8 +1418,11 @@ struct iax_session *s1 = new_session; memset(&ied0, 0, sizeof(ied0)); + memset(&ied1, 0, sizeof(ied1)); + int transfer_id = 1 + (int)(32767.0 * (iax_random() / (RAND_MAX + 1.0))); + /* reversed setup */ iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &s1->peeraddr); iax_ie_append_short(&ied0, IAX_IE_CALLNO, s1->peercallno); @@ -1425,12 +1446,14 @@ s0->transferpeer = s1->callno; s1->transferpeer = s0->callno; +#ifdef DEBUG_SUPPORT + if (debug) { + DEBU(G "iax_setup_transfer(%d, %d) transfer_id=%d\n", s0->callno, s1->callno, transfer_id); + DEBU(G "\torg: callno=%d peercallno=%d peeraddr=%s peerport=%d\n", s0->callno, s0->peercallno, inet_ntoa(s0->peeraddr.sin_addr), ntohs(s0->peeraddr.sin_port)); + DEBU(G "\tnew: callno=%d peercallno=%d peeraddr=%s peerport=%d\n", s1->callno, s1->peercallno, inet_ntoa(s1->peeraddr.sin_addr), ntohs(s1->peeraddr.sin_port)); + } +#endif - transfer_id++; - - if (transfer_id > 32767) - transfer_id = 1; - res = send_command(s0, AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1); if (res < 0) { return -1; Modified: trunk/lib/video.c =================================================================== --- trunk/lib/video.c 2007-12-19 20:01:18 UTC (rev 1319) +++ trunk/lib/video.c 2007-12-20 05:16:37 UTC (rev 1320) @@ -9,6 +9,7 @@ * Steve Kann <st...@st...> * Mihai Balea <mihai AT hates DOT ms> * Peter Grayson <jpg...@gm...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. @@ -675,8 +676,6 @@ if ( call->vformat == 0 ) { - fprintf(stderr, "video format not set for call %d\n", - selected_call); goto callback_failed; } @@ -1830,8 +1829,8 @@ ) == -1 ) { - fprintf(stderr, "Failed to send a slice, call %d, size %d\n", - selected_call, slice_set.size[i]); + fprintf(stderr, "Failed to send a slice, call %d, size %d: %s\n", + selected_call, slice_set.size[i], iax_errstr); return -1; } @@ -1842,8 +1841,8 @@ size, 0, 0) == -1 ) { fprintf(stderr, "iaxc_push_video: failed to send " - "video frame of size %d on call %d\n", - size, selected_call); + "video frame of size %d on call %d: %s\n", + size, selected_call, iax_errstr); return -1; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |