From 25ff02fbc5926fcbd5acdbea16d40901ab13d479 Mon Sep 17 00:00:00 2001 From: Nishi Date: Fri, 13 Sep 2024 16:13:27 +0000 Subject: [PATCH] fixed git-svn-id: file:///raid/svn-personal/okuu/trunk@15 7d206d2a-66c2-044b-96de-ba755a9b3ba8 --- Bot/bot.c | 10 ++++++---- Bot/news.c | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Bot/bot.c b/Bot/bot.c index 55dd11e..d49157b 100644 --- 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 { diff --git a/Bot/news.c b/Bot/news.c index 4d9840c..15dc151 100644 --- a/Bot/news.c +++ b/Bot/news.c @@ -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 {