Remove plugin-core physical actions

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent 628b5734e1
commit 4f9b5ccd3e
  1. 139
      src/main/plugin_core.c

@ -913,141 +913,6 @@ static liAction* core_header_overwrite(liServer *srv, liPlugin* p, liValue *val)
return li_action_new_function(core_handle_header_overwrite, NULL, core_header_free, li_value_extract(val).list);
}
typedef struct {
liAction *target_true, *target_false;
} core_conditional;
static core_conditional* core_conditional_create(liServer *srv, liValue *val, guint idx) {
core_conditional *cc;
liValue *val_true = NULL, *val_false = NULL;
liAction *act_true = NULL, *act_false = NULL;
GArray *l;
if (idx == 0 && val->type == LI_VALUE_ACTION) {
cc = g_slice_new0(core_conditional);
act_true = val->data.val_action.action;
li_action_acquire(act_true);
cc->target_true = act_true;
return cc;
}
if (val->type != LI_VALUE_LIST) {
ERROR(srv, "unexpected parameter of type %s, expected list", li_value_type_string(val->type));
return NULL;
}
l = val->data.list;
if (idx >= l->len) {
ERROR(srv, "expected at least %u parameters, %u given", idx+1, l->len);
}
val_true = g_array_index(l, liValue*, idx);
if (idx + 1 < l->len) val_false = g_array_index(l, liValue*, idx+1);
if (val_true->type == LI_VALUE_NONE) {
act_true = NULL;
} else if (val_true->type == LI_VALUE_ACTION) {
act_true = val_true->data.val_action.action;
} else {
ERROR(srv, "expected action at entry %u of list, got %s", idx, li_value_type_string(val_true->type));
}
if (val_false) {
if (val_false->type == LI_VALUE_NONE) {
act_false = NULL;
} else if (val_false->type == LI_VALUE_ACTION) {
act_false = val_false->data.val_action.action;
} else {
ERROR(srv, "expected action at entry %u of list, got %s", idx+1, li_value_type_string(val_false->type));
}
} else {
act_false = NULL;
}
cc = g_slice_new0(core_conditional);
if (act_true) li_action_acquire(act_true);
if (act_false) li_action_acquire(act_false);
cc->target_true = act_true;
cc->target_false = act_false;
return cc;
}
static void core_conditional_free(liServer *srv, gpointer param) {
core_conditional *cc = (core_conditional*) param;
if (!cc) return;
li_action_release(srv, cc->target_true);
li_action_release(srv, cc->target_false);
g_slice_free(core_conditional, cc);
}
static liHandlerResult core_conditional_do(liVRequest *vr, gpointer param, gboolean way) {
core_conditional *cc = (core_conditional*)param;
if (way) { if (cc->target_true) li_action_enter(vr, cc->target_true); }
else { if (cc->target_false) li_action_enter(vr, cc->target_false); }
return LI_HANDLER_GO_ON;
}
static liHandlerResult core_handle_physical_exists(liVRequest *vr, gpointer param, gpointer *context) {
struct stat st;
int err;
liHandlerResult res;
UNUSED(context);
if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE);
res = li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL);
if (res == LI_HANDLER_WAIT_FOR_EVENT)
return res;
return core_conditional_do(vr, param, (res == LI_HANDLER_GO_ON));
}
static liAction* core_physical_exists(liServer *srv, liPlugin* p, liValue *val) {
core_conditional *cc = core_conditional_create(srv, val, 0);
UNUSED(p);
if (!cc) return NULL;
return li_action_new_function(core_handle_physical_exists, NULL, core_conditional_free, cc);
}
static liHandlerResult core_handle_physical_is_file(liVRequest *vr, gpointer param, gpointer *context) {
struct stat st;
int err;
liHandlerResult res;
UNUSED(context);
if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE);
res = li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL);
if (res == LI_HANDLER_WAIT_FOR_EVENT)
return res;
return core_conditional_do(vr, param, (res == LI_HANDLER_GO_ON && S_ISREG(st.st_mode)));
}
static liAction* core_physical_is_file(liServer *srv, liPlugin* p, liValue *val) {
core_conditional *cc = core_conditional_create(srv, val, 0);
UNUSED(p);
if (!cc) return NULL;
return li_action_new_function(core_handle_physical_is_file, NULL, core_conditional_free, cc);
}
static liHandlerResult core_handle_physical_is_dir(liVRequest *vr, gpointer param, gpointer *context) {
struct stat st;
int err;
liHandlerResult res;
UNUSED(context);
if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE);
res = li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL);
if (res == LI_HANDLER_WAIT_FOR_EVENT)
return res;
return core_conditional_do(vr, param, (res == LI_HANDLER_GO_ON && S_ISDIR(st.st_mode)));
}
static liAction* core_physical_is_dir(liServer *srv, liPlugin* p, liValue *val) {
core_conditional *cc = core_conditional_create(srv, val, 0);
UNUSED(p);
if (!cc) return NULL;
return li_action_new_function(core_handle_physical_is_dir, NULL, core_conditional_free, cc);
}
/* chunkqueue memory limits */
static liHandlerResult core_handle_buffer_out(liVRequest *vr, gpointer param, gpointer *context) {
gint limit = GPOINTER_TO_INT(param);
@ -1327,10 +1192,6 @@ static const liPluginAction actions[] = {
{ "header_append", core_header_append },
{ "header_overwrite", core_header_overwrite },
{ "physical.exists", core_physical_exists },
{ "physical.is_file", core_physical_is_file },
{ "physical.is_dir", core_physical_is_dir },
{ "buffer.out", core_buffer_out },
{ "buffer.in", core_buffer_in },

Loading…
Cancel
Save