From 851e1a95f0d470e6c59d80d39e35fcea04128b48 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" <june@causal.agency> Date: Sun, 19 Jul 2020 16:09:54 -0400 Subject: Add -U scooper-url option to make scooper links --- litterbox.1 | 13 ++++++++++++- litterbox.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/litterbox.1 b/litterbox.1 index 6e9f64c..b7d0111 100644 --- a/litterbox.1 +++ b/litterbox.1 @@ -1,4 +1,4 @@ -.Dd May 21, 2020 +.Dd July 19, 2020 .Dt LITTERBOX 1 .Os . @@ -10,6 +10,7 @@ .Nm .Op Fl Qqv .Op Fl N Ar network +.Op Fl U Ar url .Op Fl c Ar cert .Op Fl d Ar path .Op Fl h Ar host @@ -113,6 +114,16 @@ The searchable columns are For search query syntax, see .Aq Lk https://www.sqlite.org/fts5.html#full_text_query_syntax . . +.It Fl U Ar url , Cm scooper-url = Ar url +Set the base URL of a +.Xr scooper 1 +instance +used to construct links to full search results +in response to the search query interface enabled by +.Fl Q +or +.Fl q . +. .It Fl b Ar path Perform a live database backup to .Ar path 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; -- cgit 1.4.1 <td>June McEnroe</td></tr> <tr><td><span title='2024-11-05 20:43:34 -0500'>2024-11-05</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-10-23/lens?id=1fd0682a0f2eea92867b20502c70716b1400f33f&follow=1'>Add a bunch of photos</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-12 23:37:16 -0400'>2024-10-12</span></td><td><a href='/src/commit/www/text.causal.agency/Makefile?id=9efb52aadc5c3c65701b998a5adcca8cb8b4a8c2&follow=1'>Publish "film review"</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-12 17:53:09 -0400'>2024-10-12</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-10-06/lens?id=300e2dd0e4cea019f0d247b90226fdf3fa5759c7&follow=1'>Add photos from October 6</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-12 10:28:02 -0400'>2024-10-12</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-10-05/lens?id=8896a95764f011c24d0817c07e23bfa4887f7da1&follow=1'>Add photos from October 5</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-09 22:12:27 -0400'>2024-10-09</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-10-01/lens?id=a147012a38017ee519ce35b3acbb0e55f3638f7b&follow=1'>Add photos from October 1</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-07 19:16:29 -0400'>2024-10-07</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-29/lens?id=1dde71aa57ac73f9f15b8a9666c36b2173bb4592&follow=1'>Add photos from September 29</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-07 18:05:03 -0400'>2024-10-07</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-28/lens?id=078d89ff74d02fd854f8de93fe225e6670644d50&follow=1'>Add photos from September 28</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-10-07 14:57:20 -0400'>2024-10-07</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-22/lens?id=1215130a85ee9abe70d2e2c8af4eb0be368f4294&follow=1'>Add photos from September 22</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-25 10:05:37 -0400'>2024-09-25</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-15/lens?id=1a4a0628513359733a2450cf38e73166f7e5cbe6&follow=1'>Add photos from September 15</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-24 18:06:38 -0400'>2024-09-24</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-14/lens?id=16992208ec0549fdbc776da35c9f799126d15d89&follow=1'>Add photos from September 14</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-24 10:13:27 -0400'>2024-09-24</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-12/lens?id=de6decda3177ae64859be30d68ba1e3c4c132ec1&follow=1'>Add photos from September 12</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-24 09:50:19 -0400'>2024-09-24</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-07/lens?id=49a105101493f4dd51259dd62dcbd24df0909bd3&follow=1'>Add photos from September 7</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-24 09:48:24 -0400'>2024-09-24</span></td><td><a href='/src/commit/www/photo.causal.agency/generate.sh?id=55728948b94a17b99fabeb1c61d20c5ef18c7f73&follow=1'>Allow not having descriptions</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-23 17:44:15 -0400'>2024-09-23</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=9a38d0932d64b4a2ed5a6a2499490094d3bf8e7e&follow=1'>Automatically select the last used lens for a body</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-19 23:20:42 -0400'>2024-09-19</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-05/lens?id=894873c86c5397a92499de39b4c52b5e99801441&follow=1'>Add photos from September 5</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-15 16:02:27 -0400'>2024-09-15</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=32b69f7df4c155d7a09f140a53c3b39a330027e4&follow=1'>Add some more film stocks to the list</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-13 20:06:35 -0400'>2024-09-13</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-09-02/lens?id=45e859f37e503f2c85a3085a628226831e394b7b&follow=1'>Add photos from September 2</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-13 12:54:24 -0400'>2024-09-13</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=57e90a2d8f5f9b6385ffeb0e0e7b3237cb395b80&follow=1'>Add Fomapan 200 to films list</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-10 20:30:28 -0400'>2024-09-10</span></td><td><a href='/src/commit/www/photo.causal.agency/2024-08-29/lens?id=1134af7da7776a0631995094a9225ce3541a9518&follow=1'>Add August 29 picnic photos</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-08 19:44:08 -0400'>2024-09-08</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=775260288133dc90bb600785772ac931854aa618&follow=1'>Apply some bold to trips rendering</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-08 19:38:22 -0400'>2024-09-08</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=dd7fda85bcc69cd4cd35e006cffabf3bdf765104&follow=1'>Render trips hopefully more efficiently</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-08 19:26:18 -0400'>2024-09-08</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=02cac2ffadee1d3f66426bb48a64aea78907878c&follow=1'>Allow removing bodies and lenses</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-08 10:59:25 -0400'>2024-09-08</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=2c25b7204ecab1be0d128d984eabe35b10a3a418&follow=1'>Limit body width so it looks less silly on desktop</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-07 21:02:03 -0400'>2024-09-07</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=74df90da35ed7886c4067fae700c9db1d3b2ef0a&follow=1'>Handle no film being loaded</a></td><td>June McEnroe</td></tr> <tr><td><span title='2024-09-07 20:58:45 -0400'>2024-09-07</span></td><td><a href='/src/commit/www/photo.causal.agency/trips.html?id=a7f8aa5246afbf9c01ca295bdd2af0e11faeb7d3&follow=1'>Fancy up the text a little</a></td><td>June McEnroe