+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_buf_freelist = 0;
+ hs->http_channel_freelist = 0;
+ return hs;
+}
+
+void http_server_destroy(http_server_t hs)
+{
+ if (hs)
+ {
+ int r;
+
+ if (hs->mutex)
+ {
+ yaz_mutex_enter(hs->mutex);
+ r = --(hs->ref_count);
+ yaz_mutex_leave(hs->mutex);
+ }
+ else
+ r = --(hs->ref_count);
+
+ if (r == 0)
+ {
+ struct http_buf *b = hs->http_buf_freelist;
+ struct http_channel *c = hs->http_channel_freelist;
+ while (b)
+ {
+ struct http_buf *b_next = b->next;
+ xfree(b);
+ b = b_next;
+ }
+ while (c)
+ {
+ struct http_channel *c_next = c->next;
+ xfree(c);
+ c = c_next;
+ }
+ xfree(hs->proxy_addr);
+ yaz_mutex_destroy(&hs->mutex);
+ 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);
+ yaz_mutex_create(&server->http_server->mutex);
+}