redirect: Add API for creating and freeing chained LsiRedirects

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
This commit is contained in:
Ikey Doherty
2017-10-22 02:47:49 +01:00
parent e45340973a
commit ffdc14c109
2 changed files with 67 additions and 3 deletions
+51
View File
@@ -38,6 +38,16 @@ void lsi_redirect_profile_free(LsiRedirectProfile *self)
if (!self) {
return;
}
/* Free all chains */
for (unsigned int i = 0; i < LSI_NUM_OPERATIONS; i++) {
LsiRedirect *r = self->op_table[i];
if (!r) {
continue;
}
lsi_redirect_free(r);
}
free(self->name);
free(self);
}
@@ -63,6 +73,47 @@ void lsi_redirect_profile_insert_rule(LsiRedirectProfile *self, LsiRedirect *red
}
}
LsiRedirect *lsi_redirect_new_path_replacement(const char *source_path, const char *target_path)
{
LsiRedirect *ret = NULL;
ret = calloc(1, sizeof(LsiRedirect));
if (!ret) {
return NULL;
}
ret->type = LSI_REDIRECT_PATH;
ret->path_source = strdup(source_path);
ret->path_target = strdup(target_path);
if (!ret->path_source || !ret->path_target) {
lsi_redirect_free(ret);
return NULL;
}
return ret;
}
void lsi_redirect_free(LsiRedirect *self)
{
if (!self) {
return;
}
/* Pass it along */
if (self->next) {
lsi_redirect_free(self->next);
}
switch (self->type) {
case LSI_REDIRECT_PATH:
default:
free(self->path_source);
free(self->path_target);
break;
}
free(self);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
+16 -3
View File
@@ -30,9 +30,8 @@ typedef struct LsiRedirect {
union {
/* Path replacement */
struct {
const char *path_source;
const char *path_target;
bool path_relative;
char *path_source;
char *path_target;
};
};
struct LsiRedirect *next;
@@ -79,6 +78,20 @@ void lsi_redirect_profile_free(LsiRedirectProfile *profile);
*/
void lsi_redirect_profile_insert_rule(LsiRedirectProfile *self, LsiRedirect *redirect);
/* LsiRedirect APIs follow */
/**
* Construct a new LsiRedirect to perform path replacements
*/
LsiRedirect *lsi_redirect_new_path_replacement(const char *source_path, const char *target_path);
/**
* Attempt to free this redirect
*
* @param redirect Pointer to allocated LsiRedirect
*/
void lsi_redirect_free(LsiRedirect *self);
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*