void reset_response_record(ResponseRecord *rec) { rec->statusCode->length = 0; rec->statusMessage->length = 0; //Delete all header strings for (size_t i = 0; i < rec->headerNames->length; ++i) { deleteString(arrayGet(rec->headerNames, i)); arraySet(rec->headerNames, i, NULL); } for (size_t i = 0; i < rec->headerValues->length; ++i) { deleteString(arrayGet(rec->headerValues, i)); arraySet(rec->headerValues, i, NULL); } rec->headerNames->length = 0; rec->headerValues->length = 0; if (rec->map.buffer != NULL && rec->map.buffer != MAP_FAILED) { munmap(rec->map.buffer, rec->map.length); rec->map.buffer = NULL; rec->map.length = 0; } if (rec->fd >= 0) { close(rec->fd); rec->fd = -1; } rec->headerBuffer.length = 0; rec->bodyBuffer.length = 0; }
void reset_request_record(RequestRecord *rec) { rec->host->length = 0; rec->port->length = 0; rec->method->length = 0; rec->protocol->length = 0; rec->path->length = 0; rec->queryString->length = 0; //Delete all header strings for (size_t i = 0; i < rec->headerNames->length; ++i) { deleteString(arrayGet(rec->headerNames, i)); arraySet(rec->headerNames, i, NULL); } for (size_t i = 0; i < rec->headerValues->length; ++i) { deleteString(arrayGet(rec->headerValues, i)); arraySet(rec->headerValues, i, NULL); } rec->headerNames->length = 0; rec->headerValues->length = 0; //Delete all parameter strings for (size_t i = 0; i < rec->parameterNames->length; ++i) { deleteString(arrayGet(rec->parameterNames, i)); arraySet(rec->parameterNames, i, NULL); } for (size_t i = 0; i < rec->parameterValues->length; ++i) { deleteString(arrayGet(rec->parameterValues, i)); arraySet(rec->parameterValues, i, NULL); } rec->parameterNames->length = 0; rec->parameterValues->length = 0; if (rec->map.buffer != NULL && rec->map.buffer != MAP_FAILED) { munmap(rec->map.buffer, rec->map.length); rec->map.buffer = NULL; rec->map.length = 0; } if (rec->fd >= 0) { close(rec->fd); rec->fd = -1; } rec->headerBuffer.length = 0; rec->bodyBuffer.length = 0; }
/* jsonUnpackArray - unpack a genArray. Use the genArray_t to contain the * output for Now. The "key" value is not used. */ int jsonUnpackArray( json_t *genArrayObj, genArray_t *genArray ) { void *tmpOut; int *tmpInt; float *tmpFloat; dictionary_t *tmpDict; genArray_t *tmpGenArray; json_t *value; int status = 0; int i, len; if ( genArrayObj == NULL || genArray == NULL ) { rodsLog( LOG_ERROR, "jsonUnpackArray: NULL input" ); return USER__NULL_INPUT_ERR; } bzero( genArray, sizeof( genArray_t ) ); if ( !json_is_array( genArrayObj ) ) { rodsLog( LOG_ERROR, "jsonUnpackArray: Obj type %d is not JSON_ARRAY.", json_typeof( genArrayObj ) ); return OOI_JSON_TYPE_ERR; } len = json_array_size( genArrayObj ); for ( i = 0; i < len; i++ ) { json_type myType; value = json_array_get( genArrayObj, i ); myType = json_typeof( value ); switch ( myType ) { case JSON_OBJECT: tmpDict = ( dictionary_t * ) calloc( 1, sizeof( dictionary_t ) ); status = jsonUnpackDict( value, tmpDict ); if ( status < 0 ) { free( tmpDict ); } else { status = arraySet( genArray, Dictionary_MS_T, tmpDict ); } break; case JSON_ARRAY: tmpGenArray = ( genArray_t * ) calloc( 1, sizeof( genArray_t ) ); status = jsonUnpackArray( value, tmpGenArray ); if ( status < 0 ) { free( tmpGenArray ); } else { status = arraySet( genArray, GenArray_MS_T, tmpGenArray ); } break; case JSON_STRING: tmpOut = strdup( json_string_value( value ) ); status = arraySet( genArray, STR_MS_T, tmpOut ); break; case JSON_INTEGER: tmpInt = ( int * ) calloc( 1, sizeof( int ) ); *tmpInt = ( int ) json_integer_value( value ); status = arraySet( genArray, INT_MS_T, ( void * ) tmpInt ); break; case JSON_REAL: tmpFloat = ( float * ) calloc( 1, sizeof( float ) ); *tmpFloat = ( float ) json_real_value( value ); status = arraySet( genArray, FLOAT_MS_T, ( void * ) tmpFloat ); break; case JSON_TRUE: tmpInt = ( int * ) calloc( 1, sizeof( int ) ); *tmpInt = 1; status = arraySet( genArray, BOOL_MS_T, ( void * ) tmpInt ); break; case JSON_FALSE: tmpInt = ( int * ) calloc( 1, sizeof( int ) ); *tmpInt = 0; status = arraySet( genArray, BOOL_MS_T, ( void * ) tmpInt ); break; default: rodsLog( LOG_ERROR, "jsonUnpackArray: myType %d not supported", myType ); status = OOI_JSON_TYPE_ERR; } } if ( status < 0 ) { clearGenArray( genArray ); } return status; }