static void test_otrl_instag_read(void) { OtrlUserState us = otrl_userstate_create(); OtrlInsTag* one, *two, *three, *four; char sone[9] = {0}, stwo[9] = {0}, sfour[9] = {0}; one = two = three = four = NULL; ok(otrl_instag_read(us, "/non_existent_file") == gcry_error_from_errno(ENOENT), "Non-existent file detected"); ok(otrl_instag_read(us, instag_filepath) == GPG_ERR_NO_ERROR, "Instag called with success"); one = otrl_instag_find(us, "alice_xmpp", "XMPP"); snprintf(sone, sizeof(sone), "%08x", one->instag); two = otrl_instag_find(us, "alice_irc", "IRC"); snprintf(stwo, sizeof(stwo), "%08x", two->instag); three = otrl_instag_find(us, "alice_inv", "IRC"); four = otrl_instag_find(us, "alice_icq", "ICQ"); snprintf(sfour, sizeof(sfour), "%08x", four->instag); ok(one && two && !three && four && strcmp(sone, "01234567") == 0 && strcmp(stwo, "9abcdef0") == 0 && strcmp(sfour, "98765432") == 0, "Instag succesfully read"); }
/* * Load instance tags. */ static void instag_load(struct otr_user_state *ustate) { int ret; char *filename; gcry_error_t err; assert(ustate); /* Getting the otr instance filename path */ ret = asprintf(&filename, "%s%s", get_client_config_dir(), OTR_INSTAG_FILE); if (ret < 0) { goto error_filename; } ret = access(filename, F_OK); if (ret < 0) { IRSSI_DEBUG("no instance tags found at %9%s%9", filename); goto end; } err = otrl_instag_read(ustate->otr_state, filename); if (err == GPG_ERR_NO_ERROR) { IRSSI_DEBUG("Instance tags loaded from %9%s%9", filename); } else { IRSSI_DEBUG("Error loading instance tags: %d (%d)", gcry_strerror(err), gcry_strsource(err)); } end: free(filename); error_filename: return; }
void ReadPrivkeyFiles() { DEBUGOUT_T("READ privkey"); lib_cs_lock(); otrl_privkey_read(otr_user_state, _T2A(g_private_key_filename)); otrl_privkey_read_fingerprints(otr_user_state, _T2A(g_fingerprint_store_filename), set_context_contact, 0); otrl_instag_read(otr_user_state, _T2A(g_instag_filename)); }
void OtrInstanceTagService::readInstanceTags() { if (!UserStateService) return; QString fileName = PathService->instanceTagsStoreFilePath(); otrl_instag_read(UserStateService.data()->userState(), fileName.toUtf8().data()); }
static void read_instag(char *file) { pthread_mutex_lock(&log_mutex); fprintf(logfd, "About to read instance tag: %s \n", file); fflush(logfd); pthread_mutex_unlock(&log_mutex); if (otrl_instag_read(us, file)) { fprintf(stderr, "Error reading instance tags"); } }
OtrInternal::OtrInternal(psiotr::OtrCallback* callback, psiotr::OtrPolicy& policy) : m_userstate(), m_uiOps(), m_callback(callback), m_otrPolicy(policy), is_generating(false) { QDir profileDir(callback->dataDir()); m_keysFile = profileDir.filePath(OTR_KEYS_FILE); m_instagsFile = profileDir.filePath(OTR_INSTAGS_FILE); m_fingerprintFile = profileDir.filePath(OTR_FINGERPRINTS_FILE); OTRL_INIT; m_userstate = otrl_userstate_create(); m_uiOps.policy = (*OtrInternal::cb_policy); m_uiOps.create_privkey = (*OtrInternal::cb_create_privkey); m_uiOps.is_logged_in = (*OtrInternal::cb_is_logged_in); m_uiOps.inject_message = (*OtrInternal::cb_inject_message); m_uiOps.update_context_list = (*OtrInternal::cb_update_context_list); m_uiOps.new_fingerprint = (*OtrInternal::cb_new_fingerprint); m_uiOps.write_fingerprints = (*OtrInternal::cb_write_fingerprints); m_uiOps.gone_secure = (*OtrInternal::cb_gone_secure); m_uiOps.gone_insecure = (*OtrInternal::cb_gone_insecure); m_uiOps.still_secure = (*OtrInternal::cb_still_secure); #if (OTRL_VERSION_MAJOR > 3 || (OTRL_VERSION_MAJOR == 3 && OTRL_VERSION_MINOR >= 2)) m_uiOps.max_message_size = NULL; m_uiOps.account_name = (*OtrInternal::cb_account_name); m_uiOps.account_name_free = (*OtrInternal::cb_account_name_free); #endif #if (OTRL_VERSION_MAJOR >= 4) m_uiOps.handle_msg_event = (*OtrInternal::cb_handle_msg_event); m_uiOps.handle_smp_event = (*OtrInternal::cb_handle_smp_event); m_uiOps.create_instag = (*OtrInternal::cb_create_instag); #else m_uiOps.log_message = (*OtrInternal::cb_log_message); m_uiOps.notify = (*OtrInternal::cb_notify); m_uiOps.display_otr_message = (*OtrInternal::cb_display_otr_message); m_uiOps.protocol_name = (*OtrInternal::cb_protocol_name); m_uiOps.protocol_name_free = (*OtrInternal::cb_protocol_name_free); #endif otrl_privkey_read(m_userstate, QFile::encodeName(m_keysFile).constData()); otrl_privkey_read_fingerprints(m_userstate, QFile::encodeName(m_fingerprintFile).constData(), NULL, NULL); #if (OTRL_VERSION_MAJOR >= 4) otrl_instag_read(m_userstate, QFile::encodeName(m_instagsFile).constData()); #endif }
int main(int argc, char **argv) { OTRL_INIT; us = otrl_userstate_create(); otrl_privkey_read(us, "/home/iang/.gaim/otr.private_key"); otrl_instag_read(us, "inst.txt"); test(1,0); test(2,0); test(3,0); test(1,1); test(2,1); test_unreadable(); test_crash1(); test_refresh(3); test_refresh(2); test_refresh(1); otrl_userstate_free(us); return 0; }