Some fixes.
This commit is contained in:
parent
10c45492bc
commit
a3774da4ee
2 changed files with 72 additions and 9 deletions
80
zynk.c
80
zynk.c
|
|
@ -20,7 +20,7 @@
|
|||
#include <ctype.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/utsname.h>
|
||||
/* #include <sys/utsname.h> */
|
||||
#include <dlfcn.h>
|
||||
#include <sys/wait.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
|
@ -29,7 +29,7 @@ int asprintf(char **, const char *, ...);
|
|||
|
||||
/* ---- constants ---- */
|
||||
|
||||
#define VERSION "0.32"
|
||||
#define VERSION "0.32.1"
|
||||
#define DEFAULT_SERVER "irc.libera.chat"
|
||||
#define OPENCODE_BIN "/usr/bin/opencode"
|
||||
#define CLR_RESET "\033[0m"
|
||||
|
|
@ -684,6 +684,13 @@ static int has_crlf(const char *s) {
|
|||
return s && strpbrk(s, "\r\n") != NULL;
|
||||
}
|
||||
|
||||
static int has_ctl(const char *s) {
|
||||
if (!s) return 0;
|
||||
for (const unsigned char *p = (const unsigned char*)s; *p; p++)
|
||||
if (*p < 0x20 || *p == 0x7f) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int valid_irc_word(const char *s) {
|
||||
if (!s || !*s || has_crlf(s)) return 0;
|
||||
for (const char *p = s; *p; p++)
|
||||
|
|
@ -993,20 +1000,69 @@ static void ai_check_completion(Session *s) {
|
|||
|
||||
/* ---- IRC protocol helpers ---- */
|
||||
|
||||
static void irc_join(Session *s, const char *chan) { net_send(s, "JOIN %s\r\n", chan); }
|
||||
static void irc_join(Session *s, const char *chan) {
|
||||
char tb[256]; size_t tl = 0;
|
||||
if (chan) {
|
||||
for (const unsigned char *p = (const unsigned char*)chan; *p && tl + 1 < sizeof tb; p++) {
|
||||
if (*p == ' ' || *p == ':' || *p == '\r' || *p == '\n') break;
|
||||
tb[tl++] = *p;
|
||||
}
|
||||
}
|
||||
tb[tl] = 0;
|
||||
if (tb[0]) net_send(s, "JOIN %s\r\n", tb);
|
||||
}
|
||||
|
||||
static void irc_msg(Session *s, const char *t, const char *txt) {
|
||||
char *clean = NULL;
|
||||
if (strpbrk(txt, "\r\n")) {
|
||||
clean = strdup(txt);
|
||||
if (clean) { for (char *p = clean; *p; p++) if (*p == '\r' || *p == '\n') *p = ' '; txt = clean; }
|
||||
char tb[256]; size_t tl = 0;
|
||||
if (t) {
|
||||
for (const unsigned char *p = (const unsigned char*)t; *p && tl + 1 < sizeof tb; p++) {
|
||||
if (*p == ' ' || *p == ':' || *p == '\r' || *p == '\n') break;
|
||||
tb[tl++] = *p;
|
||||
}
|
||||
}
|
||||
net_send(s, "PRIVMSG %s :%s\r\n", t, txt);
|
||||
tb[tl] = 0;
|
||||
const char *send_txt = txt ? txt : "";
|
||||
char *clean = NULL;
|
||||
int need_clean = 0;
|
||||
for (const unsigned char *p = (const unsigned char*)send_txt; *p; p++) {
|
||||
if (*p < 0x20 || *p == 0x7f) { need_clean = 1; break; }
|
||||
}
|
||||
if (need_clean) {
|
||||
clean = strdup(send_txt);
|
||||
if (clean) {
|
||||
for (char *p = clean; *p; p++) if ((unsigned char)*p < 0x20 || (unsigned char)*p == 0x7f) *p = ' ';
|
||||
send_txt = clean;
|
||||
}
|
||||
}
|
||||
if (tb[0]) net_send(s, "PRIVMSG %s :%s\r\n", tb, send_txt);
|
||||
free(clean);
|
||||
}
|
||||
|
||||
static void irc_nick(Session *s, const char *nn) { net_send(s, "NICK %s\r\n", nn); }
|
||||
static void irc_pong(Session *s, const char *r) { if (*r == ':') r++; net_send(s, "PONG :%s\r\n", r); }
|
||||
static void irc_nick(Session *s, const char *nn) {
|
||||
char tb[64]; size_t tl = 0;
|
||||
if (nn) {
|
||||
for (const unsigned char *p = (const unsigned char*)nn; *p && tl + 1 < sizeof tb; p++) {
|
||||
if (*p == ' ' || *p == ':' || *p == '\r' || *p == '\n') break;
|
||||
tb[tl++] = *p;
|
||||
}
|
||||
}
|
||||
tb[tl] = 0;
|
||||
if (tb[0]) net_send(s, "NICK %s\r\n", tb);
|
||||
}
|
||||
static void irc_pong(Session *s, const char *r) {
|
||||
if (*r == ':') r++;
|
||||
char pb[256]; size_t pl = 0;
|
||||
if (r) {
|
||||
for (const unsigned char *p = (const unsigned char*)r; *p && pl + 1 < sizeof pb; p++) {
|
||||
if (*p == '\r' || *p == '\n') break;
|
||||
unsigned char c = *p;
|
||||
if (c < 0x20 || c == 0x7f) c = ' ';
|
||||
pb[pl++] = (char)c;
|
||||
}
|
||||
}
|
||||
pb[pl] = 0;
|
||||
net_send(s, "PONG :%s\r\n", pb);
|
||||
}
|
||||
|
||||
/* ---- IRC command handlers ---- */
|
||||
|
||||
|
|
@ -1607,6 +1663,10 @@ int main(int argc, char **argv) {
|
|||
fprintf(stderr, CLR_RED "Invalid opencode path" CLR_RESET "\n");
|
||||
return 1;
|
||||
}
|
||||
if (has_ctl(g_opencode_bin)) {
|
||||
fprintf(stderr, CLR_RED "Invalid opencode path (control chars)" CLR_RESET "\n");
|
||||
return 1;
|
||||
}
|
||||
if (db_init() < 0) {
|
||||
fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n");
|
||||
sqlite_cleanup();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue