[asterisk-commits] jpeeler: branch jpeeler/externalivr-tcp r107098 - /team/jpeeler/externalivr-t...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 10 11:53:54 CDT 2008
Author: jpeeler
Date: Mon Mar 10 11:53:54 2008
New Revision: 107098
URL: http://svn.digium.com/view/asterisk?view=rev&rev=107098
Log:
convert socket connection to use tcp generic routines from tcptls.h
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=107098&r1=107097&r2=107098
==============================================================================
--- team/jpeeler/externalivr-tcp/apps/app_externalivr.c (original)
+++ team/jpeeler/externalivr-tcp/apps/app_externalivr.c Mon Mar 10 11:53:54 2008
@@ -51,6 +51,7 @@
#include "asterisk/linkedlists.h"
#include "asterisk/app.h"
#include "asterisk/utils.h"
+#include "asterisk/tcptls.h"
static const char *app = "ExternalIVR";
@@ -317,7 +318,7 @@
char hostname[1024];
char *port_str = NULL;
int port = 0;
- int socket;
+ struct ast_tcptls_server_instance *ser;
struct ivr_localuser foo = {
.playlist = AST_LIST_HEAD_INIT_VALUE,
@@ -349,6 +350,7 @@
pdargbuf_ptr[0] = '|';
if(!strncmp(args.cmd[0], "ivr://", 6)) {
+
/*communicate through socket to server*/
if (chan->_state != AST_STATE_UP) {
ast_answer(chan);
@@ -370,11 +372,22 @@
if(!port)
port = 2949; /*default port, if one is not provided*/
- if((socket = eivr_connect_socket(chan,hostname, port)) < 0) {
- ast_chan_log(LOG_WARNING, chan, "Failed to connect socket to %s:%d\n", hostname, port);
+ 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);
+ ser = ast_tcptls_client_start(&ivr_desc);
+
+ if (!ser) {
goto exit;
- } else
- res = eivr_comm(chan, u, socket, socket, 0, pipe_delim_argbuf);
+ }
+ res = eivr_comm(chan, u, ser->fd, ser->fd, 0, pipe_delim_argbuf);
} else {
if (pipe(child_stdin)) {
@@ -457,6 +470,9 @@
if (child_stderr[1])
close(child_stderr[1]);
+
+ if (ser)
+ free(ser);
while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
ast_free(entry);
@@ -691,29 +707,6 @@
}
-int eivr_connect_socket(struct ast_channel *chan, const char *host, int port)
-{
- int unit = -1;
- struct sockaddr_in sin;
- struct ast_hostent hp;
-
- if (ast_gethostbyname(host, &hp) == NULL) {
- return unit;
- }
- bzero((char *)&sin, sizeof(sin));
- sin.sin_family = AF_INET;
- bcopy((char *)hp.hp.h_addr, (char *)&sin.sin_addr.s_addr, hp.hp.h_length);
- sin.sin_port = htons(port);
-
- if ((unit = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- return unit;
- }
- if (connect(unit, &sin, sizeof(sin)) < 0) {
- unit = -1;
- }
- return(unit);
-}
-
static int unload_module(void)
{
return ast_unregister_application(app);
More information about the asterisk-commits
mailing list