- mod_path (untested)
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 23 Sep 2018 01:59:08 +0000 (04:59 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 23 Sep 2018 01:59:08 +0000 (04:59 +0300)
- mod_archive stub
- mod_url incomplete

src/assman.h
src/assman_impl.h
src/mod_archive.c [new file with mode: 0644]
src/mod_path.c
src/mod_url.c [new file with mode: 0644]

index 4daec0d..ecd905e 100644 (file)
@@ -24,6 +24,8 @@ enum {
 extern "C" {
 #endif
 
+int ass_errno;
+
 void ass_set_option(int opt, int val);
 int ass_get_option(int opt);
 
index 7161da1..1e089b2 100644 (file)
@@ -33,6 +33,8 @@ void ass_free_archive(struct ass_fileops *fop);
 struct ass_fileops *ass_alloc_url(const char *url);
 void ass_free_url(struct ass_fileops *fop);
 
+int ass_mod_url_max_threads;
+char ass_mod_url_cachedir[512];
 
 
 #endif /* ASSMAN_IMPL_H_ */
diff --git a/src/mod_archive.c b/src/mod_archive.c
new file mode 100644 (file)
index 0000000..dd5af4e
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "assman_impl.h"
+
+struct ass_fileops *ass_alloc_archive(const char *fname)
+{
+       fprintf(stderr, "assman: archive asset handler not implemented yet\n");
+       return 0;       /* TODO */
+}
+
+void ass_free_archive(struct ass_fileops *fop)
+{
+}
index 1776ece..1a680e6 100644 (file)
@@ -1,4 +1,14 @@
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+
+#ifdef __MSVCRT__
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
 
 #include "assman_impl.h"
 
@@ -26,7 +36,7 @@ struct ass_fileops *ass_alloc_path(const char *path)
        while(*path) {
                *p++ = *path++;
        }
-       while(p > fop->udata && (p[-1] == '/' || isspace(p[-1]))) p--;
+       while(p > (char*)fop->udata && (p[-1] == '/' || isspace(p[-1]))) p--;
        *p = 0;
 
        fop->open = fop_open;
@@ -36,10 +46,39 @@ struct ass_fileops *ass_alloc_path(const char *path)
        return fop;
 }
 
+void ass_free_path(struct ass_fileops *fop)
+{
+       free(fop->udata);
+}
+
 static void *fop_open(const char *fname, void *udata)
 {
+       const char *prefix = (char*)udata;
+       char *path;
+       FILE *fp;
+
+       path = alloca(strlen(prefix) + strlen(fname) + 2);
+       sprintf(path, "%s/%s", path, fname);
+
+       if(!(fp = fopen(path, "rb"))) {
+               ass_errno = errno;
+               return 0;
+       }
+       return fp;
 }
 
-static void fop_close(void *fp, void *udata);
-static long fop_seek(void *fp, long offs, int whence, void *udata);
-static long fop_read(void *fp, void *buf, long size, void *udata);
+static void fop_close(void *fp, void *udata)
+{
+       fclose(fp);
+}
+
+static long fop_seek(void *fp, long offs, int whence, void *udata)
+{
+       fseek(fp, offs, whence);
+       return ftell(fp);
+}
+
+static long fop_read(void *fp, void *buf, long size, void *udata)
+{
+       return fread(buf, 1, size, fp);
+}
diff --git a/src/mod_url.c b/src/mod_url.c
new file mode 100644 (file)
index 0000000..f254b68
--- /dev/null
@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef BUILD_MOD_URL
+#include <curl/curl.h>
+
+static const char *get_temp_dir(void);
+
+static char *tmpdir, *cachedir;
+
+struct ass_fileops *ass_alloc_url(const char *url)
+{
+       static int done_init;
+       struct ass_fileops *fop;
+
+       if(!done_init) {
+               curl_global_init(CURL_GLOBAL_ALL);
+               atexit(curl_global_cleanup);
+               done_init = 1;
+
+               if(!*ass_mod_url_cachedir) {
+                       strcpy(ass_mod_url_cachedir, "assman_cache");
+               }
+               tmpdir = get_temp_dir();
+               if(!(cachedir = malloc(strlen(ass_mod_url_cachedir) + strlen(tmpdir) + 2))) {
+                       fprintf(stderr, "assman: failed to allocate cachedir path buffer\n");
+                       return 0;
+               }
+               sprintf(cachedir, "%s/%s", tmpdir, ass_mod_url_cachedir);
+       }
+
+       if(!(fop = malloc(sizeof *fop))) {
+               return 0;
+       }
+
+       fop->udata = 0;
+       fop->open = fop_open;
+       fop->close = fop_close;
+       fop->seek = fop_seek;
+       fop->read = fop_read;
+       return fop;
+}
+
+void ass_free_url(struct ass_fileops *fop)
+{
+}
+
+static void *fop_open(const char *fname, void *udata)
+{
+       return 0;       /* TODO */
+}
+
+static void fop_close(void *fp, void *udata)
+{
+}
+
+static long fop_seek(void *fp, long offs, int whence, void *udata)
+{
+       return 0;
+}
+
+static long fop_read(void *fp, void *buf, long size, void *udata)
+{
+       return 0;
+}
+
+#else
+int ass_mod_url_disabled;
+#endif