void chain_save_pc( MYSQL_RES *res, QueryItem_t *item ) { int count; MYSQL_BIND *data; MYSQL_BIND temp[1]; ProtectedData_t *protect; int *id; data = item->queryData; if( !res || !(count = mysql_num_rows(res)) ) { count = 0; } protect = (ProtectedData_t *)data[3].buffer; id = (int *)protect->data; *id = *(int *)data[0].buffer; /* swap argument order */ memcpy( temp, &data[0], sizeof(MYSQL_BIND) ); memmove( &data[0], &data[1], sizeof(MYSQL_BIND) * 2 ); memcpy( &data[2], temp, sizeof(MYSQL_BIND) ); if( count ) { /* update */ ProtectedDataUnlock( protect ); LogPrint(LOG_DEBUG, "Updating id %d", *id); db_queue_query( 11, QueryTable, data, 3, NULL, NULL, NULL ); } else { /* insert */ *id = 0; LogPrintNoArg(LOG_DEBUG, "Inserting"); db_queue_query( 12, QueryTable, data, 2, result_insert_id, protect, NULL ); } }
static int db_upgrade_schema( char *setting, char *desc, QueryTable_t *defSchema, int defSchemaCount, SchemaUpgrade_t *schemaUpgrade, int current, int codeSupports ) { int i; if( current >= codeSupports ) { return( current ); } if( current == 0 ) { /* There is no dbSchema, assume that it is an empty database, populate * with the default schema */ LogPrint( LOG_ERR, "Initializing %s database to schema version %d", desc, codeSupports ); for( i = 0; i < defSchemaCount; i++ ) { db_queue_query( i, defSchema, NULL, 0, NULL, NULL, NULL ); } db_set_setting( setting, "%d", codeSupports ); return( codeSupports ); } LogPrint( LOG_ERR, "Upgrading %s database from schema version %d to %d", desc, current, current+1 ); for( i = 0; schemaUpgrade[current][i].queryPattern; i++ ) { db_queue_query( i, schemaUpgrade[current], NULL, 0, NULL, NULL, NULL ); } current++; db_set_setting( setting, "%d", current ); return( current ); }
void chain_save_account( MYSQL_RES *res, QueryItem_t *item ) { int count; MYSQL_BIND *data; MYSQL_BIND temp[1]; ProtectedData_t *protect; int *id; data = item->queryData; if( !res || !(count = mysql_num_rows(res)) ) { count = 0; } protect = (ProtectedData_t *)data[6].buffer; id = (int *)protect->data; *id = *(int *)data[0].buffer; /* swap argument order */ memcpy( temp, &data[0], sizeof(MYSQL_BIND) ); memmove( &data[0], &data[1], sizeof(MYSQL_BIND) * 5 ); memcpy( &data[5], temp, sizeof(MYSQL_BIND) ); if( count ) { /* update */ ProtectedDataUnlock( protect ); db_queue_query( 6, QueryTable, data, 6, NULL, NULL, NULL ); } else { /* insert */ db_queue_query( 7, QueryTable, data, 5, result_insert_id, protect, NULL ); } }
HavokResponse *db_mysql_find_pc( HavokRequest *req ) { MYSQL_BIND *data; pthread_mutex_t *mutex; HavokResponse *resp; if( !req || !req->pc_data || !req->pc_data->name ) { return( NULL ); } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); data = CREATEN(MYSQL_BIND, 1); bind_string( &data[0], req->pc_data->name, MYSQL_TYPE_VAR_STRING ); db_queue_query( 17, QueryTable, data, 1, result_find_pc, (void *)&resp, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); return( resp ); }
char *db_mysql_load_pc_attribs( int pc_id ) { MYSQL_BIND *data; pthread_mutex_t *mutex; char *resp; if( !pc_id ) { return( NULL ); } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); data = CREATEN(MYSQL_BIND, 1); bind_numeric( &data[0], pc_id, MYSQL_TYPE_LONG ); db_queue_query( 13, QueryTable, data, 1, result_load_pc_attribs, (void *)&resp, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); return( resp ); }
HavokResponse *db_mysql_load_pc( HavokRequest *req ) { MYSQL_BIND *data; pthread_mutex_t *mutex; HavokResponse *resp; if( !req || !req->pc_data->account_id || !req->pc_data->id ) { return( NULL ); } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); data = CREATEN(MYSQL_BIND, 2); bind_numeric( &data[0], req->pc_data->account_id, MYSQL_TYPE_LONG ); bind_numeric( &data[1], req->pc_data->id, MYSQL_TYPE_LONG ); db_queue_query( 9, QueryTable, data, 2, result_load_pc, (void *)&resp, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); resp->pc_data[0]->attribs = db_mysql_load_pc_attribs( req->pc_data->id ); return( resp ); }
HavokResponse *db_mysql_get_pc_list( HavokRequest *req) { MYSQL_BIND *data; pthread_mutex_t *mutex; HavokResponse *resp; if( !req || !req->account_data->id ) { return( NULL ); } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); data = CREATEN(MYSQL_BIND, 1); bind_numeric( &data[0], req->account_data->id, MYSQL_TYPE_LONG ); db_queue_query( 8, QueryTable, data, 1, result_get_pc_list, (void *)&resp, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); return( resp ); }
HavokResponse *db_mysql_save_account( HavokRequest *req ) { MYSQL_BIND *data; pthread_mutex_t *mutex; HavokResponse *resp; ProtectedData_t *protect; volatile int id; if( !req || !req->account_data ) { return; } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); protect = ProtectedDataCreate(); protect->data = (void *)&id; ProtectedDataLock( protect ); data = CREATEN(MYSQL_BIND, 7); bind_numeric( &data[0], req->account_data->id, MYSQL_TYPE_LONG ); bind_string( &data[1], req->account_data->email, MYSQL_TYPE_VAR_STRING ); bind_string( &data[2], req->account_data->passwd, MYSQL_TYPE_VAR_STRING ); bind_numeric( &data[3], (req->account_data->ansi ? 1 : 0), MYSQL_TYPE_TINY ); bind_numeric( &data[4], (req->account_data->confirmed ? 1 : 0), MYSQL_TYPE_TINY ); bind_string( &data[5], (req->account_data->confcode ? req->account_data->confcode : ""), MYSQL_TYPE_VAR_STRING ); bind_null_blob( &data[6], protect ); db_queue_query( 5, QueryTable, data, 7, NULL, NULL, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); ProtectedDataLock( protect ); ProtectedDataDestroy( protect ); resp = protobufCreateResponse(); if( !resp ) { return( NULL ); } resp->request_type = REQ_TYPE__SAVE_ACCOUNT; resp->account_data = CREATE(ReqAccountType); req_account_type__init( resp->account_data ); memcpy( resp->account_data, req->account_data, sizeof(ReqAccountType) ); resp->account_data->id = id; resp->account_data->email = memstrlink( req->account_data->email ); resp->account_data->passwd = memstrlink( req->account_data->passwd ); resp->account_data->confcode = memstrlink( req->account_data->confcode ); return( resp ); }
HavokResponse *db_mysql_save_pc( HavokRequest *req ) { MYSQL_BIND *data; pthread_mutex_t *mutex; HavokResponse *resp; ProtectedData_t *protect; volatile int id; if( !req || !req->pc_data ) { return( NULL ); } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); protect = ProtectedDataCreate(); protect->data = (void *)&id; ProtectedDataLock( protect ); data = CREATEN(MYSQL_BIND, 4); bind_numeric( &data[0], req->pc_data->id, MYSQL_TYPE_LONG ); bind_numeric( &data[1], req->pc_data->account_id, MYSQL_TYPE_LONG ); bind_string( &data[2], req->pc_data->name, MYSQL_TYPE_VAR_STRING ); bind_null_blob( &data[3], protect ); db_queue_query( 10, QueryTable, data, 4, NULL, NULL, mutex ); pthread_mutex_unlock( mutex ); pthread_mutex_destroy( mutex ); memfree( mutex ); ProtectedDataLock( protect ); ProtectedDataDestroy( protect ); db_mysql_save_pc_attribs( id, req->pc_data->attribs ); resp = protobufCreateResponse(); if( !resp ) { return( NULL ); } resp->request_type = REQ_TYPE__SAVE_PC; resp->n_pc_data = 1; resp->pc_data = CREATE(ReqPCType *); resp->pc_data[0] = CREATE(ReqPCType); req_pctype__init( resp->pc_data[0] ); memcpy( resp->pc_data[0], req->pc_data, sizeof(ReqPCType) ); resp->pc_data[0]->id = id; resp->pc_data[0]->name = memstrlink( req->pc_data->name ); return( resp ); }
void chain_save_pc_attribs( MYSQL_RES *res, QueryItem_t *item ) { int count; MYSQL_BIND *data; MYSQL_BIND temp[1]; data = item->queryData; if( !res || !(count = mysql_num_rows(res)) ) { count = 0; } if( count ) { /* update */ /* swap argument order */ memcpy( temp, &data[2], sizeof(MYSQL_BIND) ); memmove( &data[1], &data[0], sizeof(MYSQL_BIND) * 2 ); memcpy( &data[0], temp, sizeof(MYSQL_BIND) ); db_queue_query( 15, QueryTable, data, 3, NULL, NULL, NULL ); } else { /* insert */ db_queue_query( 16, QueryTable, data, 3, NULL, NULL, NULL ); } }
void chain_set_setting( MYSQL_RES *res, QueryItem_t *item ) { int count; MYSQL_BIND *data; MYSQL_BIND temp[1]; data = item->queryData; if( !res || !(count = mysql_num_rows(res)) ) { count = 0; } if( count ) { /* update */ /* Swap the arguments around */ memcpy( temp, &data[0], sizeof(MYSQL_BIND) ); memcpy( &data[0], &data[1], sizeof(MYSQL_BIND) ); memcpy( &data[1], temp, sizeof(MYSQL_BIND) ); db_queue_query( 2, QueryTable, data, 2, NULL, NULL, NULL ); } else { /* insert */ db_queue_query( 3, QueryTable, data, 2, NULL, NULL, NULL ); } }
HavokResponse *db_mysql_set_setting( HavokRequest *req ) { MYSQL_BIND *data; if( !req || !req->settings_data->setting_name || !req->settings_data->setting_value ) { return( NULL ); } data = CREATEN(MYSQL_BIND, 2); bind_string( &data[0], req->settings_data->setting_name, MYSQL_TYPE_VAR_STRING ); bind_string( &data[1], req->settings_data->setting_value, MYSQL_TYPE_VAR_STRING ); db_queue_query( 1, QueryTable, data, 2, NULL, NULL, NULL); return( NULL ); }
void db_mysql_save_pc_attribs( int pc_id, char *json ) { MYSQL_BIND *data; pthread_mutex_t *mutex; JSONSource_t *js; JSONSource_t *jsItem; if( !pc_id || !json ) { return; } js = SplitJSON( json ); if( !js ) { return; } mutex = CREATE(pthread_mutex_t); thread_mutex_init( mutex ); for( jsItem = js; jsItem->source; jsItem++ ) { data = CREATEN(MYSQL_BIND, 3); bind_numeric( &data[0], pc_id, MYSQL_TYPE_LONG ); bind_string( &data[1], jsItem->source, MYSQL_TYPE_VAR_STRING ); bind_string( &data[2], jsItem->json, MYSQL_TYPE_VAR_STRING ); db_queue_query( 14, QueryTable, data, 3, NULL, NULL, mutex ); pthread_mutex_unlock( mutex ); } pthread_mutex_destroy( mutex ); memfree( mutex ); DestroyJSONSource( js ); }