Improve namespacing of enum values.

This commit is contained in:
Michael Drake 2013-07-26 15:20:19 +01:00
parent 2bd587add5
commit b770130a8b
1 changed files with 100 additions and 100 deletions

View File

@ -32,30 +32,30 @@
#include "utils/log.h" #include "utils/log.h"
enum cookie_manager_field { enum cookie_manager_field {
CM_NAME, COOKIE_M_NAME,
CM_CONTENT, COOKIE_M_CONTENT,
CM_DOMAIN, COOKIE_M_DOMAIN,
CM_PATH, COOKIE_M_PATH,
CM_EXPIRES, COOKIE_M_EXPIRES,
CM_LAST_USED, COOKIE_M_LAST_USED,
CM_RESTRICTIONS, COOKIE_M_RESTRICTIONS,
CM_VERSION, COOKIE_M_VERSION,
CM_PERSISTENT, COOKIE_M_PERSISTENT,
CM_DOMAIN_FOLDER, COOKIE_M_DOMAIN_FOLDER,
N_FIELDS COOKIE_M_N_FIELDS
}; };
enum cookie_manager_value { enum cookie_manager_value {
CM_HTTPS, COOKIE_M_HTTPS,
CM_SECURE, COOKIE_M_SECURE,
CM_HTTP, COOKIE_M_HTTP,
CM_NONE, COOKIE_M_NONE,
CM_NETSCAPE, COOKIE_M_NETSCAPE,
CM_RFC2109, COOKIE_M_RFC2109,
CM_RFC2965, COOKIE_M_RFC2965,
CM_YES, COOKIE_M_YES,
CM_NO, COOKIE_M_NO,
N_VALUES COOKIE_M_N_VALUES
}; };
struct cookie_manager_folder { struct cookie_manager_folder {
@ -65,8 +65,8 @@ struct cookie_manager_folder {
struct cookie_manager_ctx { struct cookie_manager_ctx {
treeview *tree; treeview *tree;
struct treeview_field_desc fields[N_FIELDS]; struct treeview_field_desc fields[COOKIE_M_N_FIELDS];
struct treeview_field_data values[N_VALUES]; struct treeview_field_data values[COOKIE_M_N_VALUES];
bool built; bool built;
}; };
struct cookie_manager_ctx cm_ctx; struct cookie_manager_ctx cm_ctx;
@ -76,7 +76,7 @@ struct cookie_manager_entry {
treeview_node *entry; treeview_node *entry;
struct treeview_field_data data[N_FIELDS - 1]; struct treeview_field_data data[COOKIE_M_N_FIELDS - 1];
}; };
@ -95,9 +95,9 @@ static nserror cookie_manager_walk_cb(void *ctx, void *node_data,
if (type == TREE_NODE_ENTRY) { if (type == TREE_NODE_ENTRY) {
struct cookie_manager_entry *entry = node_data; struct cookie_manager_entry *entry = node_data;
if (entry->data[CM_NAME].value_len == tw->title_len && if (entry->data[COOKIE_M_NAME].value_len == tw->title_len &&
strcmp(tw->title, strcmp(tw->title,
entry->data[CM_NAME].value) == 0) { entry->data[COOKIE_M_NAME].value) == 0) {
/* Found what we're looking for */ /* Found what we're looking for */
tw->entry = entry; tw->entry = entry;
*abort = true; *abort = true;
@ -187,12 +187,12 @@ static void cookie_manager_free_treeview_field_data(
struct cookie_manager_entry *e) struct cookie_manager_entry *e)
{ {
/* Eww */ /* Eww */
free((void *)e->data[CM_NAME].value); free((void *)e->data[COOKIE_M_NAME].value);
free((void *)e->data[CM_CONTENT].value); free((void *)e->data[COOKIE_M_CONTENT].value);
free((void *)e->data[CM_DOMAIN].value); free((void *)e->data[COOKIE_M_DOMAIN].value);
free((void *)e->data[CM_PATH].value); free((void *)e->data[COOKIE_M_PATH].value);
free((void *)e->data[CM_EXPIRES].value); free((void *)e->data[COOKIE_M_EXPIRES].value);
free((void *)e->data[CM_LAST_USED].value); free((void *)e->data[COOKIE_M_LAST_USED].value);
} }
@ -235,14 +235,14 @@ static nserror cookie_manager_set_treeview_field_data(
assert(data != NULL); assert(data != NULL);
/* Set the fields up */ /* Set the fields up */
cookie_manager_field_builder(CM_NAME, cookie_manager_field_builder(COOKIE_M_NAME,
&e->data[CM_NAME], strdup(data->name)); &e->data[COOKIE_M_NAME], strdup(data->name));
cookie_manager_field_builder(CM_CONTENT, cookie_manager_field_builder(COOKIE_M_CONTENT,
&e->data[CM_CONTENT], strdup(data->value)); &e->data[COOKIE_M_CONTENT], strdup(data->value));
cookie_manager_field_builder(CM_DOMAIN, cookie_manager_field_builder(COOKIE_M_DOMAIN,
&e->data[CM_DOMAIN], strdup(data->domain)); &e->data[COOKIE_M_DOMAIN], strdup(data->domain));
cookie_manager_field_builder(CM_PATH, cookie_manager_field_builder(COOKIE_M_PATH,
&e->data[CM_PATH], strdup(data->path)); &e->data[COOKIE_M_PATH], strdup(data->path));
/* Set the Expires date field */ /* Set the Expires date field */
date = ctime(&data->expires); date = ctime(&data->expires);
@ -251,8 +251,8 @@ static nserror cookie_manager_set_treeview_field_data(
assert(date2[24] == '\n'); assert(date2[24] == '\n');
date2[24] = '\0'; date2[24] = '\0';
} }
cookie_manager_field_builder(CM_EXPIRES, cookie_manager_field_builder(COOKIE_M_EXPIRES,
&e->data[CM_EXPIRES], date2); &e->data[COOKIE_M_EXPIRES], date2);
/* Set the Last used date field */ /* Set the Last used date field */
date = ctime(&data->last_used); date = ctime(&data->last_used);
@ -261,37 +261,37 @@ static nserror cookie_manager_set_treeview_field_data(
assert(date2[24] == '\n'); assert(date2[24] == '\n');
date2[24] = '\0'; date2[24] = '\0';
} }
cookie_manager_field_builder(CM_LAST_USED, cookie_manager_field_builder(COOKIE_M_LAST_USED,
&e->data[CM_LAST_USED], date2); &e->data[COOKIE_M_LAST_USED], date2);
/* Set the Restrictions text */ /* Set the Restrictions text */
if (data->secure && data->http_only) if (data->secure && data->http_only)
e->data[CM_RESTRICTIONS] = cm_ctx.values[CM_HTTPS]; e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_HTTPS];
else if (data->secure) else if (data->secure)
e->data[CM_RESTRICTIONS] = cm_ctx.values[CM_SECURE]; e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_SECURE];
else if (data->http_only) else if (data->http_only)
e->data[CM_RESTRICTIONS] = cm_ctx.values[CM_HTTP]; e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_HTTP];
else else
e->data[CM_RESTRICTIONS] = cm_ctx.values[CM_NONE]; e->data[COOKIE_M_RESTRICTIONS] = cm_ctx.values[COOKIE_M_NONE];
/* Set the Version text */ /* Set the Version text */
switch (data->version) { switch (data->version) {
case COOKIE_NETSCAPE: case COOKIE_NETSCAPE:
e->data[CM_VERSION] = cm_ctx.values[CM_NETSCAPE]; e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_NETSCAPE];
break; break;
case COOKIE_RFC2109: case COOKIE_RFC2109:
e->data[CM_VERSION] = cm_ctx.values[CM_RFC2109]; e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_RFC2109];
break; break;
case COOKIE_RFC2965: case COOKIE_RFC2965:
e->data[CM_VERSION] = cm_ctx.values[CM_RFC2965]; e->data[COOKIE_M_VERSION] = cm_ctx.values[COOKIE_M_RFC2965];
break; break;
} }
/* Set the Persistent text */ /* Set the Persistent text */
if (data->no_destroy) if (data->no_destroy)
e->data[CM_PERSISTENT] = cm_ctx.values[CM_YES]; e->data[COOKIE_M_PERSISTENT] = cm_ctx.values[COOKIE_M_YES];
else else
e->data[CM_PERSISTENT] = cm_ctx.values[CM_NO]; e->data[COOKIE_M_PERSISTENT] = cm_ctx.values[COOKIE_M_NO];
return NSERROR_OK; return NSERROR_OK;
} }
@ -404,7 +404,7 @@ static nserror cookie_manager_create_domain_folder(
return NSERROR_NOMEM; return NSERROR_NOMEM;
} }
f->data.field = cm_ctx.fields[N_FIELDS - 1].field; f->data.field = cm_ctx.fields[COOKIE_M_N_FIELDS - 1].field;
f->data.value = strdup(data->domain); f->data.value = strdup(data->domain);
f->data.value_len = (f->data.value != NULL) ? f->data.value_len = (f->data.value != NULL) ?
strlen(data->domain) : 0; strlen(data->domain) : 0;
@ -511,95 +511,95 @@ static nserror cookie_manager_init_entry_fields(void)
int i; int i;
const char *label; const char *label;
for (i = 0; i < N_FIELDS; i++) for (i = 0; i < COOKIE_M_N_FIELDS; i++)
cm_ctx.fields[i].field = NULL; cm_ctx.fields[i].field = NULL;
cm_ctx.fields[CM_NAME].flags = TREE_FLAG_DEFAULT; cm_ctx.fields[COOKIE_M_NAME].flags = TREE_FLAG_DEFAULT;
label = "TreeviewLabelName"; label = "TreeviewLabelName";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_NAME].field) != &cm_ctx.fields[COOKIE_M_NAME].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_CONTENT].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_CONTENT].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelContent"; label = "TreeviewLabelContent";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_CONTENT].field) != &cm_ctx.fields[COOKIE_M_CONTENT].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_DOMAIN].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_DOMAIN].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelDomain"; label = "TreeviewLabelDomain";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_DOMAIN].field) != &cm_ctx.fields[COOKIE_M_DOMAIN].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_PATH].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_PATH].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelPath"; label = "TreeviewLabelPath";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_PATH].field) != &cm_ctx.fields[COOKIE_M_PATH].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_EXPIRES].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_EXPIRES].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelExpires"; label = "TreeviewLabelExpires";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_EXPIRES].field) != &cm_ctx.fields[COOKIE_M_EXPIRES].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_LAST_USED].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_LAST_USED].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelLastUsed"; label = "TreeviewLabelLastUsed";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_LAST_USED].field) != &cm_ctx.fields[COOKIE_M_LAST_USED].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_RESTRICTIONS].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_RESTRICTIONS].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelRestrictions"; label = "TreeviewLabelRestrictions";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_RESTRICTIONS].field) != &cm_ctx.fields[COOKIE_M_RESTRICTIONS].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_VERSION].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_VERSION].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelVersion"; label = "TreeviewLabelVersion";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_VERSION].field) != &cm_ctx.fields[COOKIE_M_VERSION].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_PERSISTENT].flags = TREE_FLAG_SHOW_NAME; cm_ctx.fields[COOKIE_M_PERSISTENT].flags = TREE_FLAG_SHOW_NAME;
label = "TreeviewLabelPersistent"; label = "TreeviewLabelPersistent";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_PERSISTENT].field) != &cm_ctx.fields[COOKIE_M_PERSISTENT].field) !=
lwc_error_ok) { lwc_error_ok) {
goto error; goto error;
} }
cm_ctx.fields[CM_DOMAIN_FOLDER].flags = TREE_FLAG_DEFAULT; cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].flags = TREE_FLAG_DEFAULT;
label = "TreeviewLabelDomainFolder"; label = "TreeviewLabelDomainFolder";
label = messages_get(label); label = messages_get(label);
if (lwc_intern_string(label, strlen(label), if (lwc_intern_string(label, strlen(label),
&cm_ctx.fields[CM_DOMAIN_FOLDER].field) != &cm_ctx.fields[COOKIE_M_DOMAIN_FOLDER].field) !=
lwc_error_ok) { lwc_error_ok) {
return false; return false;
} }
@ -607,7 +607,7 @@ static nserror cookie_manager_init_entry_fields(void)
return NSERROR_OK; return NSERROR_OK;
error: error:
for (i = 0; i < N_FIELDS; i++) for (i = 0; i < COOKIE_M_N_FIELDS; i++)
if (cm_ctx.fields[i].field != NULL) if (cm_ctx.fields[i].field != NULL)
lwc_string_unref(cm_ctx.fields[i].field); lwc_string_unref(cm_ctx.fields[i].field);
@ -627,45 +627,45 @@ static nserror cookie_manager_init_common_values(void)
/* Set the Restrictions text */ /* Set the Restrictions text */
temp = messages_get("CookieManagerHTTPS"); temp = messages_get("CookieManagerHTTPS");
cookie_manager_field_builder(CM_RESTRICTIONS, cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
&cm_ctx.values[CM_HTTPS], strdup(temp)); &cm_ctx.values[COOKIE_M_HTTPS], strdup(temp));
temp = messages_get("CookieManagerSecure"); temp = messages_get("CookieManagerSecure");
cookie_manager_field_builder(CM_RESTRICTIONS, cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
&cm_ctx.values[CM_SECURE], strdup(temp)); &cm_ctx.values[COOKIE_M_SECURE], strdup(temp));
temp = messages_get("CookieManagerHTTP"); temp = messages_get("CookieManagerHTTP");
cookie_manager_field_builder(CM_RESTRICTIONS, cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
&cm_ctx.values[CM_HTTP], strdup(temp)); &cm_ctx.values[COOKIE_M_HTTP], strdup(temp));
temp = messages_get("None"); temp = messages_get("None");
cookie_manager_field_builder(CM_RESTRICTIONS, cookie_manager_field_builder(COOKIE_M_RESTRICTIONS,
&cm_ctx.values[CM_NONE], strdup(temp)); &cm_ctx.values[COOKIE_M_NONE], strdup(temp));
/* Set the Cookie version text */ /* Set the Cookie version text */
assert(COOKIE_NETSCAPE == 0); assert(COOKIE_NETSCAPE == 0);
temp = messages_get("TreeVersion0"); temp = messages_get("TreeVersion0");
cookie_manager_field_builder(CM_VERSION, cookie_manager_field_builder(COOKIE_M_VERSION,
&cm_ctx.values[CM_NETSCAPE], strdup(temp)); &cm_ctx.values[COOKIE_M_NETSCAPE], strdup(temp));
assert(COOKIE_RFC2109 == 1); assert(COOKIE_RFC2109 == 1);
temp = messages_get("TreeVersion1"); temp = messages_get("TreeVersion1");
cookie_manager_field_builder(CM_VERSION, cookie_manager_field_builder(COOKIE_M_VERSION,
&cm_ctx.values[CM_RFC2109], strdup(temp)); &cm_ctx.values[COOKIE_M_RFC2109], strdup(temp));
assert(COOKIE_RFC2965 == 2); assert(COOKIE_RFC2965 == 2);
temp = messages_get("TreeVersion2"); temp = messages_get("TreeVersion2");
cookie_manager_field_builder(CM_VERSION, cookie_manager_field_builder(COOKIE_M_VERSION,
&cm_ctx.values[CM_RFC2965], strdup(temp)); &cm_ctx.values[COOKIE_M_RFC2965], strdup(temp));
/* Set the Persistent value text */ /* Set the Persistent value text */
temp = messages_get("Yes"); temp = messages_get("Yes");
cookie_manager_field_builder(CM_PERSISTENT, cookie_manager_field_builder(COOKIE_M_PERSISTENT,
&cm_ctx.values[CM_YES], strdup(temp)); &cm_ctx.values[COOKIE_M_YES], strdup(temp));
temp = messages_get("No"); temp = messages_get("No");
cookie_manager_field_builder(CM_PERSISTENT, cookie_manager_field_builder(COOKIE_M_PERSISTENT,
&cm_ctx.values[CM_NO], strdup(temp)); &cm_ctx.values[COOKIE_M_NO], strdup(temp));
return NSERROR_OK; return NSERROR_OK;
} }
@ -684,9 +684,9 @@ static void cookie_manager_delete_entry(struct cookie_manager_entry *e)
if (e->user_delete) { if (e->user_delete) {
/* Delete the cookie from URLdb */ /* Delete the cookie from URLdb */
domain = e->data[CM_DOMAIN].value; domain = e->data[COOKIE_M_DOMAIN].value;
path = e->data[CM_PATH].value; path = e->data[COOKIE_M_PATH].value;
name = e->data[CM_NAME].value; name = e->data[COOKIE_M_NAME].value;
if ((domain != NULL) && (path != NULL) && (name != NULL)) { if ((domain != NULL) && (path != NULL) && (name != NULL)) {
@ -772,7 +772,7 @@ nserror cookie_manager_init(struct core_window_callback_table *cw_t,
/* Create the cookie manager treeview */ /* Create the cookie manager treeview */
err = treeview_create(&cm_ctx.tree, &cm_tree_cb_t, err = treeview_create(&cm_ctx.tree, &cm_tree_cb_t,
N_FIELDS, cm_ctx.fields, COOKIE_M_N_FIELDS, cm_ctx.fields,
cw_t, core_window_handle, cw_t, core_window_handle,
TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS); TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
if (err != NSERROR_OK) { if (err != NSERROR_OK) {
@ -808,12 +808,12 @@ nserror cookie_manager_fini(void)
err = treeview_destroy(cm_ctx.tree); err = treeview_destroy(cm_ctx.tree);
/* Free cookie manager treeview entry fields */ /* Free cookie manager treeview entry fields */
for (i = 0; i < N_FIELDS; i++) for (i = 0; i < COOKIE_M_N_FIELDS; i++)
if (cm_ctx.fields[i].field != NULL) if (cm_ctx.fields[i].field != NULL)
lwc_string_unref(cm_ctx.fields[i].field); lwc_string_unref(cm_ctx.fields[i].field);
/* Free cookie manager treeview common entry values */ /* Free cookie manager treeview common entry values */
for (i = 0; i < N_VALUES; i++) for (i = 0; i < COOKIE_M_N_VALUES; i++)
if (cm_ctx.values[i].value != NULL) if (cm_ctx.values[i].value != NULL)
free((void *) cm_ctx.values[i].value); free((void *) cm_ctx.values[i].value);