add support for user level auth to esl and fs_cli

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16161 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2010-01-05 20:37:16 +00:00
parent 87ca6ed553
commit a53236da7f
18 changed files with 548 additions and 48 deletions

View File

@ -57,6 +57,7 @@ typedef struct {
char name[128];
char host[128];
esl_port_t port;
char user[256];
char pass[128];
int debug;
const char *console_fnkeys[12];
@ -559,6 +560,7 @@ static int usage(char *name){
printf(" -?,-h --help Usage Information\n");
printf(" -H, --host=hostname Host to connect\n");
printf(" -P, --port=port Port to connect (1 - 65535)\n");
printf(" -u, --user=user@domain user@domain\n");
printf(" -p, --password=password Password\n");
printf(" -x, --execute=command Execute Command and Exit\n");
printf(" -l, --loglevel=command Log Level\n");
@ -699,11 +701,16 @@ static int process_command(esl_handle_t *handle, const char *cmd)
printf("Unknown command [%s]\n", cmd);
} else {
char cmd_str[1024] = "";
const char *err = NULL;
snprintf(cmd_str, sizeof(cmd_str), "api %s\n\n", cmd);
esl_send_recv(handle, cmd_str);
if (handle->last_sr_event && handle->last_sr_event->body) {
printf("%s\n", handle->last_sr_event->body);
if (handle->last_sr_event) {
if (handle->last_sr_event->body) {
printf("%s\n", handle->last_sr_event->body);
} else if ((err = esl_event_get_header(handle->last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
printf("Error: %s!\n", err + 4);
}
}
}
@ -958,6 +965,7 @@ int main(int argc, char *argv[])
{"help", 0, 0, 'h'},
{"host", 1, 0, 'H'},
{"port", 1, 0, 'P'},
{"user", 1, 0, 'u'},
{"password", 1, 0, 'p'},
{"debug", 1, 0, 'd'},
{"execute", 1, 0, 'x'},
@ -968,8 +976,10 @@ int main(int argc, char *argv[])
char temp_host[128];
int argv_host = 0;
char temp_user[256];
char temp_pass[128];
int argv_pass = 0 ;
int argv_user = 0 ;
int temp_port = 0;
int argv_port = 0;
int temp_log = -1;
@ -1000,7 +1010,7 @@ int main(int argc, char *argv[])
for(;;) {
int option_index = 0;
opt = getopt_long(argc, argv, "H:U:P:S:p:d:x:l:qh?", options, &option_index);
opt = getopt_long(argc, argv, "H:U:P:S:u:p:d:x:l:qh?", options, &option_index);
if (opt == -1) break;
switch (opt)
{
@ -1017,6 +1027,10 @@ int main(int argc, char *argv[])
argv_error = 1;
}
break;
case 'u':
esl_set_string(temp_user, optarg);
argv_user = 1;
break;
case 'p':
esl_set_string(temp_pass, optarg);
argv_pass = 1;
@ -1078,6 +1092,8 @@ int main(int argc, char *argv[])
if (!strcasecmp(var, "host")) {
esl_set_string(profiles[pcount-1].host, val);
} else if (!strcasecmp(var, "user")) {
esl_set_string(profiles[pcount-1].user, val);
} else if (!strcasecmp(var, "password")) {
esl_set_string(profiles[pcount-1].pass, val);
} else if (!strcasecmp(var, "port")) {
@ -1130,6 +1146,11 @@ int main(int argc, char *argv[])
if (argv_port) {
profile->port = (esl_port_t)temp_port;
}
if (argv_user) {
esl_set_string(profile->user, temp_user);
}
if (argv_pass) {
esl_set_string(profile->pass, temp_pass);
}
@ -1151,7 +1172,7 @@ int main(int argc, char *argv[])
snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", profile->name);
}
if (esl_connect(&handle, profile->host, profile->port, profile->pass)) {
if (esl_connect(&handle, profile->host, profile->port, profile->user, profile->pass)) {
esl_global_set_default_logger(7);
esl_log(ESL_LOG_ERROR, "Error Connecting [%s]\n", handle.err);
if (!argv_exec) usage(argv[0]);
@ -1160,11 +1181,18 @@ int main(int argc, char *argv[])
if (argv_exec){
const char *err = NULL;
snprintf(cmd_str, sizeof(cmd_str), "api %s\n\n", argv_command);
esl_send_recv(&handle, cmd_str);
if (handle.last_sr_event && handle.last_sr_event->body) {
printf("%s\n", handle.last_sr_event->body);
if (handle.last_sr_event) {
if (handle.last_sr_event->body) {
printf("%s\n", handle.last_sr_event->body);
} else if ((err = esl_event_get_header(handle.last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
printf("Error: %s!\n", err + 4);
}
}
esl_disconnect(&handle);
return 0;
}

View File

@ -574,7 +574,47 @@ SWIGEXPORT jstring JNICALL Java_org_freeswitch_esl_eslJNI_ESLevent_1nextHeader(J
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jstring jarg3) {
SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jstring jarg3, jstring jarg4) {
jlong jresult = 0 ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
(void)jenv;
(void)jcls;
arg1 = 0;
if (jarg1) {
arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0);
if (!arg1) return 0;
}
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return 0;
}
arg3 = 0;
if (jarg3) {
arg3 = (char *)jenv->GetStringUTFChars(jarg3, 0);
if (!arg3) return 0;
}
arg4 = 0;
if (jarg4) {
arg4 = (char *)jenv->GetStringUTFChars(jarg4, 0);
if (!arg4) return 0;
}
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
*(ESLconnection **)&jresult = result;
if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1);
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
if (arg3) jenv->ReleaseStringUTFChars(jarg3, (const char *)arg3);
if (arg4) jenv->ReleaseStringUTFChars(jarg4, (const char *)arg4);
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jstring jarg3) {
jlong jresult = 0 ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
@ -607,7 +647,7 @@ SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SW
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jint jarg1) {
SWIGEXPORT jlong JNICALL Java_org_freeswitch_esl_eslJNI_new_1ESLconnection_1_1SWIG_12(JNIEnv *jenv, jclass jcls, jint jarg1) {
jlong jresult = 0 ;
int arg1 ;
ESLconnection *result = 0 ;

View File

@ -33,12 +33,16 @@ public class ESLconnection {
swigCPtr = 0;
}
public ESLconnection(String host, String port, String user, String password) {
this(eslJNI.new_ESLconnection__SWIG_0(host, port, user, password), true);
}
public ESLconnection(String host, String port, String password) {
this(eslJNI.new_ESLconnection__SWIG_0(host, port, password), true);
this(eslJNI.new_ESLconnection__SWIG_1(host, port, password), true);
}
public ESLconnection(int socket) {
this(eslJNI.new_ESLconnection__SWIG_1(socket), true);
this(eslJNI.new_ESLconnection__SWIG_2(socket), true);
}
public int socketDescriptor() {

View File

@ -29,8 +29,9 @@ class eslJNI {
public final static native boolean ESLevent_delHeader(long jarg1, ESLevent jarg1_, String jarg2);
public final static native String ESLevent_firstHeader(long jarg1, ESLevent jarg1_);
public final static native String ESLevent_nextHeader(long jarg1, ESLevent jarg1_);
public final static native long new_ESLconnection__SWIG_0(String jarg1, String jarg2, String jarg3);
public final static native long new_ESLconnection__SWIG_1(int jarg1);
public final static native long new_ESLconnection__SWIG_0(String jarg1, String jarg2, String jarg3, String jarg4);
public final static native long new_ESLconnection__SWIG_1(String jarg1, String jarg2, String jarg3);
public final static native long new_ESLconnection__SWIG_2(int jarg1);
public final static native void delete_ESLconnection(long jarg1);
public final static native int ESLconnection_socketDescriptor(long jarg1, ESLconnection jarg1_);
public final static native int ESLconnection_connected(long jarg1, ESLconnection jarg1_);

View File

@ -2162,6 +2162,36 @@ static const char *swig_ESLevent_base_names[] = {0};
static swig_lua_class _wrap_class_ESLevent = { "ESLevent", &SWIGTYPE_p_ESLevent,_wrap_new_ESLevent, swig_delete_ESLevent, swig_ESLevent_methods, swig_ESLevent_attributes, swig_ESLevent_bases, swig_ESLevent_base_names };
static int _wrap_new_ESLconnection__SWIG_0(lua_State* L) {
int SWIG_arg = -1;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
SWIG_check_num_args("ESLconnection",4,4)
if(!lua_isstring(L,1)) SWIG_fail_arg("ESLconnection",1,"char const *");
if(!lua_isstring(L,2)) SWIG_fail_arg("ESLconnection",2,"char const *");
if(!lua_isstring(L,3)) SWIG_fail_arg("ESLconnection",3,"char const *");
if(!lua_isstring(L,4)) SWIG_fail_arg("ESLconnection",4,"char const *");
arg1 = (char *)lua_tostring(L, 1);
arg2 = (char *)lua_tostring(L, 2);
arg3 = (char *)lua_tostring(L, 3);
arg4 = (char *)lua_tostring(L, 4);
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
SWIG_arg=0;
SWIG_NewPointerObj(L,result,SWIGTYPE_p_ESLconnection,1); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_new_ESLconnection__SWIG_1(lua_State* L) {
int SWIG_arg = -1;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
@ -2188,7 +2218,7 @@ fail:
}
static int _wrap_new_ESLconnection__SWIG_1(lua_State* L) {
static int _wrap_new_ESLconnection__SWIG_2(lua_State* L) {
int SWIG_arg = -1;
int arg1 ;
ESLconnection *result = 0 ;
@ -2211,8 +2241,8 @@ fail:
static int _wrap_new_ESLconnection(lua_State* L) {
int argc;
int argv[4]={
1,2,3,4
int argv[5]={
1,2,3,4,5
};
argc = lua_gettop(L);
@ -2222,7 +2252,7 @@ static int _wrap_new_ESLconnection(lua_State* L) {
_v = lua_isnumber(L,argv[0]);
}
if (_v) {
return _wrap_new_ESLconnection__SWIG_1(L);
return _wrap_new_ESLconnection__SWIG_2(L);
}
}
if (argc == 3) {
@ -2239,7 +2269,31 @@ static int _wrap_new_ESLconnection(lua_State* L) {
_v = lua_isstring(L,argv[2]);
}
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(L);
return _wrap_new_ESLconnection__SWIG_1(L);
}
}
}
}
if (argc == 4) {
int _v;
{
_v = lua_isstring(L,argv[0]);
}
if (_v) {
{
_v = lua_isstring(L,argv[1]);
}
if (_v) {
{
_v = lua_isstring(L,argv[2]);
}
if (_v) {
{
_v = lua_isstring(L,argv[3]);
}
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(L);
}
}
}
}

View File

@ -245,10 +245,13 @@ class ESLPINVOKE {
public static extern string ESLevent_nextHeader(HandleRef jarg1);
[DllImport("ESL", EntryPoint="CSharp_new_ESLconnection__SWIG_0")]
public static extern IntPtr new_ESLconnection__SWIG_0(string jarg1, string jarg2, string jarg3);
public static extern IntPtr new_ESLconnection__SWIG_0(string jarg1, string jarg2, string jarg3, string jarg4);
[DllImport("ESL", EntryPoint="CSharp_new_ESLconnection__SWIG_1")]
public static extern IntPtr new_ESLconnection__SWIG_1(int jarg1);
public static extern IntPtr new_ESLconnection__SWIG_1(string jarg1, string jarg2, string jarg3);
[DllImport("ESL", EntryPoint="CSharp_new_ESLconnection__SWIG_2")]
public static extern IntPtr new_ESLconnection__SWIG_2(int jarg1);
[DllImport("ESL", EntryPoint="CSharp_delete_ESLconnection")]
public static extern void delete_ESLconnection(HandleRef jarg1);

View File

@ -38,10 +38,13 @@ public class ESLconnection : IDisposable {
}
}
public ESLconnection(string host, string port, string password) : this(ESLPINVOKE.new_ESLconnection__SWIG_0(host, port, password), true) {
public ESLconnection(string host, string port, string user, string password) : this(ESLPINVOKE.new_ESLconnection__SWIG_0(host, port, user, password), true) {
}
public ESLconnection(int socket) : this(ESLPINVOKE.new_ESLconnection__SWIG_1(socket), true) {
public ESLconnection(string host, string port, string password) : this(ESLPINVOKE.new_ESLconnection__SWIG_1(host, port, password), true) {
}
public ESLconnection(int socket) : this(ESLPINVOKE.new_ESLconnection__SWIG_2(socket), true) {
}
public int socketDescriptor() {

View File

@ -542,7 +542,25 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_ESLevent_nextHeader(void * jarg1) {
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_0(char * jarg1, char * jarg2, char * jarg3) {
SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_0(char * jarg1, char * jarg2, char * jarg3, char * jarg4) {
void * jresult ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
arg4 = (char *)jarg4;
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_1(char * jarg1, char * jarg2, char * jarg3) {
void * jresult ;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
@ -558,7 +576,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_0(char * jarg1, cha
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_1(int jarg1) {
SWIGEXPORT void * SWIGSTDCALL CSharp_new_ESLconnection__SWIG_2(int jarg1) {
void * jresult ;
int arg1 ;
ESLconnection *result = 0 ;

View File

@ -2561,6 +2561,68 @@ XS(_wrap_ESLevent_nextHeader) {
XS(_wrap_new_ESLconnection__SWIG_0) {
{
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
int res4 ;
char *buf4 = 0 ;
int alloc4 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 4) || (items > 4)) {
SWIG_croak("Usage: new_ESLconnection(host,port,user,password);");
}
res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_ESLconnection" "', argument " "1"" of type '" "char const *""'");
}
arg1 = reinterpret_cast< char * >(buf1);
res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_ESLconnection" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "new_ESLconnection" "', argument " "3"" of type '" "char const *""'");
}
arg3 = reinterpret_cast< char * >(buf3);
res4 = SWIG_AsCharPtrAndSize(ST(3), &buf4, NULL, &alloc4);
if (!SWIG_IsOK(res4)) {
SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "new_ESLconnection" "', argument " "4"" of type '" "char const *""'");
}
arg4 = reinterpret_cast< char * >(buf4);
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ESLconnection, SWIG_OWNER | SWIG_SHADOW); argvi++ ;
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
XSRETURN(argvi);
fail:
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
SWIG_croak_null();
}
}
XS(_wrap_new_ESLconnection__SWIG_1) {
{
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
@ -2611,7 +2673,7 @@ XS(_wrap_new_ESLconnection__SWIG_0) {
}
XS(_wrap_new_ESLconnection__SWIG_1) {
XS(_wrap_new_ESLconnection__SWIG_2) {
{
int arg1 ;
ESLconnection *result = 0 ;
@ -2703,11 +2765,57 @@ XS(_wrap_new_ESLconnection) {
}
check_2:
if (items == 4) {
SWIG_TypeRank _ranki = 0;
SWIG_TypeRank _rankm = 0;
SWIG_TypeRank _pi = 1;
int _v = 0;
{
int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_3;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
{
int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_3;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
{
int res = SWIG_AsCharPtrAndSize(ST(2), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_3;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
{
int res = SWIG_AsCharPtrAndSize(ST(3), 0, NULL, 0);
_v = SWIG_CheckState(res);
}
if (!_v) goto check_3;
_ranki += _v*_pi;
_rankm += _pi;
_pi *= SWIG_MAXCASTRANK;
if (!_index || (_ranki < _rank)) {
_rank = _ranki; _index = 3;
if (_rank == _rankm) goto dispatch;
}
}
check_3:
dispatch:
switch(_index) {
case 1:
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_ESLconnection__SWIG_1); return;
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_ESLconnection__SWIG_2); return;
case 2:
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_ESLconnection__SWIG_1); return;
case 3:
++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_ESLconnection__SWIG_0); return;
}
}

View File

@ -112,11 +112,12 @@ class ESLevent {
class ESLconnection {
public $_cPtr=null;
function __construct($host_or_socket,$port=null,$password=null) {
function __construct($host_or_socket,$port=null,$user_or_password=null,$password=null) {
switch (func_num_args()) {
case 1: $r=new_ESLconnection($host_or_socket); break;
case 2: $r=new_ESLconnection($host_or_socket,$port); break;
default: $r=new_ESLconnection($host_or_socket,$port,$password);
case 3: $r=new_ESLconnection($host_or_socket,$port,$user_or_password); break;
default: $r=new_ESLconnection($host_or_socket,$port,$user_or_password,$password);
}
$this->_cPtr=$r;
}

View File

@ -1706,6 +1706,53 @@ fail:
ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection__SWIG_0) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
zval **args[4];
SWIG_ResetError();
if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_array_ex(4, args) != SUCCESS) {
WRONG_PARAM_COUNT;
}
/*@SWIG:/usr/local/share/swig/1.3.35/php4/utils.i,26,CONVERT_STRING_IN@*/
convert_to_string_ex(args[0]);
arg1 = (char *) Z_STRVAL_PP(args[0]);
/*@SWIG@*/;
/*@SWIG:/usr/local/share/swig/1.3.35/php4/utils.i,26,CONVERT_STRING_IN@*/
convert_to_string_ex(args[1]);
arg2 = (char *) Z_STRVAL_PP(args[1]);
/*@SWIG@*/;
/*@SWIG:/usr/local/share/swig/1.3.35/php4/utils.i,26,CONVERT_STRING_IN@*/
convert_to_string_ex(args[2]);
arg3 = (char *) Z_STRVAL_PP(args[2]);
/*@SWIG@*/;
/*@SWIG:/usr/local/share/swig/1.3.35/php4/utils.i,26,CONVERT_STRING_IN@*/
convert_to_string_ex(args[3]);
arg4 = (char *) Z_STRVAL_PP(args[3]);
/*@SWIG@*/;
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
{
SWIG_SetPointerZval(return_value, (void *)result, SWIGTYPE_p_ESLconnection, 1);
}
return;
fail:
zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());
}
ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection__SWIG_1) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
@ -1745,7 +1792,7 @@ fail:
}
ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection__SWIG_1) {
ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection__SWIG_2) {
int arg1 ;
ESLconnection *result = 0 ;
zval **args[1];
@ -1773,7 +1820,7 @@ fail:
ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection) {
int argc;
zval **argv[3];
zval **argv[4];
argc = ZEND_NUM_ARGS();
zend_get_parameters_array_ex(argc,argv);
@ -1781,7 +1828,7 @@ ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection) {
int _v;
_v = (Z_TYPE_PP(argv[0]) == IS_LONG);
if (_v) {
return _wrap_new_ESLconnection__SWIG_1(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return _wrap_new_ESLconnection__SWIG_2(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}
if (argc == 3) {
@ -1792,7 +1839,23 @@ ZEND_NAMED_FUNCTION(_wrap_new_ESLconnection) {
if (_v) {
_v = (Z_TYPE_PP(argv[2]) == IS_STRING);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return _wrap_new_ESLconnection__SWIG_1(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}
}
}
if (argc == 4) {
int _v;
_v = (Z_TYPE_PP(argv[0]) == IS_STRING);
if (_v) {
_v = (Z_TYPE_PP(argv[1]) == IS_STRING);
if (_v) {
_v = (Z_TYPE_PP(argv[2]) == IS_STRING);
if (_v) {
_v = (Z_TYPE_PP(argv[3]) == IS_STRING);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}
}
}

View File

@ -3521,6 +3521,67 @@ SWIGINTERN PyObject *ESLevent_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObj
}
SWIGINTERN PyObject *_wrap_new_ESLconnection__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
int res4 ;
char *buf4 = 0 ;
int alloc4 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OOOO:new_ESLconnection",&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_ESLconnection" "', argument " "1"" of type '" "char const *""'");
}
arg1 = reinterpret_cast< char * >(buf1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_ESLconnection" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "new_ESLconnection" "', argument " "3"" of type '" "char const *""'");
}
arg3 = reinterpret_cast< char * >(buf3);
res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
if (!SWIG_IsOK(res4)) {
SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "new_ESLconnection" "', argument " "4"" of type '" "char const *""'");
}
arg4 = reinterpret_cast< char * >(buf4);
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ESLconnection, SWIG_POINTER_NEW | 0 );
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return resultobj;
fail:
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return NULL;
}
SWIGINTERN PyObject *_wrap_new_ESLconnection__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
@ -3569,7 +3630,7 @@ fail:
}
SWIGINTERN PyObject *_wrap_new_ESLconnection__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
SWIGINTERN PyObject *_wrap_new_ESLconnection__SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
int arg1 ;
ESLconnection *result = 0 ;
@ -3593,12 +3654,12 @@ fail:
SWIGINTERN PyObject *_wrap_new_ESLconnection(PyObject *self, PyObject *args) {
int argc;
PyObject *argv[4];
PyObject *argv[5];
int ii;
if (!PyTuple_Check(args)) SWIG_fail;
argc = (int)PyObject_Length(args);
for (ii = 0; (ii < argc) && (ii < 3); ii++) {
for (ii = 0; (ii < argc) && (ii < 4); ii++) {
argv[ii] = PyTuple_GET_ITEM(args,ii);
}
if (argc == 1) {
@ -3608,7 +3669,7 @@ SWIGINTERN PyObject *_wrap_new_ESLconnection(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_ESLconnection__SWIG_1(self, args);
return _wrap_new_ESLconnection__SWIG_2(self, args);
}
}
if (argc == 3) {
@ -3622,7 +3683,27 @@ SWIGINTERN PyObject *_wrap_new_ESLconnection(PyObject *self, PyObject *args) {
int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(self, args);
return _wrap_new_ESLconnection__SWIG_1(self, args);
}
}
}
}
if (argc == 4) {
int _v;
int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[3], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(self, args);
}
}
}
}
@ -3631,6 +3712,7 @@ SWIGINTERN PyObject *_wrap_new_ESLconnection(PyObject *self, PyObject *args) {
fail:
SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'new_ESLconnection'.\n"
" Possible C/C++ prototypes are:\n"
" ESLconnection(char const *,char const *,char const *,char const *)\n"
" ESLconnection(char const *,char const *,char const *)\n"
" ESLconnection(int)\n");
return NULL;

View File

@ -2643,6 +2643,65 @@ swig_class cESLconnection;
SWIGINTERN VALUE
_wrap_new_ESLconnection__SWIG_0(int argc, VALUE *argv, VALUE self) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
char *arg4 = (char *) 0 ;
ESLconnection *result = 0 ;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
int res4 ;
char *buf4 = 0 ;
int alloc4 = 0 ;
if ((argc < 4) || (argc > 4)) {
rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)",argc); SWIG_fail;
}
res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","ESLconnection", 1, argv[0] ));
}
arg1 = reinterpret_cast< char * >(buf1);
res2 = SWIG_AsCharPtrAndSize(argv[1], &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "char const *","ESLconnection", 2, argv[1] ));
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_AsCharPtrAndSize(argv[2], &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), Ruby_Format_TypeError( "", "char const *","ESLconnection", 3, argv[2] ));
}
arg3 = reinterpret_cast< char * >(buf3);
res4 = SWIG_AsCharPtrAndSize(argv[3], &buf4, NULL, &alloc4);
if (!SWIG_IsOK(res4)) {
SWIG_exception_fail(SWIG_ArgError(res4), Ruby_Format_TypeError( "", "char const *","ESLconnection", 4, argv[3] ));
}
arg4 = reinterpret_cast< char * >(buf4);
result = (ESLconnection *)new ESLconnection((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);DATA_PTR(self) = result;
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return self;
fail:
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
if (alloc4 == SWIG_NEWOBJ) delete[] buf4;
return Qnil;
}
SWIGINTERN VALUE
_wrap_new_ESLconnection__SWIG_1(int argc, VALUE *argv, VALUE self) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
@ -2707,7 +2766,7 @@ _wrap_ESLconnection_allocate(VALUE self) {
SWIGINTERN VALUE
_wrap_new_ESLconnection__SWIG_1(int argc, VALUE *argv, VALUE self) {
_wrap_new_ESLconnection__SWIG_2(int argc, VALUE *argv, VALUE self) {
int arg1 ;
ESLconnection *result = 0 ;
int val1 ;
@ -2731,11 +2790,11 @@ fail:
SWIGINTERN VALUE _wrap_new_ESLconnection(int nargs, VALUE *args, VALUE self) {
int argc;
VALUE argv[3];
VALUE argv[4];
int ii;
argc = nargs;
if (argc > 3) SWIG_fail;
if (argc > 4) SWIG_fail;
for (ii = 0; (ii < argc); ++ii) {
argv[ii] = args[ii];
}
@ -2746,7 +2805,7 @@ SWIGINTERN VALUE _wrap_new_ESLconnection(int nargs, VALUE *args, VALUE self) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_ESLconnection__SWIG_1(nargs, args, self);
return _wrap_new_ESLconnection__SWIG_2(nargs, args, self);
}
}
if (argc == 3) {
@ -2760,14 +2819,35 @@ SWIGINTERN VALUE _wrap_new_ESLconnection(int nargs, VALUE *args, VALUE self) {
int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(nargs, args, self);
return _wrap_new_ESLconnection__SWIG_1(nargs, args, self);
}
}
}
}
if (argc == 4) {
int _v;
int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[1], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[2], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsCharPtrAndSize(argv[3], 0, NULL, 0);
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_ESLconnection__SWIG_0(nargs, args, self);
}
}
}
}
}
fail:
Ruby_Format_OverloadedError( argc, 3, "ESLconnection.new",
Ruby_Format_OverloadedError( argc, 4, "ESLconnection.new",
" ESLconnection.new(char const *host, char const *port, char const *user, char const *password)\n"
" ESLconnection.new(char const *host, char const *port, char const *password)\n"
" ESLconnection.new(int socket)\n");

View File

@ -580,7 +580,7 @@ ESL_DECLARE(esl_status_t) esl_listen(const char *host, esl_port_t port, esl_list
}
ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, esl_port_t port, const char *password)
ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, esl_port_t port, const char *user, const char *password)
{
struct hostent *result;
@ -651,7 +651,12 @@ ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, es
goto fail;
}
snprintf(sendbuf, sizeof(sendbuf), "auth %s\n\n", password);
if (esl_strlen_zero(user)) {
snprintf(sendbuf, sizeof(sendbuf), "auth %s\n\n", password);
} else {
snprintf(sendbuf, sizeof(sendbuf), "userauth %s:%s\n\n", user, password);
}
esl_send(handle, sendbuf);

View File

@ -14,7 +14,15 @@ ESLconnection::ESLconnection(const char *host, const char *port, const char *pas
connection_construct_common();
int x_port = atoi(port);
esl_connect(&handle, host, x_port, password);
esl_connect(&handle, host, x_port, NULL, password);
}
ESLconnection::ESLconnection(const char *host, const char *port, const char *user, const char *password)
{
connection_construct_common();
int x_port = atoi(port);
esl_connect(&handle, host, x_port, user, password);
}

View File

@ -379,9 +379,10 @@ ESL_DECLARE(esl_status_t) esl_sendevent(esl_handle_t *handle, esl_event_t *event
\param handle Handle to connect
\param host Host to be connected
\param port Port to be connected
\param password FreeSWITCH server username (optional)
\param password FreeSWITCH server password
*/
ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, esl_port_t port, const char *password);
ESL_DECLARE(esl_status_t) esl_connect(esl_handle_t *handle, const char *host, esl_port_t port, const char *user, const char *password);
/*!
\brief Disconnect a handle
\param handle Handle to be disconnected

View File

@ -72,6 +72,7 @@ class ESLconnection {
private:
esl_handle_t handle;
public:
ESLconnection(const char *host, const char *port, const char *user, const char *password);
ESLconnection(const char *host, const char *port, const char *password);
ESLconnection(int socket);
virtual ~ESLconnection();

View File

@ -7,7 +7,7 @@ int main(void)
{
esl_handle_t handle = {{0}};
esl_connect(&handle, "localhost", 8021, "ClueCon");
esl_connect(&handle, "localhost", 8021, NULL, "ClueCon");
esl_send_recv(&handle, "api status\n\n");