]> Git repositories of Nishi - okuu.git/commitdiff
fixed
authorNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 16:13:27 +0000 (16:13 +0000)
committerNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 16:13:27 +0000 (16:13 +0000)
git-svn-id: file:///raid/svn-personal/okuu/trunk@15 7d206d2a-66c2-044b-96de-ba755a9b3ba8

Bot/bot.c
Bot/news.c

index 55dd11e5fdd8d8116975c285886b0b0f01bbf089..d49157bc12f698752733b540011a838650c6fad6 100644 (file)
--- a/Bot/bot.c
+++ b/Bot/bot.c
@@ -101,7 +101,7 @@ void ok_bot(void) {
        signal(SIGINT, ok_bot_kill);
        signal(SIGTERM, ok_bot_kill);
 
-       char* construct = malloc(1025);
+       char* construct = malloc(4097);
 
        if(ircpass != NULL && strlen(ircpass) > 0) {
                sprintf(construct, "PASS :%s", ircpass);
@@ -135,8 +135,9 @@ void ok_bot(void) {
                        int n = scandir(nntppath, &list, nodots, namesort);
                        if(n >= 0) {
                                int i;
+                               uint64_t last = 0;
                                for(i = 0; i < n; i++) {
-                                       if(!sendable) {
+                                       if(!sendable || strcmp(list[i]->d_name, ".") == 0 || strcmp(list[i]->d_name, "..") == 0) {
                                                free(list[i]);
                                                continue;
                                        }
@@ -175,9 +176,10 @@ void ok_bot(void) {
                                                        fprintf(stderr, "Could not read %s\n", construct);
                                                }
                                        }
+                                       last = atoi(list[i]->d_name) + 1;
                                        free(list[i]);
                                }
-                               count = atoi(list[i - 1]->d_name) + 1;
+                               count = last;
                                free(list);
                        }
                        if(sendable) {
@@ -208,7 +210,7 @@ void ok_bot(void) {
                                fprintf(stderr, "Login successful\n");
                                sprintf(construct, "JOIN :%s", ircchan);
                                ircfw_socket_send_cmd(ok_sock, NULL, construct);
-                       } else if(res == 331 || res == 332) {
+                       } else if(res == 366) {
                                sendable = true;
                        }
                } else {
index 4d9840c12cdf22ee2dd156125192a0cc6cb5edd6..15dc151a81cdb455a6d59a98f987d24b1e941f4e 100644 (file)
@@ -54,7 +54,11 @@ int ok_news_read(const char* path) {
                char* boundary = NULL;
                char* buffer = malloc(s.st_size + 1);
                buffer[s.st_size] = 0;
-               FILE* f = fopen(path, "r");
+               FILE* f = fopen(path, "rb");
+               if(f == NULL){
+                       free(buffer);
+                       return 1;
+               }
                fread(buffer, s.st_size, 1, f);
 
                uint64_t i;
@@ -219,6 +223,7 @@ int ok_news_read(const char* path) {
                free(l);
 
                free(buffer);
+               fclose(f);
                if(boundary != NULL) free(boundary);
                return 0;
        } else {