void recupero_diccionario(t_dictionary* diccionario, int tamanio_contexto) { dictionary_clean(diccionario); // debemos limpiar el diccionario y rellenarlo con las variables del contexto anterior int cant_vars = tamanio_contexto; int i = 0; int incremento = 0; int posicion = 1; int offset; while (i < cant_vars) { // con esto volvemos a llenar el dicc_variables con las variables del contexto anterior int valor_var; char nombre_var; t_struct_sol_bytes * sol_var_ant = malloc(sizeof(t_struct_sol_bytes)); sol_var_ant->base = var_seg_stack; sol_var_ant->offset = temp_cursor_stack + incremento; sol_var_ant->tamanio = sizeof(char) + sizeof(int); socket_enviar(sockUMV, D_STRUCT_SOL_BYTES, sol_var_ant); void * structRecibido2; t_tipoEstructura tipoStruct2; socket_recibir(sockUMV, &tipoStruct2, &structRecibido2); memcpy(&nombre_var, ((t_struct_respuesta_umv*) structRecibido2)->buffer, offset = sizeof(char)); memcpy(&valor_var, ((t_struct_respuesta_umv*) structRecibido2)->buffer + offset, sizeof(int)); // no es necesario este valor char key = nombre_var; char keyABuscar[2] = { key, '\0' }; int* posicion_variable = malloc(sizeof(int)); *posicion_variable = posicion; dictionary_put(diccionario, keyABuscar, posicion_variable); incremento = incremento + (sol_var_ant->tamanio); i++; posicion++; free(sol_var_ant); free(((t_struct_respuesta_umv*) structRecibido2)->buffer); free(structRecibido2); } }
/* * @NAME: dictionary_size * @DESC: Destruye el diccionario */ void dictionary_destroy(t_dictionary *self) { dictionary_clean(self); free(self->elements); free(self); }
/********************************************************************************************* F_SECUNDARIA: Creando un BSON del archivo, para insertalo en la DB TESTEADO =) ****************************/ bson_t * crearDocumentoParaLaDB(char * nombreDelArchivo, long tamanioDelArchivo, int dirPadreDelArchivo, t_dictionary * diccionarioDeBloques) //Va eliminando el diccionario que ingresa por parametro :D { bson_t child; bson_t child2; bson_t child3; bson_t child4; bson_oid_t oid; int cantidadTotalDeBloques; int identificadorDelBloque = 0; t_dictionary* copiasDelBloqueX; t_copiaX* copiaX; char * iDelBloque; //FIN DECLARACION DE VARIABLES bson_t * documento = bson_new(); // ::: Estructura BASICA del documento ::: bson_oid_init (&oid, NULL); BSON_APPEND_OID (documento, "_id", &oid); BSON_APPEND_UTF8 (documento, "nombreDelArchivo", nombreDelArchivo); BSON_APPEND_INT32 (documento, "tamanio", tamanioDelArchivo); BSON_APPEND_INT32 (documento, "dirPadre", dirPadreDelArchivo); BSON_APPEND_INT32 (documento, "estado", 1); cantidadTotalDeBloques = dictionary_size(diccionarioDeBloques); BSON_APPEND_INT32 (documento, "cantidadDeBloques", cantidadTotalDeBloques); // ::: Estructura de BLOQUES del documento ::: //Guardando los N bloques con copias 3 bson_append_document_begin (documento, "Bloques", 7, &child); while(identificadorDelBloque < cantidadTotalDeBloques) { iDelBloque = string_itoa(identificadorDelBloque); bson_append_document_begin (&child, iDelBloque, 1, &child2); copiasDelBloqueX = (t_dictionary*) dictionary_get( diccionarioDeBloques, iDelBloque ); //Guardando la cantidad de copias del bloque X BSON_APPEND_INT32 (&child2, "cantidadDeCopias", 3); //Guardando las 3 copias para el bloque X bson_append_array_begin (&child2, "copias", 6, &child4); copiaX = (t_copiaX*) dictionary_get( copiasDelBloqueX, "1" ); int Guachin= dictionary_size(copiasDelBloqueX); bson_append_document_begin (&child4, "0", 1, &child3); bson_append_int32(&child3,"IP", 2, (*copiaX).IP); bson_append_int32(&child3, "puerto", 6, (*copiaX).puerto); bson_append_int32(&child3, "numBloque", 9, (*copiaX).numBloque); bson_append_document_end (&child4, &child3); copiaX = (t_copiaX*) dictionary_get( copiasDelBloqueX, "2" ); bson_append_document_begin (&child4, "1", 1, &child3); bson_append_int32(&child3,"IP", 2, (*copiaX).IP); bson_append_int32(&child3, "puerto", 6, (*copiaX).puerto); bson_append_int32(&child3, "numBloque", 9, (*copiaX).numBloque); bson_append_document_end (&child4, &child3); copiaX = (t_copiaX*) dictionary_get( copiasDelBloqueX, "3" ); bson_append_document_begin (&child4, "2", 1, &child3); bson_append_int32(&child3,"IP", 2, (*copiaX).IP); bson_append_int32(&child3, "puerto", 6, (*copiaX).puerto); bson_append_int32(&child3, "numBloque", 9, (*copiaX).numBloque); bson_append_document_end (&child4, &child3); bson_append_array_end (&child2, &child4); dictionary_clean(copiasDelBloqueX); dictionary_destroy(copiasDelBloqueX); //Anido las 3 copias al bloque X bson_append_document_end (&child, &child2); free(iDelBloque); identificadorDelBloque++; }; //::Estructura BASICA + estructura BLOQUES:: bson_append_document_end (documento, &child); //Elimino el diccionarioDeBloques dictionary_clean(diccionarioDeBloques); dictionary_destroy(diccionarioDeBloques); return documento; }