summaryrefslogtreecommitdiff
path: root/shorten.c
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2020-11-15 19:12:05 -0600
committerepoch <epoch@hacking.allowed.org>2020-11-15 19:12:05 -0600
commit33c881b546d40fe88ee0a8988c654d2563d38582 (patch)
treec81d389feb917efc75c0a1d3662b9a52df8ac20d /shorten.c
parent4f9509b7fe0e345f5d8fa7540adba45b1a363f81 (diff)
parent07f78f990a68eda368d3e195edf34d42a196583e (diff)
downloaduritools-33c881b546d40fe88ee0a8988c654d2563d38582.tar.gz
uritools-33c881b546d40fe88ee0a8988c654d2563d38582.zip
merge conflict resolved
Diffstat (limited to 'shorten.c')
-rw-r--r--shorten.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/shorten.c b/shorten.c
new file mode 100644
index 0000000..ac76d84
--- /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);
+}