aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/style.css29
-rw-r--r--dat.h13
-rw-r--r--filmoteca.c98
-rw-r--r--readme.md17
4 files changed, 157 insertions, 0 deletions
diff --git a/assets/style.css b/assets/style.css
new file mode 100644
index 0000000..792e24b
--- /dev/null
+++ b/assets/style.css
@@ -0,0 +1,29 @@
+body {
+ background-color: #ffffea;
+ color: black;
+ font-family: sans-serif;
+}
+::selection { background: #eeee9e; }
+h1 { text-align: center; }
+a {
+ color: black;
+ text-decoration: none;
+ font-size: 2em;
+}
+img#cover {
+ width: 348px;
+ height: 512px;
+ border: 4px solid #99994c;
+}
+table, th, td {
+ border: 2px solid #8888cc;
+ border-collapse: collapse;
+ background-color: #eaffff;
+}
+table ::selection { background: #9eeeee; }
+td { padding: .5em; }
+td:first-child { font-weight: bold; }
+td a {
+ text-decoration: underline dotted;
+ font-size: 1em;
+}
diff --git a/dat.h b/dat.h
index 06db25f..02d85c1 100644
--- a/dat.h
+++ b/dat.h
@@ -16,6 +16,7 @@ typedef struct Series Series;
typedef struct Season Season;
typedef struct Episode Episode;
typedef struct Resource Resource;
+typedef struct Index Index;
struct Movie {
char *release; /* release date */
@@ -89,12 +90,24 @@ enum {
Runknown
};
struct Resource {
+ char *title;
int type;
+ void *media;
+ /* this union will disappear soon */
union {
Movie movie;
Multipart multi;
Series serie;
};
+ Resource *next;
+};
+
+enum {
+ INDEXSIZE = 67,
+};
+struct Index {
+ pthread_rwlock_t lock;
+ Resource *rtab[INDEXSIZE];
};
typedef struct Req Req;
diff --git a/filmoteca.c b/filmoteca.c
index 7e928b5..458d7dd 100644
--- a/filmoteca.c
+++ b/filmoteca.c
@@ -100,11 +100,23 @@ char *wdir = "/filmoteca";
int lfd, ncpu;
pthread_t *threads;
pthread_mutex_t attendlock;
+Index catalog;
int debug;
char *argv0;
+uint
+hash(char *s)
+{
+ uint h;
+
+ h = 0x811c9dc5;
+ while(*s != 0)
+ h = (h*0x1000193) ^ (uchar)*s++;
+ return h % INDEXSIZE;
+}
+
long
truestrlen(char *s)
{
@@ -402,6 +414,92 @@ hparsereq(void)
return req;
}
+Movie *
+allocmovie(){}
+
+void
+freemovie(Movie *m){}
+
+Multipart *
+allocmultipart(){}
+
+void
+freemultipart(Multipart *m){}
+
+Series *
+allocserie(){}
+
+void
+freeserie(Series *s){}
+
+Resource *
+allocresource(char *title, int type, void *p)
+{
+ Resource *r;
+
+ r = emalloc(sizeof(Resource));
+ r->title = strdup(title);
+ r->type = type;
+ r->media = p;
+ r->next = nil;
+}
+
+void
+freeresource(Resource *r)
+{
+ free(r->title);
+ switch(r->type){
+ case Rmovie:
+ freemovie(r->media);
+ break;
+ case Rmulti:
+ freemultipart(r->media);
+ break;
+ case Rserie:
+ freeserie(r->media);
+ break;
+ }
+ free(r);
+}
+
+void
+addresource(Index *idx, Resource *r)
+{
+ Resource *rp;
+ uint h;
+
+ h = hash(r->title);
+ if(idx->rtab[h] == nil){
+ idx->rtab[h] = r;
+ return;
+ }
+ for(rp = idx->rtab[h]; rp->next != nil; rp = rp->next)
+ ;
+ rp->next = r;
+}
+
+void
+delresource(Index *idx, char *title)
+{
+ Resource *rp, *rn;
+ uint h;
+
+ h = hash(title);
+ if(strcmp(idx->rtab[h]->title, title) == 0){
+ rn = idx->rtab[h]->next;
+ freeresource(idx->rtab[h]);
+ idx->rtab[h] = rn;
+ return;
+ }
+ for(rp = idx->rtab[h]; rp->next != nil; rp = rp->next)
+ if(strcmp(rp->next->title, title) == 0){
+ rn = rp->next->next;
+ freeresource(rp->next);
+ rp->next = rn;
+ break;
+ }
+}
+
void
sendfile(Req *req, FILE *f, struct stat *fst)
{
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..0612ac3
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,17 @@
+# filmoteca
+
+1. Read doc/filmoteca.pdf
+2. Create a file tree just like the one described
+3. Run `filmoteca -d /your/filmoteca -a /your/assets -p 8080'
+4. Enjoy
+
+# Styling
+
+This is what the `-a assetsdir' option is for, you can put a
+`style.css' and a `favicon.ico' for the filmoteca to send, usually to
+web browser clients.
+
+# BUGS
+
+Any problems, errors, misbehavior you might find, please contact the
+author.