static int on_accepted(const struct jbxm_initconf_st* iconf, struct jbxm_callback_if_st* cbif) { assert(iconf); assert(cbif); assert(cbif->type == JBXM_CBT_ACCEPTED); bool success = false; struct UserData_st* ud = calloc(1, sizeof(struct UserData_st)); if (! ud) { fprintf(stderr, "error: calloc (errno=%d)\n", errno); goto EXIT_LABEL; } // set ud members ud->headers = hm_init(19); if (! ud->headers) { fprintf(stderr, "error: hm_init\n"); goto EXIT_LABEL; } ud->body_chunks = ll_init(free_varmem); if (! ud->body_chunks) { fprintf(stderr, "error: ll_init\n"); goto EXIT_LABEL; } // save to memory dbSET0(cbif, "user-data", ud); success = true; EXIT_LABEL: if (! success) { if (ud) { hm_free(ud->headers); ll_free(ud->body_chunks); free(ud); } return -1; } return 0; }
hashmap_t *hm_init ( int sizefactor ) { hashmap_t *hm = malloc ( sizeof ( hashmap_t ) ); if ( ! hm ) return NULL; if ( sizefactor <= 0 ) sizefactor = 1; hm->capacity = sizefactor * INITIAL_SIZE; hm->size = 0; hm->buckets = calloc ( hm->capacity, sizeof ( bucket_t * ) ); if ( ! hm->buckets ) { hm_free ( hm ); return NULL; } return hm; }
static int on_disconnect(const struct jbxm_initconf_st* iconf, struct jbxm_callback_if_st* cbif) { assert(iconf); assert(cbif); assert(cbif->type == JBXM_CBT_DISCONNECT); struct UserData_st* ud = NULL; dbUNSET(cbif, "user-data", &ud); assert(ud); free(ud->method); free(ud->path); free(ud->response); hm_clear(ud->headers, free_header_); hm_free(ud->headers); ll_free(ud->body_chunks); free(ud); return 0; }