static char *MARKER = "X";
-static void set_perm(const char *str, switch_event_t **event)
+static void set_perm(const char *str, switch_event_t **event, switch_bool_t add)
{
char delim = ',';
char *cur, *next;
}
}
- switch_event_create(event, SWITCH_EVENT_REQUEST_PARAMS);
-
+ if (event && !*event) {
+ switch_event_create(event, SWITCH_EVENT_REQUEST_PARAMS);
+ }
+
if (!zstr(str)) {
edup = strdup(str);
switch_assert(edup);
*next++ = '\0';
}
- switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, cur, MARKER);
-
+ if (add) {
+ switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, cur, MARKER);
+ } else {
+ switch_event_del_header(*event, cur);
+ }
+
cur = next;
}
}
- set_perm(allowed_methods, &jsock->allowed_methods);
- set_perm(allowed_jsapi, &jsock->allowed_jsapi);
- set_perm(allowed_fsapi, &jsock->allowed_fsapi);
- set_perm(allowed_event_channels, &jsock->allowed_event_channels);
+ set_perm(allowed_methods, &jsock->allowed_methods, SWITCH_TRUE);
+ set_perm(allowed_jsapi, &jsock->allowed_jsapi, SWITCH_TRUE);
+ set_perm(allowed_fsapi, &jsock->allowed_fsapi, SWITCH_TRUE);
+ set_perm(allowed_event_channels, &jsock->allowed_event_channels, SWITCH_TRUE);
switch_event_add_header_string(jsock->allowed_methods, SWITCH_STACK_BOTTOM, "login", MARKER);
}
+static switch_status_t add_perm(const char *sessid, const char *type, const char *value, switch_bool_t add)
+{
+ jsock_t *jsock = NULL;
+ switch_status_t status = SWITCH_STATUS_FALSE;
+
+ if (type && value && (jsock = get_jsock(sessid))) {
+ status = SWITCH_STATUS_SUCCESS;
+
+ if (!strcmp(type, "methods")) {
+ set_perm(value, &jsock->allowed_methods, add);
+ } else if (!strcmp(type, "jsapi")) {
+ set_perm(value, &jsock->allowed_jsapi, add);
+ } else if (!strcmp(type, "fsapi")) {
+ set_perm(value, &jsock->allowed_fsapi, add);
+ } else if (!strcmp(type, "event_channels")) {
+ set_perm(value, &jsock->allowed_event_channels, add);
+ } else {
+ status = SWITCH_STATUS_FALSE;
+ }
+
+ switch_thread_rwlock_unlock(jsock->rwlock);
+ }
+
+ return status;
+}
+
static void login_fire_custom_event(jsock_t *jsock, cJSON *params, int success, const char *result_txt)
{
switch_event_t *s_event;
"verto [status|xmlstatus|jsonstatus]\n"
"verto help\n"
"verto debug [0-10]\n"
+ "verto perm <sessid> <type> <value>\n"
"--------------------------------------------------------------------------------\n";
if (zstr(cmd)) {
if (!strcasecmp(argv[0], "help")) {
stream->write_function(stream, "%s", usage_string);
goto done;
+ } else if (!strcasecmp(argv[0], "perm")) {
+ status = add_perm(argv[1], argv[2], argv[3], SWITCH_TRUE);
+ if (status == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "+OK");
+ } else {
+ stream->write_function(stream, "-ERR");
+ }
+ status = SWITCH_STATUS_SUCCESS;
+ goto done;
+ } else if (!strcasecmp(argv[0], "noperm")) {
+ status = add_perm(argv[1], argv[2], argv[3], SWITCH_FALSE);
+ if (status == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "+OK");
+ } else {
+ stream->write_function(stream, "-ERR");
+ }
+ status = SWITCH_STATUS_SUCCESS;
+ goto done;
} else if (!strcasecmp(argv[0], "status")) {
func = cmd_status;
} else if (!strcasecmp(argv[0], "xmlstatus")) {