[svn-commits] jpeeler: branch jpeeler/externalivr-tcp r108392 - /team/jpeeler/externalivr-t...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Mar 12 18:58:31 CDT 2008
Author: jpeeler
Date: Wed Mar 12 18:58:31 2008
New Revision: 108392
URL: http://svn.digium.com/view/asterisk?view=rev&rev=108392
Log:
checkpoint, changed socket connection to use FILE *
Modified:
team/jpeeler/externalivr-tcp/apps/app_externalivr.c
Modified: team/jpeeler/externalivr-tcp/apps/app_externalivr.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/externalivr-tcp/apps/app_externalivr.c?view=diff&rev=108392&r1=108391&r2=108392
==============================================================================
--- team/jpeeler/externalivr-tcp/apps/app_externalivr.c (original)
+++ team/jpeeler/externalivr-tcp/apps/app_externalivr.c Wed Mar 12 18:58:31 2008
@@ -88,7 +88,7 @@
static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
int eivr_events_fd, int eivr_commands_fd, int eivr_errors_fd,
- const char *args);
+ FILE *stream, const char *args);
int eivr_connect_socket(struct ast_channel *chan, const char *host, int port);
@@ -312,7 +312,7 @@
char hostname[1024];
char *port_str = NULL;
int port = 0;
- struct ast_tcptls_server_instance *ser;
+ struct ast_tcptls_session_instance *ser;
struct ivr_localuser foo = {
.playlist = AST_LIST_HEAD_INIT_VALUE,
@@ -344,6 +344,11 @@
pdargbuf_ptr[0] = '|';
if(!strncmp(args.cmd[0], "ivr://", 6)) {
+ struct server_args ivr_desc = {
+ .accept_fd = -1,
+ .name = "IVR",
+ };
+ struct ast_hostent hp;
/*communicate through socket to server*/
if (chan->_state != AST_STATE_UP) {
@@ -366,22 +371,16 @@
if(!port)
port = 2949; /*default port, if one is not provided*/
- struct server_args ivr_desc = {
- .accept_fd = -1,
- .name = "IVR",
- };
- struct ast_hostent hp;
ast_gethostbyname(hostname, &hp);
-
ivr_desc.sin.sin_family = AF_INET;
ivr_desc.sin.sin_port = htons(port);
- bcopy((char *)hp.hp.h_addr, (char *)&ivr_desc.sin.sin_addr.s_addr, hp.hp.h_length);
+ memmove(&ivr_desc.sin.sin_addr.s_addr, hp.hp.h_addr, hp.hp.h_length);
ser = ast_tcptls_client_start(&ivr_desc);
if (!ser) {
goto exit;
}
- res = eivr_comm(chan, u, ser->fd, ser->fd, 0, pipe_delim_argbuf);
+ res = eivr_comm(chan, u, 0, 0, 0, ser->f, pipe_delim_argbuf);
} else {
if (pipe(child_stdin)) {
@@ -439,7 +438,7 @@
child_stdout[1] = 0;
close(child_stderr[1]);
child_stderr[1] = 0;
- res = eivr_comm(chan, u, child_stdin[1], child_stdout[0], child_stderr[0], pipe_delim_argbuf);
+ res = eivr_comm(chan, u, child_stdin[1], child_stdout[0], child_stderr[0], NULL, pipe_delim_argbuf);
}
}
@@ -465,8 +464,10 @@
if (child_stderr[1])
close(child_stderr[1]);
- if (ser)
- free(ser);
+ if (ser) {
+ fclose(ser->f);
+ ast_tcptls_session_instance_destroy(ser);
+ }
while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
ast_free(entry);
@@ -476,7 +477,7 @@
static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
int eivr_events_fd, int eivr_commands_fd, int eivr_errors_fd,
- const char *args)
+ FILE *stream, const char *args)
{
struct playlist_entry *entry;
struct ast_frame *f;
@@ -491,21 +492,25 @@
FILE *eivr_commands = NULL;
FILE *eivr_errors = NULL;
FILE *eivr_events = NULL;
-
- if (!(eivr_events = fdopen(eivr_events_fd, "w"))) {
- ast_chan_log(LOG_WARNING, chan, "Could not open stream to send events\n");
- goto exit;
- }
- if (!(eivr_commands = fdopen(eivr_commands_fd, "r"))) {
- ast_chan_log(LOG_WARNING, chan, "Could not open stream to receive commands\n");
- goto exit;
- }
- if(eivr_errors_fd) { /*if opening a socket connection, error stream will not be used*/
+
+ if (!stream) {
+ if (!(eivr_events = fdopen(eivr_events_fd, "w"))) {
+ ast_chan_log(LOG_WARNING, chan, "Could not open stream to send events\n");
+ goto exit;
+ }
+ if (!(eivr_commands = fdopen(eivr_commands_fd, "r"))) {
+ ast_chan_log(LOG_WARNING, chan, "Could not open stream to receive commands\n");
+ goto exit;
+ }
if (!(eivr_errors = fdopen(eivr_errors_fd, "r"))) {
ast_chan_log(LOG_WARNING, chan, "Could not open stream to receive errors\n");
goto exit;
}
- }
+ } else {
+ /* if opening a socket connection, error stream will not be used */
+ eivr_events = stream;
+ eivr_commands = stream;
+ }
setvbuf(eivr_events, NULL, _IONBF, 0);
setvbuf(eivr_commands, NULL, _IONBF, 0);
@@ -688,14 +693,16 @@
exit:
- if (eivr_events)
- fclose(eivr_events);
-
- if (eivr_commands)
- fclose(eivr_commands);
-
- if (eivr_errors)
- fclose(eivr_errors);
+ if (!stream) {
+ if (eivr_events)
+ fclose(eivr_events);
+
+ if (eivr_commands)
+ fclose(eivr_commands);
+
+ if (eivr_errors)
+ fclose(eivr_errors);
+ }
return res;
More information about the svn-commits
mailing list