Search command_list to get notification node.
If the command is an action command, the type may be "action" or
"support".
If the command is a parameter command, the type may be either
"support", "query" or "set".
---
gatchat/gatserver.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 829dc1d..bea51f5 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -231,10 +231,63 @@ static gboolean is_extended_character(const char c)
}
}
+static GAtServerRequestType get_command_type(char *buf, struct at_command *node)
+{
+ GAtServerRequestType type = G_AT_SERVER_REQUEST_TYPE_NONE;
+ char *prefix = node->prefix;
+ GAtServerCommandType cmd_type = node->type;
+
+ buf += strlen(prefix);
+
+ if (cmd_type == G_AT_SERVER_COMMAND_TYPE_ACTION) {
+ if (buf[0] == '=' && buf[1] == '?')
+ type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
+ else if (buf[0] == '?')
+ type = G_AT_SERVER_REQUEST_TYPE_NONE;
+ else
+ type = G_AT_SERVER_REQUEST_TYPE_ACTION;
+ } else {
+ if (buf[0] == '=' && buf[1] == '?')
+ type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
+ else if (buf[0] == '?')
+ type = G_AT_SERVER_REQUEST_TYPE_QUERY;
+ else {
+ /* Two cases:
+ * A valid basic command followed by digits.
+ * If no digit follows, zero is assumed.
+ * A valid extended command followed by '='.
+ */
+ if (is_basic_command_prefix(prefix))
+ type = G_AT_SERVER_REQUEST_TYPE_SET;
+ else if (is_extended_command_prefix(*prefix) &&
+ buf[0] == '=')
+ type = G_AT_SERVER_REQUEST_TYPE_SET;
+ }
+ }
+
+ return type;
+}
+
static GAtServerResult at_notify_callback(GAtServer *server, char *command,
char *prefix)
{
int res = G_AT_SERVER_RESULT_ERROR;
+ struct at_command *node;
+
+ node = g_hash_table_lookup(server->command_list, prefix);
+ if (node && node->notify) {
+ GAtServerRequestType type;
+ GAtResult result;
+
+ type = get_command_type(command, node);
+ if (type == G_AT_SERVER_REQUEST_TYPE_NONE)
+ return res;
+
+ result.lines = g_slist_prepend(NULL, command);
+ result.final_or_pdu = 0;
+
+ res = node->notify(type, &result, node->user_data);
+ }
return res;
}
--
1.6.6.1