diff options
author | June McEnroe <june@causal.agency> | 2020-07-19 16:09:54 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-19 16:09:54 -0400 |
commit | 851e1a95f0d470e6c59d80d39e35fcea04128b48 (patch) | |
tree | 24ed91e09ef86ed148e698eb9ee5a13ed453d820 /litterbox.c | |
parent | Replace time index with (context, time) index (diff) | |
download | litterbox-851e1a95f0d470e6c59d80d39e35fcea04128b48.tar.gz litterbox-851e1a95f0d470e6c59d80d39e35fcea04128b48.zip |
Add -U scooper-url option to make scooper links
Diffstat (limited to '')
-rw-r--r-- | litterbox.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/litterbox.c b/litterbox.c index 70a5185..884bed6 100644 --- a/litterbox.c +++ b/litterbox.c @@ -243,6 +243,28 @@ static void handleReplyEndOfMOTD(struct Message *msg) { memset(&motd, 0, sizeof(motd)); } +static char *scooperURL; + +static void urlEncode(const char *str) { + static const char *Safe = { + "$-_.+!*'()," + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + }; + while (*str) { + size_t len = strspn(str, Safe); + if (len) clientWrite(str, len); + str += len; + if (*str == ' ') { + clientWrite("+", 1); + str++; + } else if (*str) { + format("%%%02X", *str++); + } + } +} + static int color(const char *user) { return 2 + hash(user) % 74; } @@ -338,6 +360,12 @@ static void querySearch(struct Message *msg) { } else { warnx("%s", sqlite3_errmsg(db)); } + } else if (scooperURL) { + format("NOTICE %s :%s/search?network=", msg->nick, scooperURL); + urlEncode(network); + format("&query="); + urlEncode(msg->params[1]); + format("\r\n"); } sqlite3_reset(stmt); @@ -738,6 +766,7 @@ int main(int argc, char *argv[]) { { .val = '!', .name = "insecure", no_argument }, { .val = 'N', .name = "network", required_argument }, { .val = 'Q', .name = "public-query", no_argument }, + { .val = 'U', .name = "scooper-url", required_argument }, { .val = 'b', .name = "backup", required_argument }, { .val = 'c', .name = "cert", required_argument }, { .val = 'd', .name = "database", required_argument }, @@ -766,6 +795,7 @@ int main(int argc, char *argv[]) { break; case '!': insecure = true; break; case 'N': defaultNetwork = optarg; break; case 'Q': searchQuery = Public; + break; case 'U': scooperURL = optarg; break; case 'b': backup = optarg; break; case 'c': cert = optarg; break; case 'd': path = optarg; @@ -785,6 +815,10 @@ int main(int argc, char *argv[]) { } } if (!user) user = nick; + if (scooperURL && scooperURL[0]) { + size_t len = strlen(scooperURL); + if (scooperURL[len - 1] == '/') scooperURL[len - 1] = '\0'; + } int flags = SQLITE_OPEN_READWRITE; if (init) flags |= SQLITE_OPEN_CREATE; |