us_http_header_item_t *us_http_header_item_list_addn( us_http_header_item_list_t *self, const char *key, int key_len, const char *value, int value_len ) { us_http_header_item_t *item; item = us_new( self->m_allocator, us_http_header_item_t ); if ( item ) { item->m_key = 0; item->m_value = 0; item->m_key = us_strndup( self->m_allocator, key, key_len ); if ( item->m_key ) { item->m_value = us_strndup( self->m_allocator, value, value_len ); } if ( item->m_key == 0 || item->m_value == 0 ) { us_delete( self->m_allocator, item->m_key ); us_delete( self->m_allocator, item->m_value ); us_delete( self->m_allocator, item ); item = 0; } else { item->m_next = self->m_first; self->m_first = item; } } return item; }
us_reactor_handler_t *us_reactor_handler_create(us_allocator_t *allocator) { us_reactor_handler_t *item = 0; item = us_new(allocator, us_reactor_handler_t); if (item != NULL) { if (!us_reactor_handler_init(item, allocator, -1, 0)) { us_delete(allocator, item); item = 0; } } return item; }
us_http_header_item_list_t *us_http_header_item_list_create(us_allocator_t *allocator) { us_http_header_item_list_t *self = us_new(allocator, us_http_header_item_list_t); if (self) { self->destroy = us_http_header_item_list_destroy; self->add = us_http_header_item_list_add; self->addn = us_http_header_item_list_addn; self->find = us_http_header_item_list_find; self->remove = us_http_header_item_list_remove; self->m_allocator = allocator; self->m_first = 0; } return self; }
us_http_response_header_t *us_http_response_header_create(us_allocator_t *allocator) { us_http_response_header_t *self; self = us_new(allocator, us_http_response_header_t); if (self) { self->m_allocator = allocator; self->destroy = us_http_response_header_destroy; self->m_code = 0; self->m_version = us_strdup(allocator, "HTTP/1.1"); self->m_items = us_http_header_item_list_create(allocator); if (!self->m_items) { self->destroy(self); self = 0; } } return self; }
us_http_request_header_t *us_http_request_header_create(us_allocator_t *allocator) { us_http_request_header_t *self; self = us_new(allocator, us_http_request_header_t); if (self) { self->m_allocator = allocator; self->destroy = us_http_request_header_destroy; self->m_items = us_http_header_item_list_create(allocator); self->m_method = 0; self->m_path = 0; self->m_version = 0; if (self->m_items == 0) { us_delete(allocator, self); self = 0; } } return self; }
us_print_t *us_printbuf_create( us_allocator_t *allocator, int memory_length ) { us_print_t *r = 0; us_printbuf_t *self = us_new( allocator, us_printbuf_t ); if ( self ) { self->m_base.m_buffer = (char *)allocator->alloc( allocator, memory_length, 1 ); self->m_base.m_base.destroy = us_printraw_destroy; self->m_base.m_base.printf = us_printraw_printf; self->m_base.m_base.vprintf = us_printraw_vprintf; if ( self->m_base.m_buffer ) { r = &self->m_base.m_base; } else { us_delete( allocator, self ); } } return r; }
us_reactor_handler_t *us_http_server_handler_create(us_allocator_t *allocator) { return (us_reactor_handler_t *)us_new(allocator, us_http_server_handler_t); }