-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: uritools
action: commit
revision:
path_from:
revision_from: 07f78f990a68eda368d3e195edf34d42a196583e:
path_to:
revision_to:

git.thebackupbox.net

uritools

git://git.thebackupbox.net/uritools

commit 07f78f990a68eda368d3e195edf34d42a196583e
Author: epoch <epoch@hack.thebackupbox.net>
Date:   Mon Nov 16 00:53:44 2020 +0000

    added a shorten program that I use in except for making shortened links on epo.k.vu

diff --git a/.gitignore b/.gitignore

index 6dc11bf71aa94da21bcc6a94fa7f5b7eed042096..

index ..e76a1a05e2c258a12e707af48e2009ec5e8f8537 100644

--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ uriescape
 urimatch
 uriunescape
 urijoin
+shorten
diff --git a/Makefile b/Makefile

index 7809a59af514eebefce725b66d848ef5ca2730c4..

index ..39106252a45d9c6b7b576d17d2f34c50a84963b8 100644

--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,10 @@ CFLAGS:=-std=c11 -pedantic -Wall
 PREFIX:=/usr/local
 CC:=gcc

-all: urimatch uricut urijoin uricmp uriunescape uriescape
+all: urimatch uricut urijoin uricmp uriunescape uriescape shorten
+
+shorten: LDFLAGS=-lcrypto
+shorten: shorten.c

 urimatch: urimatch.c uri.h

@@ -37,3 +40,6 @@ install: all
 	install -t $(PREFIX)/bin copy_start_nevermind.sh
 	install -t $(PREFIX)/bin choose
 	install -t $(PREFIX)/bin query_param
+	install -t $(PREFIX)/bin shorten
+	chgrp shorten $(PREFIX)/bin/shorten
+	chmod g+s $(PREFIX)/bin/shorten
diff --git a/shorten.c b/shorten.c
new file mode 100644
index 0000000000000000000000000000000000000000..ac76d84d18803a621a06263e47b8e02f594fc9d3
--- /dev/null
+++ b/shorten.c
@@ -0,0 +1,37 @@
+#define _POSIX_C_SOURCE 200908
+#include <stdio.h>
+#include <sys/stat.h>
+#include <openssl/md5.h>
+#include <string.h>
+//#include <sys/types.h>
+#include <sys/xattr.h>
+
+#define BYTES_IN_SHORT 2
+#define CACHE_DIR "/var/cache/shorten"
+
+int main(int argc,char *argv[]) {
+  int i;
+  if(argc < 2) return 1;
+  unsigned char *p=MD5((unsigned char *)argv[1],strlen(argv[1]),NULL);
+  char filepath[4096];//too long, oh well
+  char out[256];
+  char tmp[3];
+  strcpy(out,"");
+  for(i=0;i<BYTES_IN_SHORT;i++) {
+    snprintf(tmp,sizeof(tmp),"%02x",p[i]);
+    strcat(out,tmp);
+  }
+  printf("%s\n",out);
+  snprintf(filepath,sizeof(filepath)-1,"%s/%s",CACHE_DIR,out);
+  FILE *fp;
+  if((fp=fopen(filepath,"w")) == NULL) {
+    fprintf(stderr,"shorten: failed to write a file: %s\n",filepath);
+    return 1;
+  }
+  fprintf(fp,"%s\n",argv[1]);
+  //disabled for now because tmpfs can't do extended attributes
+  //fprintf(stderr,"fsetxattr return: %d\n",fsetxattr(fileno(fp),"user.mime-type","text/uri-list",strlen("text/uri-list"),0));
+  //perror("fsetxattr");
+  fchmod(fileno(fp),0664);
+  fclose(fp);
+}

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 16:11:50 2024