49 DavContext *context = calloc(1, sizeof(DavContext)); |
49 DavContext *context = calloc(1, sizeof(DavContext)); |
50 if(!context) { |
50 if(!context) { |
51 return NULL; |
51 return NULL; |
52 } |
52 } |
53 context->sessions = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_intptr, CX_STORE_POINTERS); |
53 context->sessions = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_intptr, CX_STORE_POINTERS); |
|
54 context->sessions->destructor_data = dav_session_destructor; |
54 context->http_proxy = calloc(1, sizeof(DavProxy)); |
55 context->http_proxy = calloc(1, sizeof(DavProxy)); |
55 if(!context->http_proxy) { |
56 if(!context->http_proxy) { |
56 dav_context_destroy(context); |
57 dav_context_destroy(context); |
57 return NULL; |
58 return NULL; |
58 } |
59 } |
98 return context; |
99 return context; |
99 } |
100 } |
100 |
101 |
101 void dav_context_destroy(DavContext *ctx) { |
102 void dav_context_destroy(DavContext *ctx) { |
102 // destroy all sessions assoziated with this context |
103 // destroy all sessions assoziated with this context |
103 CxIterator i = cxListIterator(ctx->sessions); |
104 // ctx->sessions destructor must be dav_session_destructor |
104 cx_foreach(DavSession*, sn, i) { |
|
105 dav_session_destroy(sn); |
|
106 } |
|
107 cxListDestroy(ctx->sessions); |
105 cxListDestroy(ctx->sessions); |
|
106 |
108 if(ctx->http_proxy) { |
107 if(ctx->http_proxy) { |
109 free(ctx->http_proxy); |
108 free(ctx->http_proxy); |
110 } |
109 } |
111 if(ctx->https_proxy) { |
110 if(ctx->https_proxy) { |
112 free(ctx->https_proxy); |
111 free(ctx->https_proxy); |
113 } |
112 } |
114 |
113 |
115 if(ctx->namespaces) { |
114 if(ctx->namespaces) { |
116 i = cxMapIteratorValues(ctx->namespaces); |
115 CxIterator i = cxMapIteratorValues(ctx->namespaces); |
117 cx_foreach(DavNamespace*, ns, i) { |
116 cx_foreach(DavNamespace*, ns, i) { |
118 if(!ns) continue; |
117 if(!ns) continue; |
119 if(ns->prefix) { |
118 if(ns->prefix) { |
120 free(ns->prefix); |
119 free(ns->prefix); |
121 } |
120 } |