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 
44 
45 
46 
47 //
48 // This is called from our userinput.c if the type of object is listen.
49 //
listen_userinput(lion_t * handle,void * user_data,int status,int size,char * line)50 int listen_userinput( lion_t *handle,
51 					void *user_data, int status, int size, char *line)
52 {
53 	object_t *node = (object_t *) user_data;  // Get our object struct
54 	object_t *newo = NULL;
55 
56 	// We should _always_ have a object node here, since we are only called
57 	// from userinput.c if we did have one. But, for sanity....
58 
59 	if (!node)
60 		return 0;
61 
62 
63 
64 
65 	// Check which event we got and process...
66 
67 	switch( status ) {
68 
69 
70 	case LION_CONNECTION_LOST:
71 		printf("Listening socket '%p' was lost: %d:%s\n", handle, size, line);
72 		break;
73 
74 	case LION_CONNECTION_CLOSED:
75 		printf("Listening socket '%p' was gracefully closed.\n", handle);
76 		break;
77 
78 	case LION_CONNECTION_NEW:
79 		printf("Listening socket '%p' has a new connection...\n", handle);
80 
81 
82 		// Get a new object container...
83 		newo = object_new();
84 
85 		// Set their type to unregistered. The connection messages goes there.
86 		newo->type = OBJECT_TYPE_UNREGISTERED;
87 
88 		// Accept the port
89 		newo->handle = lion_accept(handle, 0, LION_FLAG_NONE, (void *)newo,
90 								   NULL, NULL);
91 
92 		// Lets allow SSL'ed connections too.
93 		lion_ssl_set(newo->handle, LION_SSL_SERVER);
94 
95 		break;
96 
97 	case LION_CONNECTION_CONNECTED:
98 		break;
99 
100 	case LION_BUFFER_USED:
101 		break;
102 
103 	case LION_BUFFER_EMPTY:
104 		break;
105 
106 	case LION_INPUT:
107 		break;
108 
109 	case LION_BINARY:
110 		break;
111 
112 	}
113 
114 
115 
116 	return 0;
117 
118 }
119 
120 
121