struct o_string_buffer * o_string_buffer_new() { struct o_string_buffer * new_buff = o_malloc(sizeof(struct o_string_buffer)); memset(new_buff, 0, sizeof(struct o_string_buffer)); new_buff->buffer = o_malloc(sizeof(char) * START_BUFFER_SIZE); new_buff->size = START_BUFFER_SIZE; new_buff->cursor = 0; return new_buff; }
struct o_output_stream * o_output_stream_byte_buffer() { struct o_output_stream_byte *stream = o_malloc(sizeof(struct o_output_stream_byte)); stream->stream.type = 'b'; stream->stream.o_output_stream_flush = o_output_stream_byte_flush; stream->stream.o_output_stream_free = o_output_stream_byte_free; stream->stream.o_output_stream_write_bytes = o_output_stream_byte_write_bytes; stream->content = o_malloc(sizeof(char) * START_BUFFER_SIZE); stream->size = START_BUFFER_SIZE; stream->cursor = 0; return (struct o_output_stream *) stream; }
char * o_string_buffer_str(struct o_string_buffer * buff) { char * new_str = o_malloc(buff->cursor + 1); memcpy(new_str, buff->buffer, buff->cursor); new_str[buff->cursor] = 0; return new_str; }
struct o_metadata * o_metadata_from_document(struct o_document *doc) { struct o_metadata * meta = o_malloc(sizeof(struct o_metadata)); struct o_document_value * schema = o_document_field_get(doc, "schema"); meta->schema = o_schema_from_document((struct o_document *) o_document_value_get_link(schema)); return meta; }
int o_url_resolve_information(char * connection_url, enum o_url_type *type, char **path, char ** db_name) { int pos; *type = o_url_resolve_type(connection_url); switch (*type) { case HTTP: connection_url += HTTP_PROTOCOL_PARAMETER_LENGHT; pos = strcspn(connection_url, "/"); *path = o_malloc(pos * sizeof(char)); strncpy(*path, connection_url, pos); connection_url += pos + 1; pos = strcspn(connection_url, "/"); connection_url += pos + 1; pos = strcspn(connection_url, "/"); *db_name = o_malloc(pos * sizeof(char)); strncpy(*db_name, connection_url, pos); break; case REMOTE: connection_url += HTTP_PROTOCOL_PARAMETER_LENGHT; pos = strcspn(connection_url, "/"); *path = o_malloc(pos + 1 * sizeof(char)); strncpy(*path, connection_url, pos); (*(path))[pos] = 0; connection_url += pos + 1; pos = strcspn(connection_url, "/"); *db_name = o_malloc(pos + 1 * sizeof(char)); strncpy(*db_name, connection_url, pos); (*(db_name))[pos] = 0; break; case LOCAL: connection_url += HTTP_PROTOCOL_PARAMETER_LENGHT; *path = strdup(connection_url); break; default: { char * message = o_malloc(sizeof(char) * (strlen(connection_url) + strlen(BAD_CONNECTION_URL_MESSAGE))); sprintf(message, BAD_CONNECTION_URL_MESSAGE, connection_url); struct o_exception_io *ex = o_exception_io_new(message, BAD_CONNECTION_URL_ID); o_free(message); throw(ex); return 0; } break; } return 1; }
struct o_list_iterator *o_list_begin(struct o_list * list) { if (list->size == 0) return 0; struct o_list_iterator *i = o_malloc(sizeof(struct o_list_iterator)); i->current = list->first; i->direction = 1; return i; }
struct o_list_iterator *o_list_end(struct o_list * list) { if (list->size == 0) return 0; struct o_list_iterator *i = o_malloc(sizeof(struct o_list_iterator)); i->current = list->last; i->direction = 0; return i; }
struct o_native_thread * o_native_thread_new(char * name, void *(*function)(void *)) { struct o_native_thread * th = o_malloc(sizeof(struct o_native_thread)); memset(th, 0, sizeof(struct o_native_thread)); th->name = name; th->function = function; th->count = 1; return th; }
struct o_engine * o_engine_get_instance() { if (global_engine == 0) { global_engine = (struct o_engine *) o_malloc(sizeof(struct o_engine)); global_engine->connections = o_map_string_new(); } return global_engine; }
void o_raw_buffer_record_retrieve_content(struct o_raw_buffer_record * row_buff) { struct o_output_stream * o = o_output_stream_byte_buffer(); o_record_serialize(row_buff->record, o); row_buff->content = (unsigned char *) o_output_stream_byte_content(o, &row_buff->size); unsigned char * new_content = (unsigned char *) o_malloc(row_buff->size); memcpy(new_content, row_buff->content, row_buff->size); row_buff->content = new_content; o_output_stream_free(o); }
char * createKey(char * path, char * username) { int pathLen = strlen(path); int usrLen = strlen(username); char * val = o_malloc(pathLen + pathLen + 1); memcpy(val, path, pathLen); memcpy(val + pathLen, username, usrLen); val[pathLen + pathLen] = 0; return val; }
struct o_input_stream * o_input_stream_socket_new(struct o_database_socket * socket) { struct o_input_stream_socket * new_str = o_malloc(sizeof(struct o_input_stream_socket)); new_str->socket = socket; new_str->stream.o_input_stream_read = o_input_stream_socket_read; new_str->stream.o_input_stream_peek = o_input_stream_socket_peek; new_str->stream.o_input_stream_read_bytes = o_input_stream_socket_read_bytes; new_str->stream.o_input_stream_free = o_input_stream_socket_free; return (struct o_input_stream*) new_str; }
char * o_connection_build_storage_name(char * name, char * username) { char * store_name = o_malloc(strlen(name) + strlen(username) + 2); int len = strlen(name); memcpy(store_name, name, len); store_name[len] = '\''; len += strlen(username); memcpy(store_name, username, len); store_name[len] = 0; return store_name; }
void VirtualMemberFunctionTable::construct( void* a_pInstance ) { if(sharesMemberFunctions()) { m_pBaseTable->construct(a_pInstance); return; } void*** pppWhere = (void***)((byte*)a_pInstance + getOffset()); size_t count = getMemberFunctionCount(); if(m_ppClosures == nullptr) { if(m_pBaseTable) { size_t size = std::max(count, m_pBaseTable->getMemberFunctionCount()); m_ppClosures = (void**)o_malloc(size * sizeof(void*)); } else { m_ppClosures = (void**)o_malloc(count * sizeof(void*)); } void* non_init_ptr; memset(&non_init_ptr, 0xda, sizeof(void*)); if(memcmp(pppWhere, &non_init_ptr, sizeof(void*)) != 0) // memory not equals 0xdadadada => closures already present => a base vtable has been installed here { memcpy(m_ppClosures, *pppWhere, count*sizeof(void*)); // extract native vtable closures } for(size_t i = 0; i<count; ++i) { if((*m_pMemberFunctions)[i]) { void* pVTableClosure = (*m_pMemberFunctions)[i]->getVTableClosure(getOffset()); if(pVTableClosure) { m_ppClosures[i] = pVTableClosure; // write (resp. overwrite) closures (resp. base closures) } // o_assert(m_ppClosures[i], "No vtable closure found for given vtable offset, ensure your compiler has provided all the closures for each possible multi-inheritance this adjustment (thunk)"); } } *pppWhere = m_ppClosures; // write (resp. overwrite) vtable pointer (resp. base vtable pointer) } }
struct o_raw_buffer * o_raw_buffer_record(struct o_record * record) { struct o_raw_buffer_record * row_buff = o_malloc(sizeof(struct o_raw_buffer_record)); row_buff->record = record; row_buff->content = 0; row_buff->size = 0; row_buff->buffer.o_raw_buffer_content_size = o_raw_buffer_record_content_size; row_buff->buffer.o_raw_buffer_content = o_raw_buffer_record_content; row_buff->buffer.o_raw_buffer_version = o_raw_buffer_record_version; row_buff->buffer.o_raw_buffer_type = o_raw_buffer_record_type; row_buff->buffer.o_raw_buffer_free = o_raw_buffer_record_free; return (struct o_raw_buffer *) row_buff; }
struct o_document * o_document_new_id(struct o_record_id * rid) { struct o_document * new_doc = o_malloc(sizeof(struct o_document)); o_record_new_internal_id(o_document_o_record(new_doc), DOCUMENT_RECORD_TYPE, rid); new_doc->record.o_record_serialize = o_document_record_serialize; new_doc->record.o_record_deserialize = o_document_record_deserialize; new_doc->record.o_record_before_save = o_document_before_save; new_doc->record.o_record_after_save = o_document_after_save; new_doc->record.o_record_cluster_name = o_document_cluster_name; new_doc->record.o_record_free = o_document_record_free; new_doc->fields = o_map_string_new(); new_doc->fields_old_values = 0; return new_doc; }
struct o_raw_buffer * o_raw_buffer_byte(int type, int version, unsigned char * content, int content_size) { struct o_raw_buffer_byte * row_buff = o_malloc(sizeof(struct o_raw_buffer_byte)); row_buff->type = type; row_buff->version = version; row_buff->content = content; row_buff->content_size = content_size; row_buff->buffer.o_raw_buffer_content_size = o_raw_buffer_byte_content_size; row_buff->buffer.o_raw_buffer_content = o_raw_buffer_byte_content; row_buff->buffer.o_raw_buffer_version = o_raw_buffer_byte_version; row_buff->buffer.o_raw_buffer_type = o_raw_buffer_byte_type; row_buff->buffer.o_raw_buffer_free = o_raw_buffer_byte_free; return (struct o_raw_buffer *) row_buff; }
int o_url_resolve_host_port_from_path(char * path, char ** host, int * port) { int pos = strcspn(path, ":"); int size = strlen(path); if (pos != size) { *host = o_malloc(pos * sizeof(char) + 1); strncpy(*host, path, pos); (*host)[pos] = 0; *port = atoi(path + pos + 1); return 0; } else { *host = o_memdup(path, size+1); return 1; } }
int o_list_add(struct o_list * list, void * to_add) { struct o_list_item * new_i = o_malloc(sizeof(struct o_list_item)); memset(new_i, 0, sizeof(struct o_list_item)); new_i->value = to_add; list->size++; if (list->first == 0) { list->first = new_i; list->last = new_i; } else { list->last->next = new_i; new_i->previus = list->last; list->last = new_i; } return 1; }
struct o_database_document * o_database_document_new_error_handler(char * connection_url, struct o_database_error_handler * error_handler) { struct o_database_document * new_db = o_malloc(sizeof(struct o_database_document)); o_database_new_internal(o_database_document_to_database(new_db), connection_url, error_handler); return new_db; }
struct o_list *o_list_new() { struct o_list * new_l = o_malloc(sizeof(struct o_list)); memset(new_l, 0, sizeof(struct o_list)); return new_l; }
struct o_operation_context * o_database_operation_context(struct o_storage * storage) { struct o_database_operation_context * context = (struct o_database_operation_context *) o_malloc(sizeof(struct o_database_operation_context)); memset(context, 0, sizeof(struct o_database_operation_context)); context->context.type = &o_database_operation_context_instance; context->storage = storage; context->cache = o_record_cache_new(); return &context->context; }
struct o_database * o_database_new_error_handler(char * connection_url, struct o_database_error_handler * error_handler) { struct o_database * new_db = o_malloc(sizeof(struct o_database)); o_database_new_internal(new_db, connection_url, error_handler, RAW_DB_TYPE); return new_db; }
void * pool_test_factory(void * obj) { return o_malloc(sizeof(int)); }