1
2 /*-
3 *
4 * New BSD License 2006
5 *
6 * Copyright (c) 2006, Jorgen Lundman
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met:
12 *
13 * 1 Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2 Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * 3 Neither the name of the stuff nor the names of its contributors
20 * may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37 #include <stdio.h>
38
39 #include "lion.h"
40
41 #include "object.h"
42 #include "command.h"
43
44
45
46
47
48
command_who_sub(object_t * node,void * arg1,void * arg2)49 int command_who_sub(object_t *node, void *arg1, void*arg2)
50 {
51 static object_t *user;
52
53 if (!arg1)
54 return 0; // 0 to stop iterating.
55
56 user = (object_t *) arg1;
57
58
59 switch(node->type) {
60
61 case OBJECT_TYPE_NONE:
62 lion_printf(user->handle, "[unknown-type]\r\n");
63 break;
64
65 case OBJECT_TYPE_LISTEN:
66 lion_printf(user->handle, "[ listening ]\r\n");
67 break;
68 case OBJECT_TYPE_UNREGISTERED:
69 lion_printf(user->handle, "[unregistered]\r\n");
70 break;
71 case OBJECT_TYPE_REGISTERED:
72 lion_printf(user->handle, "[ registered ] %s\r\n", node->username);
73 break;
74 }
75
76
77 return 1; // 1 to keep iterating
78
79 }
80
81
82 //
83 // Iterate the list of objects, and send them to the user.
84 //
command_who(object_t * node)85 void command_who(object_t *node)
86 {
87
88 object_find(command_who_sub, (void *)node, NULL);
89
90 }
91