Replace -S flag against a generic protocol switch -P - fiche - A pastebin adjus… | |
git clone git://vernunftzentrum.de/fiche.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit e4daa5f172e6be6e9f88a74fcd3bce30187d558d | |
parent 9206dce65fc983c49c32b20df6edce7a0b896e7a | |
Author: Christian Kellermann <[email protected]> | |
Date: Fri, 2 Mar 2018 20:31:43 +0100 | |
Replace -S flag against a generic protocol switch -P | |
This allows to use fiche with a different protocol type, e.g. gopher. | |
Diffstat: | |
README.md | 6 +++--- | |
fiche.c | 15 +++++---------- | |
fiche.h | 4 ++-- | |
main.c | 12 ++++++------ | |
4 files changed, 16 insertions(+), 21 deletions(-) | |
--- | |
diff --git a/README.md b/README.md | |
@@ -203,12 +203,12 @@ __Default value:__ 4 | |
------------------------------------------------------------------------------- | |
-#### HTTPS `-S` | |
+#### protocol prefix `-P` | |
-If set, fiche returns url with https prefix instead of http | |
+If set, fiche returns url with protocol prefix 'prefix' instead of http | |
``` | |
-fiche -S | |
+fiche -P https | |
``` | |
__Output url with this parameter__: `https://localhost/xxxx`, | |
diff --git a/fiche.c b/fiche.c | |
@@ -201,8 +201,8 @@ void fiche_init(Fiche_Settings *settings) { | |
9999, | |
// slug length | |
4, | |
- // https | |
- false, | |
+ // protocol prefix | |
+ "http", | |
// buffer length | |
32768, | |
// user name | |
@@ -362,20 +362,15 @@ static void get_date(char *buf) { | |
static int set_domain_name(Fiche_Settings *settings) { | |
- char *prefix = ""; | |
- if (settings->https) { | |
- prefix = "https://"; | |
- } else { | |
- prefix = "http://"; | |
- } | |
- const int len = strlen(settings->domain) + strlen(prefix) + 1; | |
+ const int len = strlen(settings->domain) + strlen(settings->prefix) + 4; | |
char *b = malloc(len); | |
if (!b) { | |
return -1; | |
} | |
- strcpy(b, prefix); | |
+ strcpy(b, settings->prefix); | |
+ strcat(b, "://"); | |
strcat(b, settings->domain); | |
settings->domain = b; | |
diff --git a/fiche.h b/fiche.h | |
@@ -54,9 +54,9 @@ typedef struct Fiche_Settings { | |
uint8_t slug_len; | |
/** | |
- * @brief If set, returns url with https prefix instead of http | |
+ * @brief Protocol prefix to use, defaults to "http://" | |
*/ | |
- bool https; | |
+ char *prefix; | |
/** | |
* @brief Connection buffer length | |
diff --git a/main.c b/main.c | |
@@ -44,7 +44,7 @@ int main(int argc, char **argv) { | |
// Parse input arguments | |
int c; | |
- while ((c = getopt(argc, argv, "D6eSp:b:s:d:o:l:B:u:w:")) != -1) { | |
+ while ((c = getopt(argc, argv, "D6ep:b:s:d:o:P:l:B:u:w:")) != -1) { | |
switch (c) { | |
// domain | |
@@ -68,10 +68,10 @@ int main(int argc, char **argv) { | |
} | |
break; | |
- // https | |
- case 'S': | |
+ // custom protocol prefix | |
+ case 'P': | |
{ | |
- fs.https = true; | |
+ fs.prefix = optarg; | |
} | |
break; | |
@@ -121,9 +121,9 @@ int main(int argc, char **argv) { | |
default: | |
{ | |
printf("usage: fiche [-dpsSoBulbw].\n"); | |
- printf(" [-d domain] [-p port] [-s slug size]\n"); | |
+ printf(" [-d domain] [-p port] [-P protocol] [-s s… | |
printf(" [-o output directory] [-B buffer size] [-… | |
- printf(" [-l log file] [-b banlist] [-w whitelist]… | |
+ printf(" [-l log file] [-b banlist] [-w whitelist]… | |
return 0; | |
} | |
break; |