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 
43 #include "userinput.h"
44 
45 
46 
47 //
48 // This is the function called by lion library when there is an event.
49 // To demonstrate how to write code that calls different places depending on
50 // the type of the object node, we split the logic here.
51 //
52 
53 
lion_userinput(lion_t * handle,void * user_data,int status,int size,char * line)54 int lion_userinput( lion_t *handle,
55 					void *user_data, int status, int size, char *line)
56 {
57 	object_t *node = (object_t *) user_data;  // Get our object struct
58 
59 
60 	// Basically, if we have no user_data node, and there for no object node
61 	// we just exit this function. This should never happen, since we always
62 	// pass a valid node of our own. But just incase, instead of core dumping..
63 
64 	if (!user_data)
65 		return 0;
66 
67 
68 	// Now, check the type of the object node, and call the appropriate
69 	// function.
70 
71 	switch (node->type) {
72 
73 	case OBJECT_TYPE_NONE:   // Unknown type, shouldn't happen, so do nothing.
74 		return 0;
75 
76 	case OBJECT_TYPE_LISTEN: // Our master listening socket.
77 		return listen_userinput( handle, user_data, status, size, line);
78 
79 	case OBJECT_TYPE_UNREGISTERED: // An "unregistered" connection.
80 		return unreg_userinput( handle, user_data, status, size, line);
81 
82 	case OBJECT_TYPE_REGISTERED: // An "registered" connection.
83 		return reg_userinput( handle, user_data, status, size, line);
84 
85 	}
86 
87 	// NOT REACHED
88 	return 0; // Avoid warning.
89 }
90 
91 
92