+void friend_timeout(struct friend *friend)
+{
+ if (friend->state == STATE_PINGED) {
+ friend->state = STATE_OFFLINE;
+ }
+}
+
+void friend_got_message(struct friend *friend, char *buffer, size_t len)
+{
+ if (len >= 4 && !strncmp(buffer, "PING", 4)) {
+ friend->state = STATE_ONLINE;
+ pong(friend);
+ } else if (len >= 4 && !strncmp(buffer, "PONG", 4)) {
+ friend->state = STATE_ONLINE;
+ }
+}
+
+static void friend_list(gchar **args, GSocketAddress *address);
+static void friend_add(gchar **args, GSocketAddress *address);
+
+struct menu_item cmds[] = {
+ { "list", friend_list },
+ { "add", friend_add },
+};
+
+void friend_cmd(gchar **args, GSocketAddress *address)
+{
+ int i;
+ if (args[1] == NULL)
+ return;
+ for (i = 0; i < sizeof(cmds)/sizeof(cmds[0]); i++) {
+ if (!strcmp(args[1], cmds[i].cmd)) {
+ cmds[i].func(args, address);
+ }
+ }
+}
+
+void friend_init(void)
+{
+ struct menu_item *mi;
+ mi = g_malloc(sizeof(*mi));
+ mi->cmd = "friend";
+ mi->func = friend_cmd;
+ menu_add(mi);
+}
+