1 /*
2  * Copyright (c) 2008
3  *      Matt Harris.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      "This product includes software developed by Matt Harris."
16  * 4. Neither the name of the Mr. Harris nor the names of his contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  * 5. Any modifications and/or variations in the end-product which you are
20  *    distributing from the original source code are clearly noted in
21  *    the standard end-user documentation distributed with any package
22  *    containing this software in either source or binary form, as well
23  *    as on any internet sites or media on which this software is included.
24  *
25  * THIS SOFTWARE IS PROVIDED BY Mr. Harris AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL Mr. Harris OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  */
38 
39 #include <msocket-internal.h>
40 
41 static time_t _lms_loop_lastrun = 0;
42 
43 
44 /*
45  * lms_loop() is our main event loop
46  *
47  */
lms_loop()48 int lms_loop()
49 {
50 	if (_lms_loop_lastrun < time(NULL))
51 	{
52 		lms_socket_housekeeping();
53 		lms_dns_cleancache();
54 #ifdef LMS_THROTTLE_ENABLE
55 		lms_throttle_expire();
56 #endif
57 		_lms_loop_lastrun = time(NULL);
58 	}
59 
60 	event_base_loop(lms_mux_evtb, EVLOOP_ONCE|EVLOOP_NONBLOCK);
61 
62 	return(0);
63 }
64 
65 /*
66  * lms_init() initializes all components of libmsocket
67  *
68  */
lms_init(unsigned char print)69 int lms_init(unsigned char print)
70 {
71 	if (lms_socket_init() < 0)
72 	{
73 		if (print > 0)
74 		{
75 			fprintf(stdout, "MSocket initialization failed: %s\n", strerror(errno));
76 		}
77 		return(-1);
78 	}
79 	if (lms_mux_init() < 0)
80 	{
81 		if (print > 0)
82 		{
83 			fprintf(stdout, "MUX initialization failed: %s\n", strerror(errno));
84 		}
85 		return(-1);
86 	}
87 	if (lms_dns_init() < 0)
88 	{
89 		if (print > 0)
90 		{
91 			fprintf(stdout, "DNS initialization failed: %s\n", strerror(errno));
92 		}
93 		return(-1);
94 	}
95 	if (lms_ssl_init() < 0)
96 	{
97 		if (print > 0)
98 		{
99 			fprintf(stdout, "SSL initialization failed: %s\n", strerror(errno));
100 		}
101 		return(-1);
102 	}
103 
104 	return(0);
105 }
106 
107 /*
108  * lms_version_int() returns the version of libmsocket in an integer format
109  *
110  */
lms_version_int()111 int lms_version_int()
112 {
113 	return(LMS_VERSION_INT);
114 }
115 
116 /*
117  * lms_version() returns the version of libmsocket
118  *
119  */
lms_version()120 char *lms_version()
121 {
122 	return(LMS_VERSION);
123 }
124