Merge remote-tracking branch 'origin/development'
authorpk910 <philipp@zoelle1.de>
Wed, 19 Dec 2012 13:34:00 +0000 (14:34 +0100)
committerpk910 <philipp@zoelle1.de>
Wed, 19 Dec 2012 13:34:00 +0000 (14:34 +0100)
22 files changed:
Makefile.am
neonserv.example.conf
src/IOEngine_epoll.c
src/IOEngine_kevent.c
src/IOEngine_select.c
src/IOEngine_win32.c
src/IOHandler.c
src/IOHandler.h
src/IOHandler_SSL.c
src/modules/NeonBackup.mod/cmd_neonbackup.c
src/modules/NeonBackup.mod/cmd_neonbackup.h
src/modules/NeonBackup.mod/cmd_neonbackup_recover.c [new file with mode: 0644]
src/modules/NeonServ.mod/bot_NeonServ.c
src/modules/global.mod/cmd_global_version.c
src/modules/stats.mod/module.c
src/overall.h
src/test/Makefile [deleted file]
src/test/iotest.c [deleted file]
src/test/socket/Makefile [new file with mode: 0644]
src/test/socket/iotest.c [new file with mode: 0644]
src/test/timer/Makefile [new file with mode: 0644]
src/test/timer/iotest.c [new file with mode: 0644]

index b03b830b321dfa2fdb866ef9b5986d4ae4f8ebde..679e1f6c98ed946673732e55de66d3453cf3234a 100644 (file)
@@ -67,6 +67,7 @@ libNeonHelp_la_LIBADD = $(MYSQL_LIBS)
 
 libNeonBackup_la_SOURCES = src/modules/NeonBackup.mod/bot_NeonBackup.c \
       src/modules/NeonBackup.mod/cmd_neonbackup.c \
+      src/modules/NeonBackup.mod/cmd_neonbackup_recover.c \
       src/modules/NeonBackup.mod/module.c
 libNeonBackup_la_LDFLAGS = -module -rpath /nowhere -avoid-version -no-undefined
 libNeonBackup_la_LIBADD = $(MYSQL_LIBS)
index 9bab950f9756f0bf283c697bf1d64c44ffdac200..b10eca7b2557175fd368f57e2b991d7186e3cb5e 100644 (file)
         "protected" = 0;
         "hide_networkname" = 0; //hide network name
         "hide_botnick" = 0; //hide bot nick, ident, host
+        // "use_bot" = "BotNick"; //use this bot for the statistics
         "hide_chancount" = 0; //hide joined channel count
         "hide_usercount" = 0; //hide number of users the bot can see
     };
index e36394960f3af206bf4fa594fc10732e2de324f1..d1c139f6970f734a4fdb65ef2b9d5dde12e50e30 100644 (file)
@@ -83,8 +83,14 @@ static void engine_epoll_loop(struct timeval *timeout) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
         if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         } else if(tdiff.tv_usec < 0) {
             tdiff.tv_sec--;
@@ -120,8 +126,14 @@ static void engine_epoll_loop(struct timeval *timeout) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
         if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         }
         break;
index f729dbbe820694181ee43d4ebf6dda7b7c9bfb47..ee93f8645f09f63a25cb750df661d70b91c3d535 100644 (file)
@@ -89,8 +89,14 @@ static void engine_kevent_loop(struct timeval *timeout) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
         if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         } else if(tdiff.tv_usec < 0) {
             tdiff.tv_sec--;
@@ -130,8 +136,14 @@ static void engine_kevent_loop(struct timeval *timeout) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
         if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         }
         break;
index 2d85d7cc10f0f3b7e7f6bdf597573a3a47e39ea1..aff5fb920f264e47caa8ce9a86772cb7fcf0a6dd 100644 (file)
@@ -16,6 +16,7 @@
  */
 #include "IOEngine.h"
 #include <errno.h>
+#include <time.h>
 #ifdef WIN32
 #define _WIN32_WINNT 0x501
 #include <windows.h>
 #include <stdio.h>
 #endif
 
+static int engine_select_timer_delay_fix;
+
 static int engine_select_init() {
-    /* empty */
+    engine_select_timer_delay_fix = 0;
     return 1;
 }
 
