static PyObject * PongoDict_json(PongoDict *self, PyObject *args) { char *key = NULL, *val = NULL; Py_ssize_t klen, vlen; PyObject *ret = Py_None; dbtype_t dict, obj, k; jsonctx_t *jctx; if (!PyArg_ParseTuple(args, "|s#s#:json", &key, &klen, &val, &vlen)) return NULL; dblock(self->ctx); dict = self->dbptr; jctx = json_init(self->ctx); if (key) { if (val) { // 2-arg form is dict.json('key', 'value') // inserts dict['key'] = json_parse('value') k = dbstring_new(self->ctx, key, klen); obj = json_parse(jctx, val, vlen); dbobject_setitem(SELF_CTX_AND_DBPTR, k, obj, self->ctx->sync); } else { // 1-arg form is replace dict.items with parsed json obj = json_parse(jctx, key, klen); dict.ptr = dbptr(self->ctx, dict); obj.ptr = dbptr(self->ctx, obj); dict.ptr->obj = obj.ptr->obj; } Py_INCREF(ret); } else { // The 0-arg form is to generate the json string from dictionary // contents json_emit(jctx, dict); if (jctx->outstr) ret = PyUnicode_FromStringAndSize( (const char*)jctx->outstr, jctx->outlen); } json_cleanup(jctx); dbunlock(self->ctx); return ret; }
static apr_status_t modsecurity_tx_cleanup(void *data) { modsec_rec *msr = (modsec_rec *)data; char *my_error_msg = NULL; if (msr == NULL) return APR_SUCCESS; /* Multipart processor cleanup. */ if (msr->mpd != NULL) multipart_cleanup(msr); /* XML processor cleanup. */ if (msr->xml != NULL) xml_cleanup(msr); #ifdef WITH_YAJL /* JSON processor cleanup. */ if (msr->json != NULL) json_cleanup(msr); #endif // TODO: Why do we ignore return code here? modsecurity_request_body_clear(msr, &my_error_msg); if (my_error_msg != NULL) { msr_log(msr, 1, "%s", my_error_msg); } if (msr->msc_full_request_length > 0 && msr->msc_full_request_buffer != NULL) { msr->msc_full_request_length = 0; free(msr->msc_full_request_buffer); } #if defined(WITH_LUA) #ifdef CACHE_LUA if(msr->L != NULL) lua_close(msr->L); #endif #endif return APR_SUCCESS; }