Browse Source

Add handling for environment vars in backends

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
95fee3059b
  1. 16
      include/lighttpd/environment.h
  2. 3
      include/lighttpd/typedefs.h
  3. 1
      include/lighttpd/virtualrequest.h
  4. 27
      src/environment.c

16
include/lighttpd/environment.h

@ -9,6 +9,12 @@ struct environment {
GHashTable *table;
};
/* read only duplicate of a real environment: use it to remember which
env vars you already sent (mod_fastcgi) */
struct environment_dup {
GHashTable *table;
};
LI_API void environment_init(environment *env);
LI_API void environment_reset(environment *env);
LI_API void environment_clear(environment *env);
@ -20,4 +26,14 @@ LI_API void environment_insert(environment *env, const gchar *key, size_t keylen
LI_API void environment_remove(environment *env, const gchar *key, size_t keylen);
LI_API GString* environment_get(environment *env, const gchar *key, size_t keylen);
/* create (data) read only copy of a environment; don't modify the real environment
while using the duplicate */
LI_API environment_dup* environment_make_dup(environment *env);
LI_API void environment_dup_free(environment_dup *envdup);
/* remove an entry (this is allowed - it doesn't modify anything in the original environment);
you must not modify the returned GString */
LI_API GString* environment_dup_pop(environment_dup *envdup, const gchar *key, size_t keylen);
#endif

3
include/lighttpd/typedefs.h

@ -65,6 +65,9 @@ typedef struct connection connection;
struct environment;
typedef struct environment environment;
struct environment_dup;
typedef struct environment_dup environment_dup;
/* hhtp_headers.h */
struct http_header;

1
include/lighttpd/virtualrequest.h

@ -69,6 +69,7 @@ struct vrequest {
physical physical;
response response;
/* environment entries will be passed to the backends */
environment env;
/* -> vr_in -> filters_in -> in -> handle -> out -> filters_out -> vr_out -> */

27
src/environment.c

@ -43,3 +43,30 @@ GString* environment_get(environment *env, const gchar *key, size_t keylen) {
const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */
return (GString*) g_hash_table_lookup(env->table, &skey);
}
environment_dup* environment_make_dup(environment *env) {
GHashTableIter i;
GHashTable *tdst;
gpointer key, val;
environment_dup *envdup = g_slice_new0(environment_dup);
envdup->table = tdst = g_hash_table_new((GHashFunc) g_string_hash, (GEqualFunc) g_string_equal);
g_hash_table_iter_init(&i, env->table);
while (g_hash_table_iter_next(&i, &key, &val)) {
g_hash_table_insert(tdst, key, val);
}
return envdup;
}
void environment_dup_free(environment_dup *envdup) {
g_hash_table_destroy(envdup->table);
g_slice_free(environment_dup, envdup);
}
GString* environment_dup_pop(environment_dup *envdup, const gchar *key, size_t keylen) {
const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */
GString *sval = (GString*) g_hash_table_lookup(envdup->table, &skey);
if (sval) g_hash_table_remove(envdup->table, &skey);
return sval;
}

Loading…
Cancel
Save