Add a way to set arbitrary data accessible by all tasks. Use it to allow autologin for testing multiple instances more easily.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3689 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
35
src/task.c
35
src/task.c
@ -107,6 +107,7 @@ typedef struct _tf_task_t {
|
||||
int _https_port;
|
||||
char _db_path[256];
|
||||
char _secrets_path[256];
|
||||
const char* _args;
|
||||
} tf_task_t;
|
||||
|
||||
typedef struct _export_record_t {
|
||||
@ -1260,6 +1261,35 @@ void tf_task_activate(tf_task_t* task)
|
||||
JS_SetPropertyStr(context, tildefriends, "ssb_port", JS_NewInt32(context, task->_ssb_port));
|
||||
JS_SetPropertyStr(context, tildefriends, "http_port", JS_NewInt32(context, task->_http_port));
|
||||
JS_SetPropertyStr(context, tildefriends, "https_port", JS_NewInt32(context, task->_https_port));
|
||||
JSValue args = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, tildefriends, "args", args);
|
||||
if (task->_args)
|
||||
{
|
||||
char* saveptr = NULL;
|
||||
char* copy = strdup(task->_args);
|
||||
char* start = copy;
|
||||
while (true)
|
||||
{
|
||||
char* assignment = strtok_r(start, ",", &saveptr);
|
||||
start = NULL;
|
||||
if (!assignment)
|
||||
{
|
||||
break;
|
||||
}
|
||||
char* equals = strchr(assignment, '=');
|
||||
if (equals)
|
||||
{
|
||||
*equals = '\0';
|
||||
JS_SetPropertyStr(context, args, assignment, JS_NewString(context, equals + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Assignment missing '=': %s.\n", assignment);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
JS_SetPropertyStr(context, global, "tildefriends", tildefriends);
|
||||
|
||||
if (task->_trusted)
|
||||
@ -1463,6 +1493,11 @@ void tf_task_set_secrets_path(tf_task_t* task, const char* secrets_path)
|
||||
snprintf(task->_secrets_path, sizeof(task->_secrets_path), "%s", secrets_path);
|
||||
}
|
||||
|
||||
void tf_task_set_args(tf_task_t* task, const char* args)
|
||||
{
|
||||
task->_args = args;
|
||||
}
|
||||
|
||||
const char* tf_task_get_name(tf_task_t* task)
|
||||
{
|
||||
return task->_scriptName;
|
||||
|
Reference in New Issue
Block a user