+ wrbuf_destroy(w);
+
+ server->http_server->proxy_addr = xmalloc(sizeof(struct sockaddr_in));
+ server->http_server->proxy_addr->sin_family = he->h_addrtype;
+ memcpy(&server->http_server->proxy_addr->sin_addr.s_addr,
+ he->h_addr_list[0], he->h_length);
+ server->http_server->proxy_addr->sin_port = htons(port);
+}
+
+static void http_fire_observers(struct http_channel *c)
+{
+ http_channel_observer_t p = c->observers;
+ while (p)
+ {
+ p->destroy(p->data, c, p->data2);
+ p = p->next;
+ }
+}
+
+static void http_destroy_observers(struct http_channel *c)
+{
+ while (c->observers)
+ {
+ http_channel_observer_t obs = c->observers;
+ c->observers = obs->next;
+ xfree(obs);
+ }
+}
+
+http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
+ http_channel_destroy_t des)
+{
+ http_channel_observer_t obs = xmalloc(sizeof(*obs));
+ obs->chan = c;
+ obs->data = data;
+ obs->data2 = 0;
+ obs->destroy= des;
+ obs->next = c->observers;
+ c->observers = obs;
+ return obs;
+}
+
+void http_remove_observer(http_channel_observer_t obs)
+{
+ struct http_channel *c = obs->chan;
+ http_channel_observer_t found, *p = &c->observers;
+ while (*p != obs)
+ p = &(*p)->next;
+ found = *p;
+ assert(found);
+ *p = (*p)->next;
+ xfree(found);
+}
+
+struct http_channel *http_channel_observer_chan(http_channel_observer_t obs)
+{
+ return obs->chan;
+}
+
+void http_observer_set_data2(http_channel_observer_t obs, void *data2)
+{
+ obs->data2 = data2;
+}
+
+http_server_t http_server_create(void)
+{
+ http_server_t hs = xmalloc(sizeof(*hs));
+ hs->mutex = 0;
+ hs->proxy_addr = 0;
+ hs->ref_count = 1;
+ hs->http_sessions = 0;
+
+ hs->record_file = 0;
+ return hs;
+}
+
+void http_server_destroy(http_server_t hs)
+{
+ if (hs)
+ {
+ int r;
+
+ yaz_mutex_enter(hs->mutex); /* OK: hs->mutex may be NULL */
+ r = --(hs->ref_count);
+ yaz_mutex_leave(hs->mutex);
+
+ if (r == 0)
+ {
+ http_sessions_destroy(hs->http_sessions);
+ xfree(hs->proxy_addr);
+ yaz_mutex_destroy(&hs->mutex);
+ if (hs->record_file)
+ fclose(hs->record_file);
+ xfree(hs);
+ }
+ }
+}
+
+void http_server_incref(http_server_t hs)
+{
+ assert(hs);
+ yaz_mutex_enter(hs->mutex);
+ (hs->ref_count)++;
+ yaz_mutex_leave(hs->mutex);
+}
+
+void http_mutex_init(struct conf_server *server)
+{
+ assert(server);
+
+ assert(server->http_server->mutex == 0);
+ pazpar2_mutex_create(&server->http_server->mutex, "http_server");
+ server->http_server->http_sessions = http_sessions_create();