Commit 5899590e authored by Julian Rother's avatar Julian Rother

Replaced static config.h with environment-based config

parent 3a1afc55
#define CONFIG_APIKEY "key"
#define CONFIG_APIBASE "http://localhost:5000"
#define CONFIG_VIDEOS_RELEASED "/mnt/released"
#define CONFIG_VIDEOS_TMP "/mnt/video-main/kodiert"
#define CONFIG_VIDEOS_RAW "/mnt/raw"
......@@ -7,7 +7,6 @@
#include <libxml/xpathInternals.h>
#include "util.h"
#include "config.h"
static char *getxmlattr(xmlAttr *a, char *name, char *err)
{
......@@ -71,10 +70,11 @@ int main(int argc, char *argv[])
if (argc != 5)
return 1;
av_register_all();
init_env();
init_avlogbuf();
jobid = atoi(argv[1]);
path = mprintf("%s/%s", CONFIG_VIDEOS_RAW, jstr(jlookup(argv[4], "path"), ""));
path = mprintf("%s/%s", getenv(WORKER_RAW), jstr(jlookup(argv[4], "path"), ""));
ping_job(jobid, "running", 0);
opts = 0;
......
......@@ -2,7 +2,6 @@
#include <libavformat/avformat.h>
#include "util.h"
#include "config.h"
int main(int argc, char *argv[])
{
......@@ -16,13 +15,14 @@ int main(int argc, char *argv[])
if (argc != 5)
return 1;
av_register_all();
init_env();
init_avlogbuf();
memset(&pkt, 0, sizeof(pkt));
av_init_packet(&pkt);
jobid = atoi(argv[1]);
path = mprintf("%s/%s", CONFIG_VIDEOS_RELEASED, jstr(jlookup(argv[4], "path"), ""));
tmp = mprintf("%s/.tmp-%i", CONFIG_VIDEOS_TMP, jobid);
path = mprintf("%s/%s", getenv(WORKER_RELEASED), jstr(jlookup(argv[4], "path"), ""));
tmp = mprintf("%s/.tmp-%i", getenv(WORKER_TMP), jobid);
ping_job(jobid, "running", 0);
demux = 0;
......
......@@ -3,7 +3,6 @@
#include <libswscale/swscale.h>
#include "util.h"
#include "config.h"
AVFrame *scale_frame(AVFrame *frame, enum AVPixelFormat pix_fmt,
int width, int height)
......@@ -33,13 +32,14 @@ int main(int argc, char *argv[])
if (argc != 5)
return 1;
av_register_all();
init_env();
init_avlogbuf();
/* Prepare arguments */
jobid = atoi(argv[1]);
src = mprintf("%s/%s", CONFIG_VIDEOS_RELEASED, jstr(jlookup(argv[4], "path"), ""));
tmp = mprintf("%s/.tmp-%i", CONFIG_VIDEOS_TMP, jobid);
dest = mprintf("%s/thumbnail/l_%s.jpg", CONFIG_VIDEOS_RELEASED,
src = mprintf("%s/%s", getenv(WORKER_RELEASED), jstr(jlookup(argv[4], "path"), ""));
tmp = mprintf("%s/.tmp-%i", getenv(WORKER_TMP), jobid);
dest = mprintf("%s/thumbnail/l_%s.jpg", getenv(WORKER_RELEASED),
jstr(jlookup(argv[4], "lectureid"), "0"));
ping_job(jobid, "running", 0);
......
......@@ -8,7 +8,6 @@
#include <libavfilter/buffersrc.h>
#include "util.h"
#include "config.h"
void assert_empty_opts(AVDictionary *opts)
{
......@@ -261,6 +260,7 @@ int main(int argc, char *argv[])
return 1;
av_register_all();
avfilter_register_all();
init_env();
init_avlogbuf();
pkt.data = 0;
pkt.size = 0;
......@@ -270,10 +270,10 @@ int main(int argc, char *argv[])
jobid = atoi(argv[1]);
input = jlookup(argv[4], "input");
inpath = mprintf("%s/%s", CONFIG_VIDEOS_RAW, jstr(jlookup(input, "path"), ""));
inpath = mprintf("%s/%s", getenv(WORKER_RAW), jstr(jlookup(input, "path"), ""));
output = jlookup(argv[4], "output");
outpath = mprintf("%s/%s", CONFIG_VIDEOS_RELEASED, jstr(jlookup(output, "path"), ""));
tmppath = mprintf("%s/.tmp-%i", CONFIG_VIDEOS_TMP, jobid);
outpath = mprintf("%s/%s", getenv(WORKER_RELEASED), jstr(jlookup(output, "path"), ""));
tmppath = mprintf("%s/.tmp-%i", getenv(WORKER_TMP), jobid);
demux = 0;
opts = 0;
......
......@@ -17,6 +17,13 @@ double fileduration(char *path);
size_t filesize(char *path);
char *json_fileinfo(char *path);
#define WORKER_APIKEY "WORKER_APIKEY"
#define WORKER_APIBASE "WORKER_APIBASE"
#define WORKER_RELEASED "WORKER_RELEASED"
#define WORKER_TMP "WORKER_TMP"
#define WORKER_RAW "WORKER_RAW"
void init_env(void);
/* JSON av parsing */
void parse_dict(AVDictionary **d, char *s);
void parse_chapters(AVFormatContext *ctx, char *s, int64_t duration);
......
......@@ -6,7 +6,6 @@
#include <string.h>
#include "../util.h"
#include "../config.h"
static size_t curl_write_cb(char *ptr, size_t size, size_t nmemb, void *user)
{
......@@ -23,7 +22,7 @@ int ping_job(int id, char *state, char *status, ...)
if (!(curl = curl_easy_init()))
return -1;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write_cb);
e_apikey = curl_easy_escape(curl, CONFIG_APIKEY, 0);
e_apikey = curl_easy_escape(curl, getenv(WORKER_APIKEY), 0);
e_state = curl_easy_escape(curl, state, 0);
if (gethostname(BL(hostbuf)))
strcpy(hostbuf, "localhost");
......@@ -36,6 +35,7 @@ int ping_job(int id, char *state, char *status, ...)
}
else
p = strdup("{}");
printf("%s\n", p);
e_status = curl_easy_escape(curl, p, 0);
free(p);
p = mprintf("apikey=%s&state=%s&host=%s&status=%s", e_apikey, e_state,
......@@ -45,7 +45,7 @@ int ping_job(int id, char *state, char *status, ...)
curl_free(e_host);
curl_free(e_status);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, p);
url = mprintf("%s/internal/jobs/api/job/%i/ping", CONFIG_APIBASE, id);
url = mprintf("%s/internal/jobs/api/job/%i/ping", getenv(WORKER_APIBASE), id);
curl_easy_setopt(curl, CURLOPT_URL, url);
ret = curl_easy_perform(curl);
free(p);
......
#include "../util.h"
void init_env(void)
{
setenv(WORKER_APIKEY, "empty", 0);
setenv(WORKER_APIBASE, "http://127.0.0.1:999999/nourl", 0);
setenv(WORKER_RELEASED, "/var/empty/released", 0);
setenv(WORKER_TMP, "/var/empty/kodiert", 0);
setenv(WORKER_RAW, "/var/empty/raw", 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment