[asterisk-commits] branch oej/test-this-branch r27681 - in
/team/oej/test-this-branch: ./ apps/ ...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue May 16 23:12:54 MST 2006
Author: oej
Date: Wed May 17 01:12:54 2006
New Revision: 27681
URL: http://svn.digium.com/view/asterisk?rev=27681&view=rev
Log:
- resetting automerge
- update ami_ssl part with new patch from jtodd
Modified:
team/oej/test-this-branch/ (props changed)
team/oej/test-this-branch/apps/app_dial.c
team/oej/test-this-branch/apps/app_voicemail.c
team/oej/test-this-branch/channels/chan_sip.c
team/oej/test-this-branch/cli.c
team/oej/test-this-branch/include/asterisk/manager.h
team/oej/test-this-branch/include/asterisk/rtp.h
team/oej/test-this-branch/include/asterisk/ssl_addon.h
team/oej/test-this-branch/include/asterisk/utils.h
team/oej/test-this-branch/manager.c
team/oej/test-this-branch/rtp.c
team/oej/test-this-branch/ssl_addon.c
team/oej/test-this-branch/utils.c
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
automerge = http://edvina.net/training/
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
Binary property 'branch-1.2-blocked' - no diff available.
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed May 17 01:12:54 2006
@@ -1,1 +1,1 @@
-/trunk:1-27551
+/trunk:1-27678
Modified: team/oej/test-this-branch/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/apps/app_dial.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/apps/app_dial.c (original)
+++ team/oej/test-this-branch/apps/app_dial.c Wed May 17 01:12:54 2006
@@ -472,6 +472,8 @@
c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause);
if (!c)
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
+ else
+ ast_channel_inherit_variables(in, o->chan);
} else {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", c->name);
@@ -1051,6 +1053,8 @@
tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause);
if (!tmp->chan)
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
+ else
+ ast_channel_inherit_variables(chan, tmp->chan);
} else {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", tmp->chan->name);
Modified: team/oej/test-this-branch/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/apps/app_voicemail.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/apps/app_voicemail.c (original)
+++ team/oej/test-this-branch/apps/app_voicemail.c Wed May 17 01:12:54 2006
@@ -2426,14 +2426,14 @@
char tmptxtfile[AST_MAX_FILENAME_LEN];
char callerid[256];
FILE *txt;
- int res = 0;
+ int res = 0, txtdes;
int msgnum;
int duration = 0;
int ausemacro = 0;
int ousemacro = 0;
int ouseexten = 0;
char date[256];
- char dir[256];
+ char dir[256], tmpdir[260];
char fn[AST_MAX_FILENAME_LEN];
char prefile[AST_MAX_FILENAME_LEN]="";
char tempfile[AST_MAX_FILENAME_LEN]="";
@@ -2485,6 +2485,7 @@
DISPOSE(tempfile, -1);
/* It's easier just to try to make it than to check for its existence */
create_dirpath(dir, sizeof(dir), vmu->context, ext, "INBOX");
+ create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, ext, "tmp");
/* Check current or macro-calling context for special extensions */
if (ast_test_flag(vmu, VM_OPERATOR)) {
@@ -2591,121 +2592,129 @@
if (!ast_strlen_zero(fmt)) {
msgnum = 0;
- if (vm_lock_path(dir)) {
- free_user(vmu);
- return ERROR_LOCK_PATH;
- }
-
- /*
- * This operation can be very expensive if done say over NFS or if the mailbox has 100+ messages
- * in the folder. So we should get this first so we don't cut off the first few seconds of the
- * message.
- */
- do {
- make_file(fn, sizeof(fn), dir, msgnum);
- if (!EXISTS(dir,msgnum,fn,chan->language))
- break;
- msgnum++;
- } while (msgnum < vmu->maxmsg);
+ if (count_messages(vmu, dir) >= vmu->maxmsg) {
+ res = ast_streamfile(chan, "vm-mailboxfull", chan->language);
+ if (!res)
+ res = ast_waitstream(chan, "");
+ ast_log(LOG_WARNING, "No more messages possible\n");
+ pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
+ goto leave_vm_out;
+ }
+
+ snprintf(tmptxtfile, sizeof(tmptxtfile), "%s/XXXXXX", tmpdir);
+ txtdes = mkstemp(tmptxtfile);
+ if (txtdes < 0) {
+ res = ast_streamfile(chan, "vm-mailboxfull", chan->language);
+ if (!res)
+ res = ast_waitstream(chan, "");
+ ast_log(LOG_ERROR, "Unable to create message file: %s\n", strerror(errno));
+ pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
+ goto leave_vm_out;
+ }
/* Now play the beep once we have the message number for our next message. */
if (res >= 0) {
/* Unless we're *really* silent, try to send the beep */
res = ast_stream_and_wait(chan, "beep", chan->language, "");
}
- if (msgnum < vmu->maxmsg) {
- /* assign a variable with the name of the voicemail file */
- pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", fn);
-
- /* Store information */
- snprintf(txtfile, sizeof(txtfile), "%s.txt", fn);
- snprintf(tmptxtfile, sizeof(tmptxtfile), "%s.txt.tmp", fn);
- txt = fopen(tmptxtfile, "w+");
- if (txt) {
- get_date(date, sizeof(date));
- fprintf(txt,
- ";\n"
- "; Message Information file\n"
- ";\n"
- "[message]\n"
- "origmailbox=%s\n"
- "context=%s\n"
- "macrocontext=%s\n"
- "exten=%s\n"
- "priority=%d\n"
- "callerchan=%s\n"
- "callerid=%s\n"
- "origdate=%s\n"
- "origtime=%ld\n"
- "category=%s\n",
- ext,
- chan->context,
- chan->macrocontext,
- chan->exten,
- chan->priority,
- chan->name,
- ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"),
- date, (long)time(NULL),
- category ? category : "");
- } else
- ast_log(LOG_WARNING, "Error opening text file for output\n");
- res = play_record_review(chan, NULL, fn, vmmaxmessage, fmt, 1, vmu, &duration, dir, options->record_gain);
- if (res == '0') {
- if (txt && EXISTS(dir,msgnum,fn,chan->language)) {
- fclose(txt);
- rename(tmptxtfile, txtfile);
- } else if (txt && !EXISTS(dir,msgnum,fn,chan->language)) {
- if (option_debug)
- ast_log(LOG_DEBUG, "The recorded media file is gone, so we should remove the .txt file too!\n");
- fclose(txt);
- unlink(tmptxtfile);
- }
- goto transfer;
- }
- if (res > 0)
- res = 0;
- if (txt) {
- fprintf(txt, "duration=%d\n", duration);
- fclose(txt);
- rename(tmptxtfile, txtfile);
- }
-
+
+ /* Store information */
+ txt = fdopen(txtdes, "w+");
+ if (txt) {
+ get_date(date, sizeof(date));
+ fprintf(txt,
+ ";\n"
+ "; Message Information file\n"
+ ";\n"
+ "[message]\n"
+ "origmailbox=%s\n"
+ "context=%s\n"
+ "macrocontext=%s\n"
+ "exten=%s\n"
+ "priority=%d\n"
+ "callerchan=%s\n"
+ "callerid=%s\n"
+ "origdate=%s\n"
+ "origtime=%ld\n"
+ "category=%s\n",
+ ext,
+ chan->context,
+ chan->macrocontext,
+ chan->exten,
+ chan->priority,
+ chan->name,
+ ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"),
+ date, (long)time(NULL),
+ category ? category : "");
+ } else
+ ast_log(LOG_WARNING, "Error opening text file for output\n");
+ res = play_record_review(chan, NULL, tmptxtfile, vmmaxmessage, fmt, 1, vmu, &duration, NULL, options->record_gain);
+
+ if (txt) {
if (duration < vmminmessage) {
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmminmessage);
DELETE(dir,msgnum,fn);
- /* XXX We should really give a prompt too short/option start again, with leave_vm_out called only after a timeout XXX */
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- goto leave_vm_out;
- }
- /* Are there to be more recipients of this message? */
- while (tmpptr) {
- struct ast_vm_user recipu, *recip;
- char *exten, *context;
-
- exten = strsep(&tmpptr, "&");
- context = strchr(exten, '@');
- if (context) {
- *context = '\0';
- context++;
+ } else {
+ fprintf(txt, "duration=%d\n", duration);
+ fclose(txt);
+ if (vm_lock_path(dir)) {
+ ast_log(LOG_ERROR, "Couldn't lock directory %s. Voicemail will be lost.\n", dir);
+ /* Delete files */
+ ast_filedelete(tmptxtfile, NULL);
+ unlink(tmptxtfile);
+ } else {
+ for (;;) {
+ make_file(fn, sizeof(fn), dir, msgnum);
+ if (!EXISTS(dir, msgnum, fn, NULL))
+ break;
+ msgnum++;
+ }
+
+ /* assign a variable with the name of the voicemail file */
+ pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", fn);
+
+ snprintf(txtfile, sizeof(txtfile), "%s.txt", fn);
+ ast_filerename(tmptxtfile, fn, NULL);
+ rename(tmptxtfile, txtfile);
+
+ ast_unlock_path(dir);
+
+ /* Are there to be more recipients of this message? */
+ while (tmpptr) {
+ struct ast_vm_user recipu, *recip;
+ char *exten, *context;
+
+ exten = strsep(&tmpptr, "&");
+ context = strchr(exten, '@');
+ if (context) {
+ *context = '\0';
+ context++;
+ }
+ if ((recip = find_user(&recipu, context, exten))) {
+ copy_message(chan, vmu, 0, msgnum, duration, recip, fmt);
+ free_user(recip);
+ }
+ }
+ if (ast_fileexists(fn, NULL, NULL)) {
+ STORE(dir, vmu->mailbox, vmu->context, msgnum);
+ notify_new_message(chan, vmu, msgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
+ DISPOSE(dir, msgnum);
+ }
}
- if ((recip = find_user(&recipu, context, exten))) {
- copy_message(chan, vmu, 0, msgnum, duration, recip, fmt);
- free_user(recip);
- }
- }
- if (ast_fileexists(fn, NULL, NULL)) {
- STORE(dir, vmu->mailbox, vmu->context, msgnum);
- notify_new_message(chan, vmu, msgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
- DISPOSE(dir, msgnum);
- }
+ }
+ }
+
+ if (res == '0') {
+ goto transfer;
+ } else if (res > 0)
+ res = 0;
+
+ if (duration < vmminmessage)
+ /* XXX We should really give a prompt too short/option start again, with leave_vm_out called only after a timeout XXX */
+ pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
+ else
pbx_builtin_setvar_helper(chan, "VMSTATUS", "SUCCESS");
- } else {
- ast_unlock_path(dir);
- res = ast_stream_and_wait(chan, "vm-mailboxfull", chan->language, "");
- ast_log(LOG_WARNING, "No more messages possible\n");
- pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
- }
} else
ast_log(LOG_WARNING, "No format for saving voicemail?\n");
leave_vm_out:
Modified: team/oej/test-this-branch/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_sip.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_sip.c (original)
+++ team/oej/test-this-branch/channels/chan_sip.c Wed May 17 01:12:54 2006
@@ -2273,6 +2273,7 @@
ast_rtp_destroy(r->vrtp);
r->vrtp = NULL;
}
+ ast_rtp_setdtmf(r->rtp, ast_test_flag(&r->flags[0], SIP_DTMF) != SIP_DTMF_INFO);
r->prefs = peer->prefs;
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)) {
@@ -3722,9 +3723,12 @@
free(p);
return NULL;
}
+ ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_INFO);
ast_rtp_settos(p->rtp, global_tos_audio);
- if (p->vrtp)
+ if (p->vrtp) {
ast_rtp_settos(p->vrtp, global_tos_video);
+ ast_rtp_setdtmf(p->vrtp, 0);
+ }
if (p->udptl)
ast_udptl_settos(p->udptl, global_tos_audio);
p->rtptimeout = global_rtptimeout;
@@ -11919,6 +11923,7 @@
get_rdnis(p, NULL); /* Get redirect information */
extract_uri(p, req); /* Get the Contact URI */
build_contact(p); /* Build our contact header */
+ ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_INFO);
if (gotdest) {
if (gotdest == 1 && ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP)) {
Modified: team/oej/test-this-branch/cli.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/cli.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/cli.c (original)
+++ team/oej/test-this-branch/cli.c Wed May 17 01:12:54 2006
@@ -65,7 +65,7 @@
if (res == -1) {
ast_log(LOG_ERROR, "Memory allocation failure\n");
} else {
- ast_carefulwrite(fd, stuff, strlen(stuff), 100);
+ ast_carefulwrite(fd, stuff, strlen(stuff), 100, NULL);
free(stuff);
}
}
Modified: team/oej/test-this-branch/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/manager.h?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/manager.h (original)
+++ team/oej/test-this-branch/include/asterisk/manager.h Wed May 17 01:12:54 2006
@@ -26,6 +26,10 @@
#include <arpa/inet.h>
#include "asterisk/lock.h"
+
+#if AMI_WITH_SSL
+#include "asterisk/ssl_addon.h"
+#endif
/*!
\file
@@ -180,6 +184,10 @@
struct eventqent *eventq;
/* Timeout for ast_carefulwrite() */
int writetimeout;
+#if AMI_WITH_SSL
+ /*! Whether or not we use SSL (ssl context *, or NULL) */
+ SSL *ssl;
+#endif
struct mansession *next;
};
Modified: team/oej/test-this-branch/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/rtp.h?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/rtp.h (original)
+++ team/oej/test-this-branch/include/asterisk/rtp.h Wed May 17 01:12:54 2006
@@ -151,6 +151,9 @@
void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
+/*! \brief Indicate whether this RTP session is carrying DTMF or not */
+void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf);
+
int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
Modified: team/oej/test-this-branch/include/asterisk/ssl_addon.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/ssl_addon.h?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/ssl_addon.h (original)
+++ team/oej/test-this-branch/include/asterisk/ssl_addon.h Wed May 17 01:12:54 2006
@@ -59,7 +59,7 @@
Accepts the connection, if the security is enabled it returns the negative fd. -1 is flase, -2, -3
etc are ssl connections.
*/
-int saccept(int s);
+int saccept(void *s);
/*! \brief
Sends the data over secured or unsecured connections.
@@ -70,7 +70,7 @@
/*! \brief
Receives the connection from either ssl or fd.
*/
-int m_recv(int s, void *buf, size_t len, int flags);
+int m_recv(void *s, void *buf, size_t len, int flags);
/*! \brief
@@ -78,7 +78,7 @@
It also closes the ssl meta connection.
*/
-int close_sock(int socket);
+int close_sock(void *s);
int errexit(char s[]);
Modified: team/oej/test-this-branch/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/utils.h?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/utils.h (original)
+++ team/oej/test-this-branch/include/asterisk/utils.h Wed May 17 01:12:54 2006
@@ -233,8 +233,10 @@
it on a file descriptor that _DOES_ have NONBLOCK set. This way,
there is only one system call made to do a write, unless we actually
have a need to wait. This way, we get better performance.
-*/
-int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
+ The file descriptor is taken from the struct mansession pointer, if it is
+ non NULL, otherwise the parameter fd is used.
+*/
+int ast_carefulwrite(int fd, char *s, int len, int timeoutms, void *vs);
/*! Compares the source address and port of two sockaddr_in */
static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
Modified: team/oej/test-this-branch/manager.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/manager.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/manager.c (original)
+++ team/oej/test-this-branch/manager.c Wed May 17 01:12:54 2006
@@ -53,6 +53,9 @@
#include "asterisk/channel.h"
#include "asterisk/file.h"
+#ifdef AMI_WITH_SSL
+#include "asterisk/ssl_addon.h"
+#endif
#include "asterisk/manager.h"
#include "asterisk/config.h"
#include "asterisk/callerid.h"
@@ -65,9 +68,6 @@
#include "asterisk/md5.h"
#include "asterisk/acl.h"
#include "asterisk/utils.h"
-#ifdef AMI_WITH_SSL
-#include "asterisk/ssl_addon.h"
-#endif
#include "asterisk/http.h"
struct fast_originate_helper {
@@ -388,7 +388,7 @@
return;
}
if (s->fd > -1)
- ast_carefulwrite(s->fd, stuff, strlen(stuff), s->writetimeout);
+ ast_carefulwrite(0, stuff, strlen(stuff), s->writetimeout, s);
else {
tmp = realloc(s->outputstr, (s->outputstr ? strlen(s->outputstr) : 0) + strlen(stuff) + 1);
if (tmp) {
@@ -622,7 +622,7 @@
{
struct eventqent *eqe;
#ifdef AMI_WITH_SSL
- close_sock(s->fd);
+ close_sock(s);
#else
if (s->fd > -1)
close(s->fd);
@@ -1760,7 +1760,7 @@
eqe = s->eventq->next;
if ((s->authenticated && (s->readperm & eqe->category) == eqe->category) &&
((s->send_events & eqe->category) == eqe->category)) {
- if (!ret && ast_carefulwrite(s->fd, eqe->eventdata, strlen(eqe->eventdata), s->writetimeout) < 0)
+ if (!ret && ast_carefulwrite(0, eqe->eventdata, strlen(eqe->eventdata), s->writetimeout, s) < 0)
ret = -1;
}
unuse_eventqent(s->eventq);
@@ -1876,9 +1876,6 @@
s->inlen = 0;
}
fds[0].fd = s->fd;
-#ifdef AMI_WITH_SSL
- fds[0].fd = get_real_fd(s->fd);
-#endif
fds[0].events = POLLIN;
do {
@@ -1902,7 +1899,14 @@
} else if (res > 0) {
ast_mutex_lock(&s->__lock);
#ifdef AMI_WITH_SSL
- res = m_recv(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen, 0);
+ if (s->ssl) {
+ res = SSL_read (s->ssl, s->inbuf + s->inlen,
+ sizeof(s->inbuf) - 1 - s->inlen);
+ }
+ else {
+ res = read(s->fd, s->inbuf + s->inlen,
+ sizeof(s->inbuf) - 1 - s->inlen);
+ }
#else
res = read(s->fd, s->inbuf + s->inlen, sizeof(s->inbuf) - 1 - s->inlen);
#endif
@@ -2034,53 +2038,55 @@
ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
}
}
+
+ s = malloc(sizeof(struct mansession));
+ if (!s) {
+ ast_log(LOG_WARNING, "Failed to allocate management session: %s\n", strerror(errno));
+ continue;
+ }
+
+ memset(s, 0, sizeof(struct mansession));
+ memcpy(&s->sin, &sin, sizeof(sin));
+ s->writetimeout = 100;
+ s->waiting_thread = AST_PTHREADT_NULL;
+
+ s->fd = as;
+
#ifdef AMI_WITH_SSL
is_encrypted = is_encrypt_request(sslclhellotimeout, as);
if (is_encrypted > 0) {
if (!acceptencryptedconnection) {
ast_log(LOG_WARNING, "Accepting encrypted connection disabled, closing the connection \n");
- close_sock(as);
+ close_sock(s);
+ free(s);
continue;
} else {
- if((as = saccept(as)) >= 0 ) {
+ if(saccept(s) == -1 ) {
ast_log(LOG_WARNING, "Can't accept the ssl connection, since SSL init has failed for certificate reason\n");
- close_sock(as);
+ close_sock(s);
+ free(s);
continue;
}
}
} else if (is_encrypted == -1) {
ast_log(LOG_ERROR, "SSL version 2 is unsecure, we don't support it\n");
- close_sock(as);
+ close_sock(s);
+ free(s);
continue;
}
if ( (! acceptunencryptedconnection) && (as >= 0)) {
ast_log(LOG_NOTICE, "Unencrypted connections are not accepted and we received an unencrypted connection request\n");
- close_sock(as);
+ close_sock(s);
+ free(s);
continue;
}
#endif
- s = malloc(sizeof(struct mansession));
- if (!s) {
- ast_log(LOG_WARNING, "Failed to allocate management session: %s\n", strerror(errno));
- continue;
- }
- memset(s, 0, sizeof(struct mansession));
- memcpy(&s->sin, &sin, sizeof(sin));
- s->writetimeout = 100;
- s->waiting_thread = AST_PTHREADT_NULL;
-
if (!block_sockets) {
/* For safety, make sure socket is non-blocking */
-#ifdef AMI_WITH_SSL
- flags = fcntl(get_real_fd(as), F_GETFL);
- fcntl(get_real_fd(as), F_SETFL, flags | O_NONBLOCK);
-#else
flags = fcntl(as, F_GETFL);
fcntl(as, F_SETFL, flags | O_NONBLOCK);
-#endif
}
ast_mutex_init(&s->__lock);
- s->fd = as;
s->send_events = -1;
ast_mutex_lock(&sessionlock);
num_sessions++;
Modified: team/oej/test-this-branch/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/rtp.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/rtp.c (original)
+++ team/oej/test-this-branch/rtp.c Wed May 17 01:12:54 2006
@@ -110,6 +110,7 @@
#define FLAG_NAT_ACTIVE (3 << 1)
#define FLAG_NAT_INACTIVE (0 << 1)
#define FLAG_NAT_INACTIVE_NOWARN (1 << 1)
+#define FLAG_HAS_DTMF (1 << 3)
/*! \brief RTP session description */
struct ast_rtp {
@@ -510,6 +511,11 @@
void ast_rtp_setnat(struct ast_rtp *rtp, int nat)
{
rtp->nat = nat;
+}
+
+void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf)
+{
+ ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF);
}
static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
@@ -1638,6 +1644,7 @@
rtp->s = rtp_socket();
rtp->ssrc = ast_random();
rtp->seqno = ast_random() & 0xffff;
+ ast_set_flag(rtp, FLAG_HAS_DTMF);
if (rtp->s < 0) {
free(rtp);
ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno));
@@ -2503,10 +2510,6 @@
memset(&vac0, 0, sizeof(vac0));
memset(&vac1, 0, sizeof(vac1));
- /* if need DTMF, cant native bridge */
- if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
- return AST_BRIDGE_FAILED_NOWARN;
-
/* Lock channels */
ast_channel_lock(c0);
while(ast_channel_trylock(c1)) {
@@ -2548,6 +2551,25 @@
ast_channel_unlock(c1);
return AST_BRIDGE_FAILED_NOWARN;
}
+
+ if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) {
+ /* can't bridge, we are carrying DTMF for this channel and the bridge
+ needs it
+ */
+ ast_channel_unlock(c0);
+ ast_channel_unlock(c1);
+ return AST_BRIDGE_FAILED_NOWARN;
+ }
+
+ if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) {
+ /* can't bridge, we are carrying DTMF for this channel and the bridge
+ needs it
+ */
+ ast_channel_unlock(c0);
+ ast_channel_unlock(c1);
+ return AST_BRIDGE_FAILED_NOWARN;
+ }
+
/* Get codecs from both sides */
codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0;
codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0;
Modified: team/oej/test-this-branch/ssl_addon.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/ssl_addon.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/ssl_addon.c (original)
+++ team/oej/test-this-branch/ssl_addon.c Wed May 17 01:12:54 2006
@@ -61,10 +61,9 @@
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/ssl_addon.h"
+#include "asterisk/manager.h"
SSL_CTX *sctx;
-static long rec_bytes;
-static long sent_bytes;
static int ssl_initialized;
@@ -100,153 +99,42 @@
return 0;
}
-/*! \brief Takes the negative ssl fd and returns the positive fd recieved from the os.
- * It goes through arrray of fixed maximum number of secured channels.
-*/
-int get_real_fd(int fd)
-{
- if (fd<-1) {
- fd = -fd - 2;
- if (fd>=0 && fd <SEC_MAX)
- fd = sec_channel[fd].fd;
- else fd = -1;
-
- }
- return fd;
-}
-
-/*! \brief Returns the SSL pointer from the fd. This structure is filled when we accept
- * the ssl connection and used
- * for reading and writing through ssl.
-*/
-SSL *get_ssl(int fd)
-{
- SSL *ssl = NULL;
-
- fd = -fd - 2;
-
- if (fd>=0 && fd <SEC_MAX)
- ssl = sec_channel[fd].ssl;
-
- return ssl;
-}
-
-/*! \brief Returns the empty ssl slot. Used to save ssl information.
-*/
-int sec_getslot(void)
-{
- int i;
-
- for (i=0; i<SEC_MAX; i++) {
- if(sec_channel[i].ssl==NULL)
- break;
- }
-
- if (i==SEC_MAX)
+/*! \brief Accepts the ssl connection.
+*/
+int saccept(void *vs)
+{
+ int fd, err;
+
+ struct mansession *s = (struct mansession *) vs;
+
+ if (!ssl_initialized)
return -1;
- return i;
-}
-
-/*! \brief Accepts the ssl connection. Retrurns the negative fd. negative fd's are
- * choosen to differentiate between ssl and non-ssl connections. positive
- * fd's are used for non-ssl connections and negative fd's are used for ssl
- * connections. So we purposefully calculate and return negative fds.
- * You can always get positive fd by calling get_real_fd(negative fd).
- * The positive fd's are required for system calls.
- *
-*/
-int saccept(int s)
-{
- int fd, err;
- SSL* ssl;
-
- if (!ssl_initialized)
- return s;
-
- if (((fd=sec_getslot())!=-1)) {
- ssl=SSL_new(sctx);
- SSL_set_fd(ssl, s);
- sec_channel[fd].ssl = ssl; /* remember ssl */
- sec_channel[fd].fd = s; /* remember the real fd */
- do {
- err = SSL_accept(ssl);
- err = SSL_get_error(ssl, err);
- } while( err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
-
- SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
- ast_log(LOG_DEBUG, "ssl_addon: Connection accepted");
-
- err=1;
-
- fd = -(fd+2);
-
- if (err!=1 || !ssl) {
- /* it did not work */
- sec_channel[fd].ssl = NULL; /* free the slot */
- fd = -1;
- }
- }
- return fd;
-}
-
-/*!
- * \brief Writes through secured ssl connection
-*/
-int m_send(int fd, const void *data, size_t len)
-{
- sent_bytes += len;
-
- if (fd < -1) {
- SSL* ssl = get_ssl(fd);
- return SSL_write(ssl, data, len);
- }
- return write(fd, data, len);
-}
-
-/*!
- * \brief Receives data from the SSL connection.
-*/
-int m_recv(int s, void *buf, size_t len, int flags)
-{
- int ret = 0;
-
- if (s<-1) {
- SSL* ssl = get_ssl(s);
- ret = SSL_read (ssl, buf, len);
- } else
- ret = recv(s, buf, len, flags);
-
- if (ret > 0)
- rec_bytes += ret;
-
- if (option_debug > 2)
- ast_log(LOG_DEBUG, "Received data from SSL socket - %d\n", ret);
- return ret;
-}
-
-
-/*! \brief
- Needs to be called instead of close() to close a socket.
- It also closes the SSL meta connection.
-*/
-
-int close_sock(int socket)
-{
- int ret=0;
- SSL* ssl = NULL;
-
- if (socket < -1) {
- socket = - socket - 2;
-
- ssl = sec_channel[socket].ssl;
- sec_channel[socket].ssl = NULL;
- socket = sec_channel[socket].fd;
- }
-
- ret= close(socket);
-
- if (ssl)
- SSL_free (ssl);
+
+ s->ssl=SSL_new(sctx);
+ SSL_set_fd(s->ssl, s->fd);
+ do {
+ err = SSL_accept(s->ssl);
+ err = SSL_get_error(s->ssl, err);
+ } while( err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
+
+ SSL_set_mode(s->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
+ ast_log(LOG_DEBUG, "ssl_addon: Connection accepted");
+
+ if (!s->ssl)
+ fd = -1; /* it did not work */
+
+ return 0;
+}
+
+int close_sock(void *vs)
+{
+ int ret;
+ struct mansession *s = (struct mansession *) vs;
+
+ ret = close(s->fd);
+
+ if(s->ssl)
+ SSL_free (s->ssl);
return(ret);
}
Modified: team/oej/test-this-branch/utils.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/utils.c?rev=27681&r1=27680&r2=27681&view=diff
==============================================================================
--- team/oej/test-this-branch/utils.c (original)
+++ team/oej/test-this-branch/utils.c Wed May 17 01:12:54 2006
@@ -47,6 +47,11 @@
#include "asterisk/sha1.h"
#include "asterisk/options.h"
#include "asterisk/compat.h"
+
+#ifdef AMI_WITH_SSL
+#include "asterisk/ssl_addon.h"
+#include "asterisk/manager.h"
+#endif
#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */
#include "asterisk/strings.h"
@@ -591,14 +596,27 @@
return poll(pfd, 1, ms);
}
-int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
+int ast_carefulwrite(int fd, char *s, int len, int timeoutms, void *vs)
{
/* Try to write string, but wait no more than ms milliseconds
before timing out */
int res = 0;
struct pollfd fds[1];
+#if AMI_WITH_SSL
+ struct mansession *ms = (struct mansession *)vs;
+
+ if(ms) fd = ms->fd;
+#endif
+
while (len) {
+#if AMI_WITH_SSL
+ if (ms->ssl)
+ res = SSL_write(ms->ssl, s, len);
+ else
+ res = write(ms->fd, s, len);
+#else
res = write(fd, s, len);
+#endif
if ((res < 0) && (errno != EAGAIN)) {
return -1;
}
More information about the asterisk-commits
mailing list