From 791e1a47049924611dbf58c5191837a89e8980a3 Mon Sep 17 00:00:00 2001 From: rodri Date: Tue, 28 Sep 2021 19:42:15 +0000 Subject: implemented part of the catalog management procedures. --- dat.h | 1 + filmoteca.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/dat.h b/dat.h index 02d85c1..b23ccb7 100644 --- a/dat.h +++ b/dat.h @@ -8,6 +8,7 @@ typedef unsigned long long uvlong; typedef uint32_t u32int; typedef struct sockaddr sockaddr; typedef struct sockaddr_in sockaddr_in; +typedef struct dirent dirent; typedef struct Movie Movie; typedef struct Multipart Multipart; diff --git a/filmoteca.c b/filmoteca.c index 458d7dd..751ac4e 100644 --- a/filmoteca.c +++ b/filmoteca.c @@ -48,12 +48,14 @@ char httpver[] = "HTTP/1.1"; char srvname[] = "filmoteca"; char errmsg[] = "NO MOVIES HERE"; char listhead[] = "\n\n\n" + "\n" "\n" "Filmoteca\n" "\n\n" "

Filmoteca

\n"; char listfeet[] = "\n\n"; char portalhead[] = "\n\n\n" + "\n" "\n" "Filmoteca - %s\n" "\n\n
\n" @@ -415,22 +417,40 @@ hparsereq(void) } Movie * -allocmovie(){} +allocmovie() +{ + +} void -freemovie(Movie *m){} +freemovie(Movie *m) +{ + +} Multipart * -allocmultipart(){} +allocmultipart() +{ + +} void -freemultipart(Multipart *m){} +freemultipart(Multipart *m) +{ + +} Series * -allocserie(){} +allocserie() +{ + +} void -freeserie(Series *s){} +freeserie(Series *s) +{ + +} Resource * allocresource(char *title, int type, void *p) @@ -500,6 +520,60 @@ delresource(Index *idx, char *title) } } +void +initindex(Index *idx) +{ + Resource *r; + Movie *m; + Multipart *mp; + Series *s; + DIR *dp; + dirent *dpe; + char **dirs, *d, path[512]; + int ndirs, rtype; + + dirs = nil; + ndirs = 0; + + filldirlist(wdir, &dirs, &ndirs); + while(ndirs > 0){ + rtype = Runknown; + d = dirs[--ndirs]; + snprint(path, sizeof path, "%s/%s", wdir, d); + dp = opendir(path); + while((dpe = readdir(dp)) != nil) + if(strcmp(dpe->d_name, "video") == 0){ + rtype = Rmovie; + break; + }else if(strcmp(dpe->d_name, "video1") == 0){ + rtype = Rmulti; + break; + }else if(strcmp(dpe->d_name, "s") == 0){ + rtype = Rserie; + break; + } + if(rtype != Runknown) + rewinddir(dp); + else{ + closedir(dp); + free(d); + continue; + } + switch(rtype){ + case Rmovie: + m = allocmovie(); + break; + case Rmulti: + mp = allocmultipart(); + break; + case Rserie: + s = allocserie(); + break; + } + free(d); + } +} + void sendfile(Req *req, FILE *f, struct stat *fst) { @@ -1167,6 +1241,9 @@ main(int argc, char *argv[]) pwd = getpwnam(runusr); if(pwd == nil) sysfatal("getpwnam: %r"); + /* good practice */ + if(setgroups(0, nil) < 0) + sysfatal("setgroups: %r"); if(setgid(pwd->pw_gid) < 0) sysfatal("setgid: %r"); if(setuid(pwd->pw_uid) < 0) -- cgit v1.2.3