[asterisk-commits] kharwell: branch kharwell/stasis_aoc_event r392860 - /team/kharwell/stasis_ao...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 25 13:54:45 CDT 2013
Author: kharwell
Date: Tue Jun 25 13:54:43 2013
New Revision: 392860
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392860
Log:
made sure event output looked correct, fixed a couple small bugs during testing
Modified:
team/kharwell/stasis_aoc_event/main/aoc.c
team/kharwell/stasis_aoc_event/main/manager.c
Modified: team/kharwell/stasis_aoc_event/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis_aoc_event/main/aoc.c?view=diff&rev=392860&r1=392859&r2=392860
==============================================================================
--- team/kharwell/stasis_aoc_event/main/aoc.c (original)
+++ team/kharwell/stasis_aoc_event/main/aoc.c Tue Jun 25 13:54:43 2013
@@ -1702,8 +1702,16 @@
static void json_to_ast_str(struct ast_json *obj, const char *key,
struct ast_str **res);
-static void json_to_ast_str_key(struct ast_json *obj, const char* key,
- const char *parent_key, struct ast_str **res)
+static void json_array_with_key(struct ast_json *obj, const char* key,
+ size_t index, struct ast_str **res)
+{
+ struct ast_str *key_str = ast_str_alloca(64);
+ ast_str_set(&key_str, 0, "%s(%zu)", key, index);
+ json_to_ast_str(obj, ast_str_buffer(key_str), res);
+}
+
+static void json_obj_with_key(struct ast_json *obj, const char* key,
+ const char *parent_key, struct ast_str **res)
{
if (parent_key) {
struct ast_str *key_str = ast_str_alloca(64);
@@ -1730,19 +1738,19 @@
return;
}
- if (ast_json_typeof(obj) != AST_JSON_ARRAY) {
+ if (ast_json_typeof(obj) == AST_JSON_ARRAY) {
size_t j;
for (j = 0; j < ast_json_array_size(obj); ++j) {
- json_to_ast_str_key(ast_json_array_get(obj, j),
- key, NULL, res);
+ json_array_with_key(ast_json_array_get(obj, j),
+ key, j, res);
}
return;
}
for (i = ast_json_object_iter(obj); i;
i = ast_json_object_iter_next(obj, i)) {
- json_to_ast_str_key(ast_json_object_iter_value(i),
- ast_json_object_iter_key(i), key, res);
+ json_obj_with_key(ast_json_object_iter_value(i),
+ ast_json_object_iter_key(i), key, res);
}
}
@@ -1753,14 +1761,13 @@
return res;
}
-static struct ast_manager_event_blob *aoc_to_ami(struct stasis_message *message)
+static struct ast_manager_event_blob *aoc_to_ami(struct stasis_message *message,
+ const char *event_name)
{
struct ast_channel_blob *obj = stasis_message_data(message);
RAII_VAR(struct ast_str *, channel, NULL, ast_free);
RAII_VAR(struct ast_str *, aoc, NULL, ast_free);
- const char *name;
-
- ast_log(LOG_VERBOSE, "ast_stasis_event - START\n");
+
if (!(channel = ast_manager_build_channel_state_string(
obj->snapshot))) {
return NULL;
@@ -1770,10 +1777,23 @@
return NULL;
}
- name = stasis_message_type_name(stasis_message_type(message));
- ast_log(LOG_VERBOSE, "ast_stasis_event - name = %s, channel = %s, \n\naoc = %s\n", name, ast_str_buffer(channel), ast_str_buffer(aoc));
- return ast_manager_event_blob_create(EVENT_FLAG_AOC, name, "%s%s",
+ return ast_manager_event_blob_create(EVENT_FLAG_AOC, event_name, "%s%s",
AS_OR(channel, ""), ast_str_buffer(aoc));
+}
+
+static struct ast_manager_event_blob *aoc_s_to_ami(struct stasis_message *message)
+{
+ return aoc_to_ami(message, "AOC-S");
+}
+
+static struct ast_manager_event_blob *aoc_d_to_ami(struct stasis_message *message)
+{
+ return aoc_to_ami(message, "AOC-D");
+}
+
+static struct ast_manager_event_blob *aoc_e_to_ami(struct stasis_message *message)
+{
+ return aoc_to_ami(message, "AOC-E");
}
struct stasis_message_type *aoc_s_type(void);
@@ -1782,39 +1802,20 @@
STASIS_MESSAGE_TYPE_DEFN(
aoc_s_type,
- .to_ami = aoc_to_ami);
+ .to_ami = aoc_s_to_ami);
STASIS_MESSAGE_TYPE_DEFN(
aoc_d_type,
- .to_ami = aoc_to_ami);
+ .to_ami = aoc_d_to_ami);
STASIS_MESSAGE_TYPE_DEFN(
aoc_e_type,
- .to_ami = aoc_to_ami);
+ .to_ami = aoc_e_to_ami);
int ast_aoc_manager_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan)
{
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
struct stasis_message_type *msg_type;
-
- RAII_VAR(struct ast_str *, aoc, NULL, ast_free);
- const char *blob_str;
- ast_log(LOG_VERBOSE, "ast_aoc_manager_event - START type = %d\n", decoded->msg_type);
-/*
-action: login
-username: kharwell
-secret: pass
-
-Action: AOCMessage
-Channel: SIP/102-00000000
-MsgType: e
-ChargeType: Currency
-CurrencyAmount: 16
-CurrencyName: USD
-CurrencyMultiplier: OneThousandth
-AOCBillingId: Normal
-ActionID: 1234
-*/
if (!decoded) {
return -1;
@@ -1838,12 +1839,6 @@
return 0;
}
- if (!blob) {
- ast_log(LOG_VERBOSE, "Why is BLOB NULL??..oh noes!\n");
- }
- aoc = json_obj_to_ast_str(blob); /* ast_manager_str_from_json_object(blob, NULL); */
- blob_str = ast_json_dump_string(blob/* , AST_JSON_PRETTY */);
- ast_log(LOG_VERBOSE, "ast_aoc_manager_event - bob the blob = %s\n\n AOCstuff = %s\n", blob_str, ast_str_buffer(aoc));
ast_channel_publish_blob(chan, msg_type, blob);
return 0;
}
@@ -1920,15 +1915,6 @@
STASIS_MESSAGE_TYPE_INIT(aoc_d_type);
STASIS_MESSAGE_TYPE_INIT(aoc_e_type);
- /* stasis_message_router_add(message_router, aoc_s_type(), */
- /* aoc_stasis_event, "AOC-S"); */
-
- /* stasis_message_router_add(message_router, aoc_d_type(), */
- /* aoc_stasis_event, "AOC-D"); */
-
- /* stasis_message_router_add(message_router, aoc_e_type(), */
- /* aoc_stasis_event, "AOC-E"); */
-
ast_register_atexit(aoc_shutdown);
return ast_cli_register_multiple(aoc_cli, ARRAY_LEN(aoc_cli));
}
Modified: team/kharwell/stasis_aoc_event/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis_aoc_event/main/manager.c?view=diff&rev=392860&r1=392859&r2=392860
==============================================================================
--- team/kharwell/stasis_aoc_event/main/manager.c (original)
+++ team/kharwell/stasis_aoc_event/main/manager.c Tue Jun 25 13:54:43 2013
@@ -4549,10 +4549,6 @@
ast_aoc_set_billing_id(decoded, _billingid);
ast_aoc_set_total_type(decoded, _totaltype);
- /* TODO: remove below used for tmp testing */
- ast_aoc_manager_event(decoded, chan);
- /* TODO: remove code before this */
-
if ((encoded = ast_aoc_encode(decoded, &encoded_size, NULL)) && !ast_indicate_data(chan, AST_CONTROL_AOC, encoded, encoded_size)) {
astman_send_ack(s, m, "AOC Message successfully queued on channel");
} else {
More information about the asterisk-commits
mailing list