static CcnetMessage * ccnet_message_new_full (const char *from, const char *to, const char *app, const char *body, time_t ctime, time_t rtime, const char *id, char flags) { CcnetMessage *message = g_new0 (CcnetMessage, 1); g_assert (flags >= 0); g_assert (from != NULL && to != NULL && app != NULL); message->flags = flags; memcpy (message->from, from, 40); message->from[40] = '\0'; memcpy (message->to, to, 40); /* ok if strlen(to) == 36 */ message->to[40] = '\0'; message->app = g_intern_string(app); message->body = g_strdup(body); message->ctime = (ctime ? ctime : time(NULL)); message->rtime = rtime; message->id = (id ? g_strdup (id) : gen_uuid()); message->ref_count = 1; return message; }
int create_queue(struct ast_json* j_queue) { int ret; char* uuid; struct ast_json* j_tmp; if(j_queue == NULL) { return false; } j_tmp = ast_json_deep_copy(j_queue); uuid = gen_uuid(); ast_json_object_set(j_tmp, "uuid", ast_json_string_create(uuid)); ast_log(LOG_NOTICE, "Create queue. uuid[%s], name[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")), ast_json_string_get(ast_json_object_get(j_tmp, "name")) ); ret = db_insert("queue", j_tmp); AST_JSON_UNREF(j_tmp); if(ret == false) { ast_free(uuid); return false; } // send ami event j_tmp = get_queue(uuid); send_manager_evt_out_queue_create(j_tmp); AST_JSON_UNREF(j_tmp); return true; }
static std::tuple<uint32_t, uint32_t> find_a_friendly_neighborhood_for_our_new_visitor() { PGresult* result = PQexec(s_postgres, "SELECT idx FROM vault.\"Nodes\" WHERE \"String64_2\"=" " 'Neighborhood' AND \"String64_4\" = '" HOOD_USER_NAME "'" " ORDER BY \"Int32_1\""); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_tuple<uint32_t, uint32_t>(0, 0); } uint32_t theHoodInfo = 0; for (int i = 0; i < PQntuples(result); ++i) { uint32_t ageInfoId = strtoul(PQgetvalue(result, i, 0), 0, 10); uint32_t owners = v_count_age_owners(ageInfoId); if (owners < HOOD_POPULATION_THRESHOLD) { theHoodInfo = ageInfoId; break; } } PQclear(result); // Need new hood? if (theHoodInfo == 0) { AuthServer_AgeInfo age; age.m_ageId = gen_uuid(); age.m_filename = "Neighborhood"; age.m_instName = HOOD_INSTANCE_NAME; age.m_userName = HOOD_USER_NAME; age.m_description = HOOD_USER_NAME " " HOOD_INSTANCE_NAME; age.m_seqNumber = -1; // Auto-generate theHoodInfo = std::get<1>(v_create_age(age, e_AgePublic)); } // It's important to BCast new hood members, so we'll return the ageOwners folder PostgresStrings<2> parms; parms.set(0, theHoodInfo); parms.set(1, DS::Vault::e_AgeOwnersFolder); result = PQexecParams(s_postgres, "SELECT idx FROM vault.find_folder($1, $2);", 2, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) == PGRES_TUPLES_OK) { uint32_t ownersFolder = strtoul(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); return std::make_tuple(theHoodInfo, ownersFolder); } else { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_tuple(0, 0); } }
// creates new empty nodeinfo struct struct nodeinfo *create_node() { struct nodeinfo *node = malloc(sizeof(struct nodeinfo)); node->hostname = strdup(na); node->internalhost = strdup(na); node->keynode = strdup(na); node->externalhost = strdup(na); node->identifier = strdup(na); //node->neighbour[0] = strdup(na); //node->neighbour[1] = strdup(na); node->command = strdup(na); node->unique = gen_uuid(); update_node_timestamp(node); return node; }
/** * Create plan. * @param j_plan * @return */ bool create_plan(const struct ast_json* j_plan) { int ret; char* uuid; struct ast_json* j_tmp; char* tmp; if(j_plan == NULL) { return false; } j_tmp = ast_json_deep_copy(j_plan); uuid = gen_uuid(); ast_json_object_set(j_tmp, "uuid", ast_json_string_create(uuid)); tmp = get_utc_timestamp(); ast_json_object_set(j_tmp, "tm_create", ast_json_string_create(tmp)); ast_free(tmp); ast_log(LOG_NOTICE, "Create plan. uuid[%s], name[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")), ast_json_string_get(ast_json_object_get(j_tmp, "name"))? : "<unknown>" ); ret = db_insert("plan", j_tmp); AST_JSON_UNREF(j_tmp); if(ret == false) { ast_free(uuid); return false; } ast_log(LOG_VERBOSE, "Finished insert.\n"); // send ami event j_tmp = get_plan(uuid); ast_log(LOG_VERBOSE, "Check plan info. uuid[%s]\n", ast_json_string_get(ast_json_object_get(j_tmp, "uuid")) ); ast_free(uuid); if(j_tmp == NULL) { ast_log(LOG_ERROR, "Could not get created plan info."); return false; } send_manager_evt_out_plan_create(j_tmp); AST_JSON_UNREF(j_tmp); return true; }
static void test_kv_mgr() { CcnetKVItem *item, *item2; char *uuid = gen_uuid(); /* test item new and unref */ item = ccnet_kvitem_new ("fileshare", group->id, uuid, "hello", 0); ccnet_kvitem_unref (item); /* build the item again */ item = ccnet_kvitem_new ("fileshare", group->id, uuid, "hello world", 0); /* receive the item twice */ ccnet_kvitem_manager_receive_item_local (session->kv_mgr, item); ccnet_kvitem_manager_receive_item_local (session->kv_mgr, item); item2 = ccnet_kvitem_manager_get_item (session->kv_mgr, uuid); g_assert (item2); g_assert (item2->ref == 3); ccnet_kvitem_unref (item2); ccnet_kvitem_unref (item); /* receive new item */ item = ccnet_kvitem_new ("fileshare", group->id, uuid, "hello world2", 0); ccnet_kvitem_manager_receive_item (session->kv_mgr, item); item2 = ccnet_kvitem_manager_get_item (session->kv_mgr, uuid); g_assert (strcmp(item2->value, "hello world2") == 0); g_assert (item == item2); /* test fetch list api */ GList *items; items = ccnet_kvitem_manager_get_items_by_group (session->kv_mgr, group->id); g_assert (g_list_length(items) == 1); ccnet_kvitem_list_free (items); items = ccnet_kvitem_manager_get_items_by_category (session->kv_mgr, "fileshare"); ccnet_kvitem_list_free (items); items = ccnet_kvitem_manager_get_item_timestamps ( session->kv_mgr, "fileshare", group->id); ccnet_kvitem_list_free (items); g_assert (g_list_length(items) == 1); g_free (uuid); }
void init_node(cmsg_bytes_t container_name) { if (container_name.len == 0) { unsigned char buf[CMSG_UUID_BUF_SIZE]; gen_uuid(buf); _container_name = cmsg_bytes_malloc_dup(CMSG_BYTES(CMSG_UUID_BUF_SIZE, buf)); } else { _container_name = cmsg_bytes_malloc_dup(container_name); } info("Local container name is <<%.*s>>\n", _container_name.len, _container_name.bytes); init_hashtable(&node_class_table, 31, NULL, NULL); init_hashtable(&directory, 10007, node_incref, node_decref); }
/* Simple driver for UUID generator */ void main(int argc, char **argv) { uuid_t u; int f; uuid_create(&u); printf("uuid_create(): "); puid(u); char my_uuid[35]; gen_uuid(my_uuid, 35); printf("my_uuid:%s\n", my_uuid); f = uuid_compare(&u, &u); printf("uuid_compare(u,u): %d\n", f); /* should be 0 */ f = uuid_compare(&u, &NameSpace_DNS); printf("uuid_compare(u, NameSpace_DNS): %d\n", f); /* s.b. 1 */ f = uuid_compare(&NameSpace_DNS, &u); printf("uuid_compare(NameSpace_DNS, u): %d\n", f); /* s.b. -1 */ uuid_create_md5_from_name(&u, NameSpace_DNS, "www.widgets.com", 15); printf("uuid_create_md5_from_name(): "); puid(u); }
std::list<AuthServer_AgeInfo> configure_static_ages() { AuthServer_AgeInfo age; std::list<AuthServer_AgeInfo> configs; DS::String filename = DS::Settings::SettingsPath() + "/static_ages.ini"; FILE* cfgfile = fopen(filename.c_str(), "r"); if (!cfgfile) { fprintf(stderr, "Cannot open %s for reading\n", filename.c_str()); return configs; } try { char buffer[4096]; bool haveAge = false; while (fgets(buffer, 4096, cfgfile)) { DS::String line = DS::String(buffer).strip('#'); if (line.isEmpty()) continue; if (line.strip().c_str()[0] == '[') { if (haveAge) configs.push_back(age); age.clear(); DS::String header = line.strip(); header.replace("[",""); header.replace("]",""); if (header == "auto") age.m_ageId = gen_uuid(); else age.m_ageId = DS::Uuid(header.c_str()); haveAge = true; continue; } std::vector<DS::String> params = line.split('=', 1); if (params.size() != 2) { fprintf(stderr, "Warning: Invalid config line: %s\n", line.c_str()); continue; } // Clean any whitespace around the '=' params[0] = params[0].strip(); params[1] = params[1].strip(); if (params[0] == "Filename") { age.m_filename = params[1]; } else if (params[0] == "Instance") { age.m_instName = params[1]; } else if (params[0] == "UserName") { age.m_userName = params[1]; } else { fprintf(stderr, "Warning: Unknown setting '%s' ignored\n", params[0].c_str()); } } if (haveAge) configs.push_back(age); } catch (DS::AssertException ex) { fprintf(stderr, "[Auth] Assertion failed at %s:%ld: %s\n", ex.m_file, ex.m_line, ex.m_cond); fclose(cfgfile); return configs; } fclose(cfgfile); return configs; }
bool dm_vault_init() { PostgresStrings<1> sparm; sparm.set(0, DS::Vault::e_NodeSystem); PGresult* result = PQexecParams(s_postgres, "SELECT \"idx\" FROM vault.\"Nodes\"" " WHERE \"NodeType\"=$1", 1, 0, sparm.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return false; } int count = PQntuples(result); if (count == 0) { PQclear(result); fprintf(stderr, "[Vault] Initializing empty DirtSand vault\n"); // Create system and global inbox nodes DS::Vault::Node node; node.set_NodeType(DS::Vault::e_NodeSystem); s_systemNode = v_create_node(node); if (s_systemNode == 0) return false; node.set_NodeType(DS::Vault::e_NodeFolder); node.set_Int32_1(DS::Vault::e_GlobalInboxFolder); uint32_t globalInbox = v_create_node(node); if (globalInbox == 0) return false; if (!v_ref_node(s_systemNode, globalInbox, 0)) return false; AuthServer_AgeInfo age; age.m_ageId = gen_uuid(); age.m_filename = "city"; age.m_instName = "Ae'gura"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "Neighborhood02"; age.m_instName = "Kirel"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "Kveer"; age.m_instName = "K'veer"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GreatTreePub"; age.m_instName = "The Watcher's Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GuildPub-Cartographers"; age.m_instName = "The Cartographers' Guild Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GuildPub-Greeters"; age.m_instName = "The Greeters' Guild Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GuildPub-Maintainers"; age.m_instName = "The Maintainers' Guild Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GuildPub-Messengers"; age.m_instName = "The Messengers' Guild Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; age.m_ageId = gen_uuid(); age.m_filename = "GuildPub-Writers"; age.m_instName = "The Writers' Guild Pub"; if (v_create_age(age, e_AgePublic).first == 0) return false; } else { DS_DASSERT(count == 1); s_systemNode = strtoul(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); } return true; }
char * seaf_repo_manager_create_virtual_repo (SeafRepoManager *mgr, const char *origin_repo_id, const char *path, const char *repo_name, const char *repo_desc, const char *owner, const char *passwd, GError **error) { SeafRepo *origin_repo = NULL; SeafCommit *origin_head = NULL; char *repo_id = NULL; char *dir_id = NULL; char *orig_owner = NULL; if (seaf_repo_manager_is_virtual_repo (mgr, origin_repo_id)) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Cannot create sub-library from a sub-library"); return NULL; } repo_id = get_existing_virtual_repo (mgr, origin_repo_id, path); if (repo_id) { return repo_id; } origin_repo = seaf_repo_manager_get_repo (mgr, origin_repo_id); if (!origin_repo) { seaf_warning ("Failed to get origin repo %.10s\n", origin_repo_id); g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Origin library not exists"); return NULL; } if (origin_repo->encrypted) { if (origin_repo->enc_version < 2) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Library encryption version must be higher than 2"); seaf_repo_unref (origin_repo); return NULL; } if (!passwd || passwd[0] == 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Password is not set"); seaf_repo_unref (origin_repo); return NULL; } if (seafile_verify_repo_passwd (origin_repo_id, passwd, origin_repo->magic, origin_repo->enc_version) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Incorrect password"); seaf_repo_unref (origin_repo); return NULL; } } origin_head = seaf_commit_manager_get_commit (seaf->commit_mgr, origin_repo->id, origin_repo->version, origin_repo->head->commit_id); if (!origin_head) { seaf_warning ("Failed to get head commit %.8s of repo %s.\n", origin_repo->head->commit_id, origin_repo->id); g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Bad origin repo head"); goto error; } dir_id = seaf_fs_manager_get_seafdir_id_by_path (seaf->fs_mgr, origin_repo->store_id, origin_repo->version, origin_head->root_id, path, NULL); if (!dir_id) { seaf_warning ("Path %s doesn't exist or is not a dir in repo %.10s.\n", path, origin_repo_id); g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Bad path"); goto error; } repo_id = gen_uuid(); /* Save virtual repo info before actually create the repo. */ if (save_virtual_repo_info (mgr, repo_id, origin_repo_id, path, origin_head->commit_id) < 0) { seaf_warning ("Failed to save virtual repo info for %.10s:%s", origin_repo_id, path); g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Internal error"); goto error; } orig_owner = seaf_repo_manager_get_repo_owner (mgr, origin_repo_id); if (do_create_virtual_repo (mgr, origin_repo, repo_id, repo_name, repo_desc, dir_id, orig_owner, passwd, error) < 0) goto error; if (seaf_repo_manager_set_repo_owner (mgr, repo_id, orig_owner) < 0) { seaf_warning ("Failed to set repo owner for %.10s.\n", repo_id); g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to set repo owner."); goto error; } /* The size of virtual repo is non-zero at the beginning. */ update_repo_size (repo_id); seaf_repo_unref (origin_repo); seaf_commit_unref (origin_head); g_free (dir_id); g_free (orig_owner); return repo_id; error: seaf_repo_unref (origin_repo); seaf_commit_unref (origin_head); g_free (repo_id); g_free (dir_id); g_free (orig_owner); return NULL; }
int gen_uuid_v1(char *uuid_str) { return gen_uuid(uuid_str, UUID_MAKE_V1); }
int gen_uuid_v4(char *uuid_str) { return gen_uuid(uuid_str, UUID_MAKE_V4); }
static uint32_t find_a_friendly_neighborhood_for_our_new_visitor(uint32_t playerInfoId) { PGresult* result = PQexec(s_postgres, "SELECT \"AgeUuid\" FROM game.\"PublicAges\"" " WHERE \"AgeFilename\" = 'Neighborhood'" " AND \"Population\" < 20 AND \"SeqNumber\" <> 0"); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return 0; } std::pair<uint32_t, uint32_t> ageNode; DS::Uuid ageId; if (PQntuples(result) != 0) { ageId = DS::Uuid(PQgetvalue(result, 0, 0)); PQclear(result); PostgresStrings<2> parms; parms.set(0, DS::Vault::e_NodeAgeInfo); parms.set(1, ageId.toString()); result = PQexecParams(s_postgres, "SELECT idx FROM vault.\"Nodes\"" " WHERE \"NodeType\"=$1 AND \"Uuid_1\"=$2", 2, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return 0; } DS_DASSERT(PQntuples(result) == 1); ageNode.second = strtoul(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); } else { PQclear(result); AuthServer_AgeInfo age; age.m_ageId = gen_uuid(); age.m_filename = "Neighborhood"; age.m_instName = "Neighborhood"; age.m_userName = "******"; age.m_description = "DS Neighborhood"; age.m_seqNumber = -1; // Auto-generate ageNode = v_create_age(age, e_AgePublic); if (ageNode.second == 0) return 0; } { PostgresStrings<2> parms; parms.set(0, ageNode.second); parms.set(1, DS::Vault::e_AgeOwnersFolder); result = PQexecParams(s_postgres, "SELECT idx FROM vault.find_folder($1, $2);", 2, 0, parms.m_values, 0, 0, 0); } if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return 0; } DS_DASSERT(PQntuples(result) == 1); uint32_t ownerFolder = strtoul(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); if (!v_ref_node(ownerFolder, playerInfoId, 0)) return 0; { PostgresStrings<1> parms; parms.set(0, ageId.toString()); result = PQexecParams(s_postgres, "UPDATE game.\"PublicAges\"" " SET \"Population\" = \"Population\"+1" " WHERE \"AgeUuid\" = $1", 1, 0, parms.m_values, 0, 0, 0); } if (PQresultStatus(result) != PGRES_COMMAND_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return 0; } PQclear(result); return ageNode.second; }
std::tuple<uint32_t, uint32_t, uint32_t> v_create_player(DS::Uuid acctId, const AuthServer_PlayerInfo& player) { DS::Vault::Node node; node.set_NodeType(DS::Vault::e_NodePlayer); node.set_CreatorUuid(acctId); node.set_Int32_2(player.m_explorer); node.set_Uuid_1(acctId); node.set_String64_1(player.m_avatarModel); node.set_IString64_1(player.m_playerName); uint32_t playerIdx = v_create_node(node); if (playerIdx == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfo); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Uint32_1(playerIdx); node.set_IString64_1(player.m_playerName); uint32_t playerInfoNode = v_create_node(node); if (playerInfoNode == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_BuddyListFolder); uint32_t buddyList = v_create_node(node); if (buddyList == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_IgnoreListFolder); uint32_t ignoreList = v_create_node(node); if (ignoreList == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_PlayerInviteFolder); uint32_t invites = v_create_node(node); if (invites == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_AgesIOwnFolder); uint32_t agesNode = v_create_node(node); if (agesNode == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_AgeJournalsFolder); uint32_t journals = v_create_node(node); if (journals == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_ChronicleFolder); uint32_t chronicles = v_create_node(node); if (chronicles == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_AgesICanVisitFolder); uint32_t visitFolder = v_create_node(node); if (visitFolder == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_AvatarOutfitFolder); uint32_t outfit = v_create_node(node); if (outfit == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_AvatarClosetFolder); uint32_t closet = v_create_node(node); if (closet == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_InboxFolder); uint32_t inbox = v_create_node(node); if (inbox == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Int32_1(DS::Vault::e_PeopleIKnowAboutFolder); uint32_t peopleNode = v_create_node(node); if (peopleNode == 0) return std::make_tuple(0, 0, 0); DS::Blob link(reinterpret_cast<const uint8_t*>("Default:LinkInPointDefault:;"), strlen("Default:LinkInPointDefault:;")); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeLink); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Blob_1(link); uint32_t reltoLink = v_create_node(node); if (reltoLink == 0) return std::make_tuple(0, 0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeLink); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Blob_1(link); uint32_t hoodLink = v_create_node(node); if (hoodLink == 0) return std::make_tuple(0, 0, 0); link = DS::Blob(reinterpret_cast<const uint8_t*>("Ferry Terminal:LinkInPointFerry:;"), strlen("Ferry Terminal:LinkInPointFerry:;")); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeLink); node.set_CreatorUuid(acctId); node.set_CreatorIdx(playerIdx); node.set_Blob_1(link); uint32_t cityLink = v_create_node(node); if (hoodLink == 0) return std::make_tuple(0, 0, 0); AuthServer_AgeInfo relto; relto.m_ageId = gen_uuid(); relto.m_filename = "Personal"; relto.m_instName = "Relto"; relto.m_userName = player.m_playerName + "'s"; relto.m_description = relto.m_userName + " " + relto.m_instName; std::tuple<uint32_t, uint32_t> reltoAge = v_create_age(relto, 0); if (std::get<0>(reltoAge) == 0) return std::make_tuple(0, 0, 0); { PostgresStrings<2> parms; parms.set(0, std::get<1>(reltoAge)); parms.set(1, DS::Vault::e_AgeOwnersFolder); PGresult* result = PQexecParams(s_postgres, "SELECT idx FROM vault.find_folder($1, $2);", 2, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_tuple(0, 0, 0); } DS_DASSERT(PQntuples(result) == 1); uint32_t ownerFolder = strtoul(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); if (!v_ref_node(ownerFolder, playerInfoNode, 0)) return std::make_tuple(0, 0, 0); } std::tuple<uint32_t, uint32_t> hoodAge = find_a_friendly_neighborhood_for_our_new_visitor(); if (std::get<0>(hoodAge) == 0) return std::make_tuple(0, 0, 0); uint32_t cityAge = find_public_age_1("city"); if (cityAge == 0) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, s_systemNode, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, playerInfoNode, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, buddyList, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, ignoreList, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, invites, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, agesNode, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, journals, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, chronicles, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, visitFolder, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, outfit, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, closet, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, inbox, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(playerIdx, peopleNode, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(agesNode, reltoLink, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(agesNode, hoodLink, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(agesNode, cityLink, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(reltoLink, std::get<1>(reltoAge), 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(hoodLink, std::get<0>(hoodAge), 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(cityLink, cityAge, 0)) return std::make_tuple(0, 0, 0); if (!v_ref_node(std::get<0>(reltoAge), agesNode, 0)) return std::make_tuple(0, 0, 0); return std::make_tuple(playerIdx, playerInfoNode, std::get<1>(hoodAge)); }
uint64_t gen_uuid64() { md5_hash h(gen_uuid()); return (static_cast<uint64_t>(h[0]) | (static_cast<uint64_t>(h[1]) << 32U)) ^ (static_cast<uint64_t>(h[3]) | (static_cast<uint64_t>(h[2]) << 20U)); }
// pTrace_archive may be NULL. Takes ownership of pTrace_archive. // TODO: Get rid of the demarcation packet, etc. Make the initial sequence of packets more explicit. bool vogl_trace_file_writer::open(const char *pFilename, vogl_archive_blob_manager *pTrace_archive, bool delete_archive, bool write_demarcation_packet, uint pointer_sizes) { VOGL_FUNC_TRACER close(); if (!pFilename) return false; m_filename = pFilename; if (!m_stream.open(pFilename, cDataStreamWritable | cDataStreamSeekable, false)) { vogl_error_printf("%s: Failed opening trace file \"%s\"\n", VOGL_METHOD_NAME, pFilename); return false; } vogl_message_printf("%s: Prepping trace file \"%s\"\n", VOGL_METHOD_NAME, pFilename); m_sof_packet.init(); m_sof_packet.m_pointer_sizes = pointer_sizes; m_sof_packet.m_first_packet_offset = sizeof(m_sof_packet); md5_hash h(gen_uuid()); VOGL_ASSUME(sizeof(h) == sizeof(m_sof_packet.m_uuid)); memcpy(&m_sof_packet.m_uuid, &h, sizeof(h)); m_sof_packet.finalize(); VOGL_VERIFY(m_sof_packet.full_validation(sizeof(m_sof_packet))); if (m_stream.write(&m_sof_packet, sizeof(m_sof_packet)) != sizeof(m_sof_packet)) { vogl_error_printf("%s: Failed writing to trace file \"%s\"\n", VOGL_METHOD_NAME, pFilename); return false; } if (pTrace_archive) { m_pTrace_archive.reset(pTrace_archive); m_delete_archive = delete_archive; } else { m_pTrace_archive.reset(vogl_new(vogl_archive_blob_manager)); m_delete_archive = true; if (!m_pTrace_archive->init_file_temp(cBMFReadWrite, NULL)) { vogl_error_printf("%s: Failed opening temp archive!\n", VOGL_METHOD_NAME); m_pTrace_archive.reset(); return false; } } // TODO: The trace reader records the first offset right after SOF, I would like to do this after the demarcation packet. m_frame_file_offsets.reserve(10000); m_frame_file_offsets.resize(0); m_frame_file_offsets.push_back(m_stream.get_ofs()); write_ctypes_packet(); write_entrypoints_packet(); if (write_demarcation_packet) { vogl_write_glInternalTraceCommandRAD(m_stream, m_pCTypes, cITCRDemarcation, 0, NULL); } vogl_message_printf("%s: Finished opening trace file \"%s\"\n", VOGL_METHOD_NAME, pFilename); return true; }
int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; int ret = 1; size_t i, j; int c, debug = 0; const char *log_file = NULL; const char *entropy_file = NULL; char **bss_config = NULL, **tmp_bss; size_t num_bss_configs = 0; #ifdef CONFIG_DEBUG_LINUX_TRACING int enable_trace_dbg = 0; #endif /* CONFIG_DEBUG_LINUX_TRACING */ if (os_program_init()) return -1; os_memset(&interfaces, 0, sizeof(interfaces)); interfaces.reload_config = hostapd_reload_config; interfaces.config_read_cb = hostapd_config_read; interfaces.for_each_interface = hostapd_for_each_interface; interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; interfaces.driver_init = hostapd_driver_init; interfaces.global_iface_path = NULL; interfaces.global_iface_name = NULL; interfaces.global_ctrl_sock = -1; wpa_supplicant_event = hostapd_wpa_event; for (;;) { c = getopt(argc, argv, "b:Bde:f:hKP:Ttu:g:G:v::"); if (c < 0) break; switch (c) { case 'h': usage(); break; case 'd': debug++; if (wpa_debug_level > 0) wpa_debug_level--; break; case 'B': daemonize++; break; case 'e': entropy_file = optarg; break; case 'f': log_file = optarg; break; case 'K': wpa_debug_show_keys++; break; case 'P': os_free(pid_file); pid_file = os_rel2abs_path(optarg); break; case 't': wpa_debug_timestamp++; break; #ifdef CONFIG_DEBUG_LINUX_TRACING case 'T': enable_trace_dbg = 1; break; #endif /* CONFIG_DEBUG_LINUX_TRACING */ case 'v': if (optarg) exit(!has_feature(optarg)); show_version(); exit(1); break; case 'g': if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) return -1; break; case 'G': if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) return -1; break; case 'b': tmp_bss = os_realloc_array(bss_config, num_bss_configs + 1, sizeof(char *)); if (tmp_bss == NULL) goto out; bss_config = tmp_bss; bss_config[num_bss_configs++] = optarg; break; #ifdef CONFIG_WPS case 'u': return gen_uuid(optarg); #endif /* CONFIG_WPS */ default: usage(); break; } } if (optind == argc && interfaces.global_iface_path == NULL && num_bss_configs == 0) usage(); wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); if (log_file) wpa_debug_open_file(log_file); #ifdef CONFIG_DEBUG_LINUX_TRACING if (enable_trace_dbg) { int tret = wpa_debug_open_linux_tracing(); if (tret) { wpa_printf(MSG_ERROR, "Failed to enable trace logging"); return -1; } } #endif /* CONFIG_DEBUG_LINUX_TRACING */ interfaces.count = argc - optind; if (interfaces.count || num_bss_configs) { interfaces.iface = os_calloc(interfaces.count + num_bss_configs, sizeof(struct hostapd_iface *)); if (interfaces.iface == NULL) { wpa_printf(MSG_ERROR, "malloc failed"); return -1; } } if (hostapd_global_init(&interfaces, entropy_file)) { wpa_printf(MSG_ERROR, "Failed to initilize global context"); return -1; } /* Allocate and parse configuration for full interface files */ for (i = 0; i < interfaces.count; i++) { interfaces.iface[i] = hostapd_interface_init(&interfaces, argv[optind + i], debug); if (!interfaces.iface[i]) { wpa_printf(MSG_ERROR, "Failed to initialize interface"); goto out; } } /* Allocate and parse configuration for per-BSS files */ for (i = 0; i < num_bss_configs; i++) { struct hostapd_iface *iface; char *fname; wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); fname = os_strchr(bss_config[i], ':'); if (fname == NULL) { wpa_printf(MSG_ERROR, "Invalid BSS config identifier '%s'", bss_config[i]); goto out; } *fname++ = '\0'; iface = hostapd_interface_init_bss(&interfaces, bss_config[i], fname, debug); if (iface == NULL) goto out; for (j = 0; j < interfaces.count; j++) { if (interfaces.iface[j] == iface) break; } if (j == interfaces.count) { struct hostapd_iface **tmp; tmp = os_realloc_array(interfaces.iface, interfaces.count + 1, sizeof(struct hostapd_iface *)); if (tmp == NULL) { hostapd_interface_deinit_free(iface); goto out; } interfaces.iface = tmp; interfaces.iface[interfaces.count++] = iface; } } /* * Enable configured interfaces. Depending on channel configuration, * this may complete full initialization before returning or use a * callback mechanism to complete setup in case of operations like HT * co-ex scans, ACS, or DFS are needed to determine channel parameters. * In such case, the interface will be enabled from eloop context within * hostapd_global_run(). */ interfaces.terminate_on_error = interfaces.count; for (i = 0; i < interfaces.count; i++) { if (hostapd_driver_init(interfaces.iface[i]) || hostapd_setup_interface(interfaces.iface[i])) goto out; } hostapd_global_ctrl_iface_init(&interfaces); if (hostapd_global_run(&interfaces, daemonize, pid_file)) { wpa_printf(MSG_ERROR, "Failed to start eloop"); goto out; } ret = 0; out: hostapd_global_ctrl_iface_deinit(&interfaces); /* Deinitialize all interfaces */ for (i = 0; i < interfaces.count; i++) { if (!interfaces.iface[i]) continue; interfaces.iface[i]->driver_ap_teardown = !!(interfaces.iface[i]->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); hostapd_interface_deinit_free(interfaces.iface[i]); } os_free(interfaces.iface); hostapd_global_deinit(pid_file); os_free(pid_file); if (log_file) wpa_debug_close_file(); wpa_debug_close_linux_tracing(); os_free(bss_config); os_program_deinit(); return ret; }
std::tuple<uint32_t, uint32_t> v_create_age(AuthServer_AgeInfo age, uint32_t flags) { if (age.m_ageId.isNull()) age.m_ageId = gen_uuid(); int seqNumber = age.m_seqNumber; if (seqNumber < 0) { check_postgres(); PGresult* result = PQexec(s_postgres, "SELECT nextval('game.\"AgeSeqNumber\"'::regclass)"); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_pair(0, 0); } DS_DASSERT(PQntuples(result) == 1); seqNumber = strtol(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); } DS::Vault::Node node; node.set_NodeType(DS::Vault::e_NodeAge); node.set_CreatorUuid(age.m_ageId); node.set_Uuid_1(age.m_ageId); if (!age.m_parentId.isNull()) node.set_Uuid_2(age.m_parentId); node.set_String64_1(age.m_filename); uint32_t ageNode = v_create_node(node); if (ageNode == 0) return std::make_pair(0, 0); // TODO: Global SDL node node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_ChronicleFolder); uint32_t chronFolder = v_create_node(node); if (chronFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_PeopleIKnowAboutFolder); uint32_t knownFolder = v_create_node(node); if (knownFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_SubAgesFolder); uint32_t subAgesFolder = v_create_node(node); if (subAgesFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfo); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(seqNumber); node.set_Int32_2((flags & e_AgePublic) != 0 ? 1 : 0); node.set_Int32_3(age.m_language); node.set_Uint32_1(ageNode); node.set_Uint32_2(0); // Czar ID node.set_Uint32_3(0); // Flags node.set_Uuid_1(age.m_ageId); if (!age.m_parentId.isNull()) node.set_Uuid_2(age.m_parentId); node.set_String64_2(age.m_filename); if (!age.m_instName.isNull()) node.set_String64_3(age.m_instName); if (!age.m_userName.isEmpty()) node.set_String64_4(age.m_userName); if (!age.m_description.isEmpty()) node.set_Text_1(age.m_description); uint32_t ageInfoNode = v_create_node(node); if (ageInfoNode == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_AgeDevicesFolder); uint32_t devsFolder = v_create_node(node); if (devsFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_CanVisitFolder); uint32_t canVisitList = v_create_node(node); if (canVisitList == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeSDL); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(0); node.set_String64_1(age.m_filename); node.set_Blob_1(gen_default_sdl(age.m_filename)); uint32_t ageSdlNode = v_create_node(node); if (ageSdlNode == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_AgeOwnersFolder); uint32_t ageOwners = v_create_node(node); if (ageOwners == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_ChildAgesFolder); uint32_t childAges = v_create_node(node); if (childAges == 0) return std::make_pair(0, 0); if (!v_ref_node(ageNode, s_systemNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, chronFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, knownFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, subAgesFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, ageInfoNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, devsFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, canVisitList, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, ageSdlNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, ageOwners, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, childAges, 0)) return std::make_pair(0, 0); // Register with the server database { DS::String agedesc = !age.m_description.isEmpty() ? age.m_description : !age.m_instName.isEmpty() ? age.m_instName : age.m_filename; PostgresStrings<5> parms; parms.set(0, age.m_ageId.toString()); parms.set(1, age.m_filename); parms.set(2, agedesc); parms.set(3, ageNode); parms.set(4, ageSdlNode); PGresult* result = PQexecParams(s_postgres, "INSERT INTO game.\"Servers\"" " (\"AgeUuid\", \"AgeFilename\", \"DisplayName\", \"AgeIdx\", \"SdlIdx\")" " VALUES ($1, $2, $3, $4, $5)", 5, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_COMMAND_OK) { fprintf(stderr, "%s:%d:\n Postgres INSERT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_pair(0, 0); } PQclear(result); } return std::make_tuple(ageNode, ageInfoNode); }