@@ -53,6 +56,7 @@ static void engine_select_loop(struct timeval *timeout) {
     struct IODescriptor *iofd, *tmp_iofd;
     struct timeval now, tdiff;
     int select_result;
+    int timer_fix;
     
     gettimeofday(&now, NULL);
     
@@ -60,6 +64,7 @@ static void engine_select_loop(struct timeval *timeout) {
     FD_ZERO(&read_fds);
     FD_ZERO(&write_fds);
     
+    select_result = 0;
     for(iofd = first_descriptor; iofd; iofd = tmp_iofd) {
         tmp_iofd = iofd->next;
         if(iofd->type == IOTYPE_STDIN) {
@@ -96,6 +101,7 @@ static void engine_select_loop(struct timeval *timeout) {
             if(iofd->fd > fds_size)
                 fds_size = iofd->fd;
             FD_SET(iofd->fd, &read_fds);
+            select_result++;
             #endif
         }
         else if(iofd->type == IOTYPE_SERVER || iofd->type == IOTYPE_CLIENT) {
@@ -104,6 +110,7 @@ static void engine_select_loop(struct timeval *timeout) {
             if(iofd->fd > fds_size)
                 fds_size = iofd->fd;
             FD_SET(iofd->fd, &read_fds);
+            select_result++;
             if(iohandler_wants_writes(iofd))
                 FD_SET(iofd->fd, &write_fds);
         }
@@ -113,8 +120,14 @@ static void engine_select_loop(struct timeval *timeout) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
         if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         } else if(tdiff.tv_usec < 0) {
             tdiff.tv_sec--;
@@ -122,13 +135,28 @@ static void engine_select_loop(struct timeval *timeout) {
         }
         if(timeval_is_smaler((&tdiff), timeout)) {
             timeout->tv_sec = tdiff.tv_sec;
-            timeout->tv_usec = tdiff.tv_usec;
+            timeout->tv_usec = tdiff.tv_usec + engine_select_timer_delay_fix;
+            if(timeout->tv_usec < 0) {
+                timeout->tv_sec--;
+                timeout->tv_usec += 1000000;
+            }
         }
         break;
     }
     
-    //select system call
-    select_result = select(fds_size + 1, &read_fds, &write_fds, NULL, timeout);
+    if(select_result) {
+        //select system call
+        select_result = select(fds_size + 1, &read_fds, &write_fds, NULL, timeout);
+    } else {
+        #ifdef WIN32
+        Sleep((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000) + 1);
+        #else
+        struct timespec usleep_time;
+        usleep_time.tv_sec = timeout->tv_sec;
+        usleep_time.tv_nsec = timeout->tv_usec * 1000;
+        nanosleep(&usleep_time, NULL);
+        #endif
+    }
     
     if (select_result < 0) {
         if (errno != EINTR) {
@@ -154,9 +182,20 @@ static void engine_select_loop(struct timeval *timeout) {
     while(timer_priority) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
-        if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+        timer_fix = (tdiff.tv_sec * 1000000) + tdiff.tv_usec;
+        if(timer_fix <= 100) {
+            if(timer_fix + 100 < engine_select_timer_delay_fix || timer_fix - 100 > engine_select_timer_delay_fix) {
+                engine_select_timer_delay_fix = ((engine_select_timer_delay_fix * 19) + timer_fix) / 20;
+                iohandler_log(IOLOG_DEBUG, "timer delay fix set to: %d us", engine_select_timer_delay_fix);
+            }
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         }
         break;
index bce6fc14da687edf98597f061b2547dacde2593f..e29f8e57ae1e765fdb2656b38b102b07fe822ffd 100644 (file)
@@ -63,8 +63,14 @@ static LRESULT CALLBACK engine_win32_wndproc(HWND hWnd, UINT uMsg, WPARAM wParam
             tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
             tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
             if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec <= 0)) {
-                iohandler_events(timer_priority, 0, 0);
-                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+                if(timer_priority->constant_timeout) {
+                    tdiff.tv_sec = 0;
+                    iohandler_set_timeout(timer_priority, &tdiff);
+                    iohandler_events(timer_priority, 0, 0);
+                } else {
+                    iohandler_events(timer_priority, 0, 0);
+                    iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+                }
                 continue;
             }
             break;
@@ -213,9 +219,15 @@ static void engine_win32_loop(struct timeval *timeout) {
     while(timer_priority) {
         tdiff.tv_sec = timer_priority->timeout.tv_sec - now.tv_sec;
         tdiff.tv_usec = timer_priority->timeout.tv_usec - now.tv_usec;
-        if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec < 1000)) {
-            iohandler_events(timer_priority, 0, 0);
-            iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+        if(tdiff.tv_sec < 0 || (tdiff.tv_sec == 0 && tdiff.tv_usec < 100)) {
+            if(timer_priority->constant_timeout) {
+                tdiff.tv_sec = 0;
+                iohandler_set_timeout(timer_priority, &tdiff);
+                iohandler_events(timer_priority, 0, 0);
+            } else {
+                iohandler_events(timer_priority, 0, 0);
+                iohandler_close(timer_priority); //also sets timer_priority to the next timed element
+            }
             continue;
         } else if(tdiff.tv_usec < 0) {
             tdiff.tv_sec--;
index 52b27b35b3d8faa1138bc06f28e811394b5d5721..b2a391bf11e68388112f107a56747f84f6e8cde2 100644 (file)
@@ -73,20 +73,30 @@ extern struct IOEngine engine_kevent;
 extern struct IOEngine engine_epoll;
 extern struct IOEngine engine_win32;
 
+int iohandler_settings = 0;
 struct IOEngine *engine = NULL;
 
+void iohandler_set(int setting, int value) {
+    if(value)
+        iohandler_settings |= setting;
+    else
+        iohandler_settings &= ~setting;
+}
+
 static void iohandler_init_engine() {
     if(engine) return;
     IOTHREAD_MUTEX_INIT(io_thread_sync);
     IOTHREAD_MUTEX_INIT(io_poll_sync);
     
     //try other engines
-    if(!engine && engine_kevent.init && engine_kevent.init())
-        engine = &engine_kevent;
-    if(!engine && engine_epoll.init && engine_epoll.init())
-        engine = &engine_epoll;
-    if(!engine && engine_win32.init && engine_win32.init())
-        engine = &engine_win32;
+    if(!(iohandler_settings & IOHANDLER_SETTING_HIGH_PRECISION_TIMER)) {
+        if(!engine && engine_kevent.init && engine_kevent.init())
+            engine = &engine_kevent;
+        if(!engine && engine_epoll.init && engine_epoll.init())
+            engine = &engine_epoll;
+        if(!engine && engine_win32.init && engine_win32.init())
+            engine = &engine_win32;
+    }
     
     if (!engine) {
         if(engine_select.init())
@@ -185,8 +195,13 @@ struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval
     descriptor->type = type;
     descriptor->state = (type == IOTYPE_STDIN ? IO_CONNECTED : IO_CLOSED);
     descriptor->callback = callback;
-    if(timeout)
+    if(timeout) {
         descriptor->timeout = *timeout;
+        if(descriptor->timeout.tv_usec > 1000000) {
+            descriptor->timeout.tv_usec -= 1000000;
+            descriptor->timeout.tv_sec++;
+        }
+    }
     if(type != IOTYPE_TIMER) {
         descriptor->readbuf.buffer = malloc(IO_READ_BUFLEN + 2);
         descriptor->readbuf.bufpos = 0;
@@ -220,9 +235,20 @@ void iohandler_set_timeout(struct IODescriptor *descriptor, struct timeval *time
         descriptor->next->prev = descriptor->prev;
     if(descriptor == timer_priority)
         timer_priority = descriptor->next;
-    if(timeout) 
+    if(timeout && timeout->tv_sec == 0 && descriptor->constant_timeout) {
+        descriptor->timeout.tv_usec += (descriptor->constant_timeout % 1000) * 1000;
+        descriptor->timeout.tv_sec += (descriptor->constant_timeout / 1000);
+        if(descriptor->timeout.tv_usec > 1000000) {
+            descriptor->timeout.tv_sec += (descriptor->timeout.tv_usec / 1000000);
+            descriptor->timeout.tv_usec %= 1000000;
+        }
+    } else if(timeout) {
         descriptor->timeout = *timeout;
-    else {
+        if(descriptor->timeout.tv_usec > 1000000) {
+            descriptor->timeout.tv_usec -= 1000000;
+            descriptor->timeout.tv_sec++;
+        }
+    } else {
         descriptor->timeout.tv_sec = 0;
         descriptor->timeout.tv_usec = 0;
     }
@@ -249,6 +275,26 @@ struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback
     return descriptor;
 }
 
+struct IODescriptor *iohandler_constant_timer(int msec, iohandler_callback *callback) {
+    struct IODescriptor *descriptor;
+    struct timeval timeout;
+    gettimeofday(&timeout, NULL);
+    timeout.tv_usec += (msec % 1000) * 1000;
+    timeout.tv_sec += (msec / 1000);
+    if(timeout.tv_usec > 1000000) {
+        timeout.tv_sec += (timeout.tv_usec / 1000000);
+        timeout.tv_usec %= 1000000;
+    }
+    descriptor = iohandler_add(-1, IOTYPE_TIMER, &timeout, callback);
+    if(!descriptor) {
+        iohandler_log(IOLOG_ERROR, "could not allocate memory for IODescriptor in %s:%d", __FILE__, __LINE__);
+        return NULL;
+    }
+    descriptor->constant_timeout = msec;
+    iohandler_log(IOLOG_DEBUG, "added timer descriptor (sec: %d; usec: %d)", timeout.tv_sec, timeout.tv_usec);
+    return descriptor;
+}
+
 struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, int ssl, const char *bindhost, iohandler_callback *callback) {
     return iohandler_connect_flags(hostname, port, ssl, bindhost, callback, IOHANDLER_CONNECT_IPV4 | IOHANDLER_CONNECT_IPV6);
 }
index 95429859ba61cf7c01006056ae2fd8a532f63098..82781d61e0be415f1ad662b0154b8b461316b820 100644 (file)
@@ -83,6 +83,7 @@ struct IODescriptor {
     enum IOType type;
     enum IOStatus state;
     struct timeval timeout;
+    int constant_timeout;
     iohandler_callback *callback;
     struct IOBuffer readbuf;
     struct IOBuffer writebuf;
@@ -115,8 +116,13 @@ struct IOEvent {
 #define IOHANDLER_CONNECT_IPV4 0x01
 #define IOHANDLER_CONNECT_IPV6 0x02 /* overrides IOHANDLER_CONNECT_IPV4 */
 
+#define IOHANDLER_SETTING_HIGH_PRECISION_TIMER 0x01
+
+void iohandler_set(int setting, int value);
+
 struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval *timeout, iohandler_callback *callback);
 struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback *callback);
+struct IODescriptor *iohandler_constant_timer(int msec, iohandler_callback *callback);
 struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, int ssl, const char *bind, iohandler_callback *callback);
 struct IODescriptor *iohandler_connect_flags(const char *hostname, unsigned int port, int ssl, const char *bindhost, iohandler_callback *callback, int flags);
 struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, iohandler_callback *callback);
index 5d87cecb62afb47f9280d71cc4a34ff76e2c1e38..5408e9786eb232db8a821d0698f42ddeee1da627 100644 (file)
  */
 #include "IOEngine.h"
 #include "IOHandler_SSL.h"
+#ifdef HAVE_SSL
 
 void iohandler_ssl_init() {
-#ifdef HAVE_SSL
     SSL_library_init();
     OpenSSL_add_all_algorithms(); /* load & register all cryptos, etc. */
     SSL_load_error_strings();
-#endif
 }
 
 static void iohandler_ssl_error() {
@@ -33,7 +32,6 @@ static void iohandler_ssl_error() {
 }
 
 void iohandler_ssl_connect(struct IODescriptor *iofd) {
-#ifdef HAVE_SSL
     iofd->state = IO_SSLWAIT;
     iofd->ssl_server_hs = 0;
     struct IOSSLNode *sslnode = malloc(sizeof(*sslnode));
@@ -61,11 +59,9 @@ void iohandler_ssl_connect(struct IODescriptor *iofd) {
 ssl_connect_err:
     free(sslnode);
     iohandler_events(iofd, 0, 0);
-#endif    
 }
 
 void iohandler_ssl_listen(struct IODescriptor *iofd, const char *certfile, const char *keyfile) {
-#ifdef HAVE_SSL
     struct IOSSLNode *sslnode = malloc(sizeof(*sslnode));
     sslnode->sslContext = SSL_CTX_new(SSLv23_server_method());
     if(!sslnode->sslContext) {
@@ -97,11 +93,9 @@ ssl_listen_err:
     free(sslnode);
     iofd->sslnode = NULL;
     iohandler_events(iofd, 0, 0);
-#endif    
 }
 
 void iohandler_ssl_client_handshake(struct IODescriptor *iofd) {
-#ifdef HAVE_SSL
     // Perform an SSL handshake.
     int ret = SSL_do_handshake(iofd->sslnode->sslHandle);
     iofd->ssl_hs_read = 0;
@@ -126,11 +120,9 @@ void iohandler_ssl_client_handshake(struct IODescriptor *iofd) {
             iohandler_events(iofd, 0, 0);
             break;
     }
-#endif
 }
 
 void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescriptor *client_iofd) {
-#ifdef HAVE_SSL
     struct IOSSLNode *sslnode = malloc(sizeof(*sslnode));
     sslnode->sslHandle = SSL_new(sslnode->sslContext);
     if(!sslnode->sslHandle) {
@@ -153,11 +145,9 @@ void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescripto
 ssl_accept_err:
     iohandler_close(client_iofd);
     free(sslnode);
-#endif
 }
 
 void iohandler_ssl_server_handshake(struct IODescriptor *iofd) {
-#ifdef HAVE_SSL
     // Perform an SSL handshake.
     int ret = SSL_accept(iofd->sslnode->sslHandle);
     iofd->ssl_hs_read = 0;
@@ -182,11 +172,9 @@ void iohandler_ssl_server_handshake(struct IODescriptor *iofd) {
             iohandler_events(iofd, 0, 0);
             break;
     }
-#endif
 }
 
 void iohandler_ssl_disconnect(struct IODescriptor *iofd) {
-#ifdef HAVE_SSL
     if(!iofd->sslnode) return;
     SSL_shutdown(iofd->sslnode->sslHandle);
     SSL_free(iofd->sslnode->sslHandle);
@@ -194,11 +182,9 @@ void iohandler_ssl_disconnect(struct IODescriptor *iofd) {
     free(iofd->sslnode);
     iofd->sslnode = NULL;
     iofd->ssl_active = 0;
-#endif
 }
 
 int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) {
-#ifdef HAVE_SSL
     if(!iofd->sslnode) return 0;
     int ret = SSL_read(iofd->sslnode->sslHandle, buffer, len);
     int update = (iofd->ssl_hs_read || iofd->ssl_hs_write);
@@ -230,12 +216,9 @@ int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) {
             return -1;
             break;
     }
-#endif
-    return 0;
 }
 
 int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) {
-#ifdef HAVE_SSL
     if(!iofd->sslnode) return 0;
     int ret = SSL_write(iofd->sslnode->sslHandle, buffer, len);
     int update = (iofd->ssl_hs_read || iofd->ssl_hs_write);
@@ -267,6 +250,18 @@ int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) {
             return -1;
             break;
     }
-#endif
-    return 0;
 }
+
+#else
+// NULL-backend
+
+void iohandler_ssl_init() {};
+void iohandler_ssl_connect(struct IODescriptor *iofd) {};
+void iohandler_ssl_listen(struct IODescriptor *iofd, const char *certfile, const char *keyfile) {};
+void iohandler_ssl_client_handshake(struct IODescriptor *iofd) {};
+void iohandler_ssl_client_accepted(struct IODescriptor *iofd, struct IODescriptor *client_iofd) {};
+void iohandler_ssl_server_handshake(struct IODescriptor *iofd) {};
+void iohandler_ssl_disconnect(struct IODescriptor *iofd) {};
+int iohandler_ssl_read(struct IODescriptor *iofd, char *buffer, int len) { return 0; };
+int iohandler_ssl_write(struct IODescriptor *iofd, char *buffer, int len) { return 0; };
+#endif
index 92348546eb79ac26b68b216d06d6aab3ae3730b9..f78bf3756ac010d8ebf64b08757dbe426b9dd271 100644 (file)
@@ -23,6 +23,9 @@ void register_commands() {
     //NeonBackup Commands
     register_command_alias(6, "NeonBackup");
     
-    
+    #define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(6, NAME, module_id, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS)
+    //            NAME            FUNCTION              PARAMS  ACCS  FLAGS
+    OPER_COMMAND("recover",      neonbackup_cmd_recover, 0,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    #undef OPER_COMMAND
     
 }
\ No newline at end of file
index fed816da4d690a894c3518e0cae54f05b675e6ab..d6f17631e676c0fad0c0f36b066251f1dc8fc830 100644 (file)
@@ -32,5 +32,6 @@
 
 void register_commands();
 
+CMD_BIND(neonbackup_cmd_recover);
 
 #endif
diff --git a/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c b/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c
new file mode 100644 (file)
index 0000000..dc71276
--- /dev/null
@@ -0,0 +1,56 @@
+/* cmd_neonbackup_recover.c - NeonServ v5.6
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_neonbackup.h"
+
+/*
+* no argv
+*/
+static struct ClientSocket *neonbackup_cmd_recover_get_bot(int clientid) {
+    struct ClientSocket *bot;
+    for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+        if(bot->clientid == clientid)
+            return bot;
+    }
+    return NULL;
+}
+
+CMD_BIND(neonbackup_cmd_recover) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `channels`.`channel_name`, `bots`.`id` FROM `bot_channels`, `bots`, `channels` WHERE `bots`.`id` = `botid` AND `channel_id` = `chanid` AND `active` = 1");
+    res = mysql_use();
+    
+    struct ClientSocket *bot;
+    struct ChanUser *chanuser;
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        chan = getChanByName(row[0]);
+        if(!chan)
+            continue;
+        bot = neonbackup_cmd_recover_get_bot(atoi(row[1]));
+        if(!bot)
+            continue;
+        if(!(chanuser = getChanUser(bot->user, chan))) {
+            requestInvite(bot->user, chan);
+            reply(textclient, user, "NS_INVITE_DONE", bot->user->nick, chan->name);
+        } else if(!chanuser->flags & CHANUSERFLAG_OPPED) {
+            requestOp(bot->user, chan);
+            reply(textclient, user, "NS_OP_DONE", chan->name);
+        }
+    }
+    logEvent(event);
+}
index c3cb123cff4761ca586ce659141811c2458e7137..ca2a3083f5303d9951bc0e1495047d3874d1a177 100644 (file)
@@ -243,7 +243,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_RESYNC_DONE", "Synchronized users in $b%s$b with the userlist."}, /* {ARGS: "#TestChan"} */
     {"NS_TIMEBAN_DURATION_TOO_SHORT", "You must specify a ban duration of at least %d seconds."}, /* {ARGS: 30} */
     {"NS_TIMEBAN_DONE", "Banned $b%s$b from %s for %s. (matching %d users)"}, /* {ARGS: "*!*@bla*", "#TestChan", "2 hours", 5} */
-    {"NS_MODE_INVALID", "$b%c$b is an invalid set of channel modes."}, /* {ARGS: "+xyz"} */
+    {"NS_MODE_INVALID", "$b%s$b is an invalid set of channel modes."}, /* {ARGS: "+xyz"} */
     {"NS_MODE_LOCKED", "Modes conflicting with $b%s$b are not allowed in %s."}, /* {ARGS: "+xyz", "#TestChan"} */
     {"NS_MODE_DONE", "Channel modes are now $b%s$b."}, /* {ARGS: "+xyz"} */
     {"NS_MODE_ENFOPS", "You may not op or deop users on $b%s$b."}, /* {ARGS: "#TestChan"} */
@@ -358,7 +358,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_NICKLIST_NICK", "Nick"},
     {"NS_NICKLIST_STATE", "State"},
     {"NS_NICKLIST_ACCESS", "Access"},
-    {"NS_NICKLIST_SYNC", "use `nicklist sync` to fix all red and orange entrys in the list above (add opped users with %d and voiced with %d access)"},
+    {"NS_NICKLIST_SYNC", "use `nicklist sync` to fix all red and orange entrys in the list above (add opped users with %d and voiced with %d access)"}, /* {ARGS: 200, 100} */
     {"NS_NICKLIST_ACCESS_BOT", "Bot"},
     {"NS_NICKLIST_ACCESS_OPER", "Operator"},
     {"NS_SETBOT_UNKNOWN", "`%d` is an unknown botid."}, /* {ARGS: 50} */
index da7968bf02dcbc69f4252ec7a53152c386f424ee..9cc3392059a77f9a5d102459710dd076ede47ec0 100644 (file)
@@ -27,10 +27,13 @@ CMD_BIND(global_cmd_version) {
     reply(textclient, user, "NeonServ can be found on: http://dev.pk910.de/NeonServ");
     //helpers :D
     reply(textclient, user, "special thanks to:");
-    reply(textclient, user, "  Zer0n, TeaTow, Phil  (testing and ideas current version)");
-    reply(textclient, user, "  Buschman, Zer0n, Neon  (translating current version)");
-    reply(textclient, user, "  Patschi95, DerGrinch, Darkfly, Zer0n, Buschman  (testing and ideas older versions)");
-    reply(textclient, user, "  Buschman, Georg, richard  (translating older versions)");
+    reply(textclient, user, "  Testing and Ideas:");
+    reply(textclient, user, "    Zer0n, TeaTow, Phil, Stricted");
+    reply(textclient, user, "  Translations:");
+    reply(textclient, user, "    Buschman (de), Zer0n (de), Neon (de), TheFlie (nl), GodsWarriors (pt)");
+    reply(textclient, user, "  Others:");
+    reply(textclient, user, "    Patschi95, DerGrinch, Darkfly, Zer0n, Buschman  (testing and ideas older versions)");
+    reply(textclient, user, "    Buschman, Georg, richard  (translating older versions)");
     reply(textclient, user, "and all the other users that reported all these nasty bugs :D");
     reply(textclient, user, "\002If you found a bug or if you have a good idea report it on http://dev.pk910.de/BugTrack\002");
     
index c81e3a6b12a14ecbea820690013d8d19e3ade7aa..4780077c49739e35666736f293626eb1573df819 100644 (file)
@@ -94,21 +94,27 @@ static TIMEQ_CALLBACK(stats_timer_callback) {
     if(get_int_field(tmp))
         pkgpos += sprintf(pkgbuf + pkgpos, "*\n");
     else {
-        struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL;
+        sprintf(tmp, "modules/%s/use_bot", modname);
+        char *botname = get_string_field(tmp);
+        struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL, *bot4 = NULL;
         for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
-            if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED))
+            if(botname && !stricmp(bot->nick, botname))
                 bot1 = bot;
-            else if((bot->flags & SOCKET_FLAG_PREFERRED))
+            else if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED))
                 bot2 = bot;
-            else
+            else if((bot->flags & SOCKET_FLAG_PREFERRED))
                 bot3 = bot;
+            else
+                bot4 = bot;
         }
         if(bot1)
             bot = bot1;
         else if(bot2)
             bot = bot2;
-        else
+        else if(bot3)
             bot = bot3;
+        else
+            bot = bot4;
         if(bot) {
             pkgpos += sprintf(pkgbuf + pkgpos, "%s!%s@%s %d\n", (bot->user ? bot->user->nick : "*"), (bot->user ? bot->user->ident : "*"), (bot->host ? bot->host : "*"), bot->port);
         } else
index ff6f40873ab71ee3e87d8cee6c06c4f104074e44..55b48eac97e0771cbecbfe6343e89500e349f496 100644 (file)
 #define MAXLOGLEN       1024
 #define TRIGGERLEN      50
 #define MAXNUMPARAMS    200 /* maximum number of parameters in one line */
-#define MAXLANGUAGES    5
+#define MAXLANGUAGES    15
 #define MAXMODES        6
 #define INVITE_TIMEOUT  30
 #define BOTWAR_DETECTION_TIME 7
diff --git a/src/test/Makefile b/src/test/Makefile
deleted file mode 100644 (file)
index 37fa3d8..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-
-CC      = gcc
-CFLAGS  = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H
-LDFLAGS = -lws2_32 -lpthread
-
-OBJ     = ../IOEngine_epoll.o ../IOEngine_kevent.o ../IOEngine_select.o ../IOEngine_win32.o ../IOHandler.o ../IOHandler_SSL.o iotest.o
-
-all: $(OBJ)
-       $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS)
-
-%.o: %.c
-       $(CC) $(CFLAGS) -o$@ -c $<
diff --git a/src/test/iotest.c b/src/test/iotest.c
deleted file mode 100644 (file)
index 15f32f4..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/* main.c - IOMultiplexer
- * Copyright (C) 2012  Philipp Kreil (pk910)
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License 
- * along with this program. If not, see <http://www.gnu.org/licenses/>. 
- */
-
-#include <stdio.h>
-#include "../IOHandler.h"
-
-static IOHANDLER_CALLBACK(io_callback);
-static IOHANDLER_LOG_BACKEND(io_log);
-
-static struct IODescriptor *irc_iofd = NULL;
-
-int main(int argc, char *argv[]) {
-    iolog_backend = io_log;
-    
-    irc_iofd = iohandler_connect("pk910.de", 6667, 0, NULL, io_callback);
-    
-    struct IODescriptor *iofd;
-    iofd = iohandler_add(0, IOTYPE_STDIN, NULL, io_callback);
-    iofd->read_lines = 1;
-    
-    while(1) {
-        iohandler_poll();
-    }
-}
-
-static IOHANDLER_CALLBACK(io_callback) {
-    switch(event->type) {
-        case IOEVENT_CONNECTED:
-            printf("[connect]\n");
-            break;
-        case IOEVENT_CLOSED:
-            printf("[disconnect]\n");
-            break;
-        case IOEVENT_RECV:
-            if(event->iofd->type == IOTYPE_STDIN) {
-                iohandler_printf(irc_iofd, "%s\n", event->data.recv_str);
-                printf("[out] %s\n", event->data.recv_str);
-            } else
-                printf("[in] %s\n", event->data.recv_str);
-            break;
-        
-        default:
-            break;
-    }
-}
-
-static IOHANDLER_LOG_BACKEND(io_log) {
-    //printf("%s", line);
-}
diff --git a/src/test/socket/Makefile b/src/test/socket/Makefile
new file mode 100644 (file)
index 0000000..724e34b
--- /dev/null
@@ -0,0 +1,12 @@
+
+CC      = gcc
+CFLAGS  = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H
+LDFLAGS = -lws2_32 -lpthread
+
+OBJ     = ../../IOEngine_epoll.o ../../IOEngine_kevent.o ../../IOEngine_select.o ../../IOEngine_win32.o ../../IOHandler.o ../../IOHandler_SSL.o iotest.o
+
+all: $(OBJ)
+       $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS)
+
+%.o: %.c
+       $(CC) $(CFLAGS) -o$@ -c $<
diff --git a/src/test/socket/iotest.c b/src/test/socket/iotest.c
new file mode 100644 (file)
index 0000000..15f32f4
--- /dev/null
@@ -0,0 +1,63 @@
+/* main.c - IOMultiplexer
+ * Copyright (C) 2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include <stdio.h>
+#include "../IOHandler.h"
+
+static IOHANDLER_CALLBACK(io_callback);
+static IOHANDLER_LOG_BACKEND(io_log);
+
+static struct IODescriptor *irc_iofd = NULL;
+
+int main(int argc, char *argv[]) {
+    iolog_backend = io_log;
+    
+    irc_iofd = iohandler_connect("pk910.de", 6667, 0, NULL, io_callback);
+    
+    struct IODescriptor *iofd;
+    iofd = iohandler_add(0, IOTYPE_STDIN, NULL, io_callback);
+    iofd->read_lines = 1;
+    
+    while(1) {
+        iohandler_poll();
+    }
+}
+
+static IOHANDLER_CALLBACK(io_callback) {
+    switch(event->type) {
+        case IOEVENT_CONNECTED:
+            printf("[connect]\n");
+            break;
+        case IOEVENT_CLOSED:
+            printf("[disconnect]\n");
+            break;
+        case IOEVENT_RECV:
+            if(event->iofd->type == IOTYPE_STDIN) {
+                iohandler_printf(irc_iofd, "%s\n", event->data.recv_str);
+                printf("[out] %s\n", event->data.recv_str);
+            } else
+                printf("[in] %s\n", event->data.recv_str);
+            break;
+        
+        default:
+            break;
+    }
+}
+
+static IOHANDLER_LOG_BACKEND(io_log) {
+    //printf("%s", line);
+}
diff --git a/src/test/timer/Makefile b/src/test/timer/Makefile
new file mode 100644 (file)
index 0000000..724e34b
--- /dev/null
@@ -0,0 +1,12 @@
+
+CC      = gcc
+CFLAGS  = -g -O0 -Wall -Wshadow -Werror -DHAVE_PTHREAD_H
+LDFLAGS = -lws2_32 -lpthread
+
+OBJ     = ../../IOEngine_epoll.o ../../IOEngine_kevent.o ../../IOEngine_select.o ../../IOEngine_win32.o ../../IOHandler.o ../../IOHandler_SSL.o iotest.o
+
+all: $(OBJ)
+       $(CC) $(CFLAGS) -oiotest $(OBJ) $(LDFLAGS)
+
+%.o: %.c
+       $(CC) $(CFLAGS) -o$@ -c $<
diff --git a/src/test/timer/iotest.c b/src/test/timer/iotest.c
new file mode 100644 (file)
index 0000000..17a91ec
--- /dev/null
@@ -0,0 +1,81 @@
+/* main.c - IOMultiplexer
+ * Copyright (C) 2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include <stdio.h>
+#include "../../IOHandler.h"
+
+#define TEST_DURATION 100
+
+static IOHANDLER_CALLBACK(io_callback);
+static IOHANDLER_LOG_BACKEND(io_log);
+
+static struct timeval test_clock1, test_clock2;
+static int timercount;
+
+void add_timer(int ms) {
+    struct timeval timeout;
+    gettimeofday(&timeout, NULL);
+    timeout.tv_usec += (ms % 1000) * 1000;
+    timeout.tv_sec += (ms / 1000);
+    if(timeout.tv_usec > 1000000) {
+        timeout.tv_usec -= 1000000;
+        timeout.tv_sec++;
+    }
+    iohandler_timer(timeout, io_callback);
+}
+
+int main(int argc, char *argv[]) {
+    iolog_backend = io_log;
+    
+    iohandler_set(IOHANDLER_SETTING_HIGH_PRECISION_TIMER, 1);
+    
+    gettimeofday(&test_clock1, NULL);
+    gettimeofday(&test_clock2, NULL);
+    //add_timer(TEST_DURATION);
+    iohandler_constant_timer(TEST_DURATION, io_callback);
+    timercount = 0;
+    
+    printf("[timer 0] %ld.%ld\n", test_clock1.tv_sec, test_clock1.tv_usec);
+    
+    while(1) {
+        iohandler_poll();
+    }
+}
+
+static IOHANDLER_CALLBACK(io_callback) {
+    struct timeval curr_time;
+    int diff1;
+    double diff2;
+    switch(event->type) {
+        case IOEVENT_TIMEOUT:
+            //add_timer(TEST_DURATION);
+            timercount++;
+            gettimeofday(&curr_time, NULL);
+            diff1 = (curr_time.tv_sec - test_clock1.tv_sec) * 1000 + ((curr_time.tv_usec - test_clock1.tv_usec) / 1000);
+            diff2 = (curr_time.tv_sec - test_clock2.tv_sec) * 1000 + ((curr_time.tv_usec - test_clock2.tv_usec) / 1000.0);
+            diff2 -= (timercount * TEST_DURATION);
+            gettimeofday(&test_clock1, NULL);
+            printf("[timer %03d] %ld.%06ld [%d ms]  accuracy: %f ms\n", timercount, curr_time.tv_sec, curr_time.tv_usec, diff1, diff2);
+            break;
+        default:
+            break;
+    }
+}
+
+static IOHANDLER_LOG_BACKEND(io_log) {
+    //printf("%s", line);
+}