Merge pull request #89 in FS/freeswitch from ~TMK/freeswitch:master to master
* commit 'f5f6d15709427a1f8125b538fd4f753188bb3e16': add command 'action' with types 'reboot', 'reset', 'dialeddel', 'misseddel', 'receiveddel' Fix url encoding for snom remote commands (required to make # key work)
This commit is contained in:
commit
8b1fad813b
|
@ -116,8 +116,10 @@ SWITCH_STANDARD_API(snom_command_api_function)
|
|||
{
|
||||
int argc;
|
||||
long httpRes = 0;
|
||||
char *key = NULL;
|
||||
char *url = NULL;
|
||||
char *argv[5] = { 0 };
|
||||
char host[32];
|
||||
char *argdata = NULL;
|
||||
char *userpwd = NULL;
|
||||
char *apiresp = NULL;
|
||||
|
@ -135,16 +137,15 @@ SWITCH_STANDARD_API(snom_command_api_function)
|
|||
goto end;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[1],"key")) {
|
||||
stream->write_function(stream, "-ERR only KEY command allowed at the moment\n");
|
||||
if (strcasecmp(argv[1],"key") && strcasecmp(argv[1],"action")) {
|
||||
stream->write_function(stream, "-ERR only key or action commands allowed at the moment\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (switch_inet_pton(AF_INET, argv[0], &ip)) {
|
||||
url = switch_mprintf("http://%s/command.htm?%s=%s",argv[0],argv[1],argv[2]);
|
||||
strncpy(host, argv[0], sizeof(host));
|
||||
} else {
|
||||
char *sql = NULL;
|
||||
char buf[32];
|
||||
char *ret = NULL;
|
||||
switch_cache_db_handle_t *db = NULL;
|
||||
switch_stream_handle_t apistream = { 0 };
|
||||
|
@ -173,7 +174,7 @@ SWITCH_STANDARD_API(snom_command_api_function)
|
|||
|
||||
sql = switch_mprintf("select network_ip from registrations where url = '%s'", apiresp);
|
||||
|
||||
ret = switch_cache_db_execute_sql2str(db, sql, buf, sizeof(buf), NULL);
|
||||
ret = switch_cache_db_execute_sql2str(db, sql, host, sizeof(host), NULL);
|
||||
switch_safe_free(sql);
|
||||
switch_cache_db_release_db_handle(&db);
|
||||
|
||||
|
@ -181,11 +182,34 @@ SWITCH_STANDARD_API(snom_command_api_function)
|
|||
stream->write_function(stream, "%s", "-ERR Query '%s' failed!\n", sql);
|
||||
goto end;
|
||||
}
|
||||
|
||||
url = switch_mprintf("http://%s/command.htm?%s=%s",buf,argv[1],argv[2]);
|
||||
}
|
||||
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
if (0 == strcasecmp(argv[1],"key")) {
|
||||
key = curl_easy_escape(curl_handle, argv[2], 0);
|
||||
url = switch_mprintf("http://%s/command.htm?key=%s", host, key);
|
||||
curl_free(key);
|
||||
}
|
||||
|
||||
if (0 == strcasecmp(argv[1],"action")) {
|
||||
if (0 == strcasecmp(argv[2],"reboot")) {
|
||||
url = switch_mprintf("http://%s/advanced_update.htm?reboot=Reboot", host);
|
||||
} else if (0 == strcasecmp(argv[2],"reset")) {
|
||||
url = switch_mprintf("http://%s/advanced_update.htm?reset=Reset", host);
|
||||
} else if (0 == strcasecmp(argv[2],"dialeddel")) {
|
||||
url = switch_mprintf("http://%s/index.htm?dialeddel=0", host);
|
||||
} else if (0 == strcasecmp(argv[2],"misseddel")) {
|
||||
url = switch_mprintf("http://%s/index.htm?misseddel=0", host);
|
||||
} else if (0 == strcasecmp(argv[2],"receiveddel")) {
|
||||
url = switch_mprintf("http://%s/index.htm?receiveddel=0", host);
|
||||
} else {
|
||||
stream->write_function(stream, "-ERR action '%s' not supported (supported actions are reboot, reset, dialeddel, misseddel, receiveddel)\n", argv[2]);
|
||||
curl_easy_cleanup(curl_handle);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, curl_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
||||
|
|
Loading…
Reference in New Issue