int create_queue(struct ast_json* j_queue) { int ret; char* uuid; struct ast_json* j_tmp; if(j_queue == NULL) { return false; } j_tmp = ast_json_deep_copy(j_queue); uuid = gen_uuid(); ast_json_object_set(j_tmp, "uuid", ast_json_string_create(uuid)); ast_log(LOG_NOTICE, "Create queue. uuid[%s], name[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")), ast_json_string_get(ast_json_object_get(j_tmp, "name")) ); ret = db_insert("queue", j_tmp); AST_JSON_UNREF(j_tmp); if(ret == false) { ast_free(uuid); return false; } // send ami event j_tmp = get_queue(uuid); send_manager_evt_out_queue_create(j_tmp); AST_JSON_UNREF(j_tmp); return true; }
/*! \internal \brief convert multi object blob to ari json */ static struct ast_json *multi_user_event_to_json( struct stasis_message *message, const struct stasis_message_sanitizer *sanitize) { RAII_VAR(struct ast_json *, out, NULL, ast_json_unref); struct ast_multi_object_blob *multi = stasis_message_data(message); struct ast_json *blob = multi->blob; const struct timeval *tv = stasis_message_timestamp(message); enum stasis_user_multi_object_snapshot_type type; int i; out = ast_json_object_create(); if (!out) { return NULL; } ast_json_object_set(out, "type", ast_json_string_create("ChannelUserevent")); ast_json_object_set(out, "timestamp", ast_json_timeval(*tv, NULL)); ast_json_object_set(out, "eventname", ast_json_string_create(ast_json_string_get((ast_json_object_get(blob, "eventname"))))); ast_json_object_set(out, "userevent", ast_json_deep_copy(blob)); for (type = 0; type < STASIS_UMOS_MAX; ++type) { for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) { struct ast_json *json_object = NULL; char *name = NULL; void *snapshot = AST_VECTOR_GET(&multi->snapshots[type], i); switch (type) { case STASIS_UMOS_CHANNEL: json_object = ast_channel_snapshot_to_json(snapshot, sanitize); name = "channel"; break; case STASIS_UMOS_BRIDGE: json_object = ast_bridge_snapshot_to_json(snapshot, sanitize); name = "bridge"; break; case STASIS_UMOS_ENDPOINT: json_object = ast_endpoint_snapshot_to_json(snapshot, sanitize); name = "endpoint"; break; } if (json_object) { ast_json_object_set(out, name, json_object); } } } return ast_json_ref(out); }
/** * Create plan. * @param j_plan * @return */ bool create_plan(const struct ast_json* j_plan) { int ret; char* uuid; struct ast_json* j_tmp; char* tmp; if(j_plan == NULL) { return false; } j_tmp = ast_json_deep_copy(j_plan); uuid = gen_uuid(); ast_json_object_set(j_tmp, "uuid", ast_json_string_create(uuid)); tmp = get_utc_timestamp(); ast_json_object_set(j_tmp, "tm_create", ast_json_string_create(tmp)); ast_free(tmp); ast_log(LOG_NOTICE, "Create plan. uuid[%s], name[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")), ast_json_string_get(ast_json_object_get(j_tmp, "name"))? : "<unknown>" ); ret = db_insert("plan", j_tmp); AST_JSON_UNREF(j_tmp); if(ret == false) { ast_free(uuid); return false; } ast_log(LOG_VERBOSE, "Finished insert.\n"); // send ami event j_tmp = get_plan(uuid); ast_log(LOG_VERBOSE, "Check plan info. uuid[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")) ); ast_free(uuid); if(j_tmp == NULL) { ast_log(LOG_ERROR, "Could not get created plan info."); return false; } send_manager_evt_out_plan_create(j_tmp); AST_JSON_UNREF(j_tmp); return true; }
static struct ast_json *recording_to_json(struct stasis_message *message, const struct stasis_message_sanitizer *sanitize) { struct ast_channel_blob *channel_blob = stasis_message_data(message); struct ast_json *blob = channel_blob->blob; const char *state = ast_json_string_get(ast_json_object_get(blob, "state")); const char *type; if (!strcmp(state, "recording")) { type = "RecordingStarted"; } else if (!strcmp(state, "done") || !strcasecmp(state, "canceled")) { type = "RecordingFinished"; } else if (!strcmp(state, "failed")) { type = "RecordingFailed"; } else { return NULL; } return ast_json_pack("{s: s, s: o}", "type", type, "recording", ast_json_deep_copy(blob)); }
/** * Update plan * @param j_plan * @return */ bool update_plan(const struct ast_json* j_plan) { char* tmp; const char* tmp_const; char* sql; struct ast_json* j_tmp; int ret; char* uuid; if(j_plan == NULL) { return false; } j_tmp = ast_json_deep_copy(j_plan); if(j_tmp == NULL) { return false; } tmp_const = ast_json_string_get(ast_json_object_get(j_tmp, "uuid")); if(tmp_const == NULL) { ast_log(LOG_WARNING, "Could not get uuid.\n"); AST_JSON_UNREF(j_tmp); return false; } uuid = ast_strdup(tmp_const); tmp = get_utc_timestamp(); ast_json_object_set(j_tmp, "tm_update", ast_json_string_create(tmp)); ast_free(tmp); tmp = db_get_update_str(j_tmp); if(tmp == NULL) { ast_log(LOG_WARNING, "Could not get update str.\n"); AST_JSON_UNREF(j_tmp); ast_free(uuid); return false; } AST_JSON_UNREF(j_tmp); ast_asprintf(&sql, "update plan set %s where in_use=%d and uuid=\"%s\";", tmp, E_DL_USE_OK, uuid); ast_free(tmp); ret = db_exec(sql); ast_free(sql); if(ret == false) { ast_log(LOG_WARNING, "Could not update plan info. uuid[%s]\n", uuid); ast_free(uuid); return false; } j_tmp = get_plan(uuid); ast_free(uuid); if(j_tmp == NULL) { ast_log(LOG_WARNING, "Could not get updated plan info.\n"); return false; } send_manager_evt_out_plan_update(j_tmp); AST_JSON_UNREF(j_tmp); return true; }