Add command menu for messages received from loopback.
[cascardo/f2fchat.git] / menu.c
diff --git a/menu.c b/menu.c
new file mode 100644 (file)
index 0000000..6796be3
--- /dev/null
+++ b/menu.c
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "menu.h"
+
+#include <gio/gio.h>
+
+static GList *menu = NULL;
+
+void menu_add(struct menu_item *mi)
+{
+       menu = g_list_append(menu, mi);
+}
+
+void menu_run(gchar **args, GSocketAddress *address)
+{
+       GList *l;
+       for (l = g_list_first(menu); l != NULL; l = g_list_next(l)) {
+               struct menu_item *mi = l->data;
+               if (!strcmp(args[0], mi->cmd)) {
+                       mi->func(args, address);
+                       break;
+               }
+       }
+}