static void linphone_vcard_import_export_friends_test(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc); const MSList *friends = linphone_friend_list_get_friends(lfl); char *import_filepath = bc_tester_res("vcards/vcards.vcf"); char *export_filepath = create_filepath(bc_tester_get_writable_dir_prefix(), "export_vcards", "vcf"); int count = 0; BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath); BC_ASSERT_EQUAL(count, 3, int, "%d"); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); linphone_friend_list_export_friends_as_vcard4_file(lfl, export_filepath); lfl = linphone_core_create_friend_list(manager->lc); count = linphone_friend_list_import_friends_from_vcard4_file(lfl, export_filepath); BC_ASSERT_EQUAL(count, 3, int, "%d"); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); linphone_friend_list_unref(lfl); remove(export_filepath); ms_free(import_filepath); ms_free(export_filepath); linphone_core_manager_destroy(manager); }
static int open_channel(char *name) { static char infile[256]; create_filepath(infile, sizeof(infile), name, "in"); if(access(infile, F_OK) == -1) mkfifo(infile, S_IRWXU); return open(infile, O_RDONLY | O_NONBLOCK, 0); }
static void print_out(char *channel, char *buf) { static char outfile[256], server[256], buft[18]; FILE *out = NULL; time_t t = time(0); if(channel) snprintf(server, sizeof(server), "-!- %s", channel); if(strstr(buf, server)) channel=""; create_filepath(outfile, sizeof(outfile), channel, "out"); if(!(out = fopen(outfile, "a"))) return; if(channel && channel[0]) add_channel(channel); strftime(buft, sizeof(buft), "%F %R", localtime(&t)); fprintf(out, "%s %s\n", buft, buf); fclose(out); }
static int load_vomses(const char *path, voms_string_array *array) { struct stat file_stat; assert(path != NULL); if (stat(path, &file_stat) < 0) { return -1; } if (S_ISREG(file_stat.st_mode)) { int i; char **vomses = NULL; vomses = load_vomses_file(path); if (vomses == NULL) { return -1; } for (i = 0; vomses[i] != NULL; i++) { voms_string_array_add(array, vomses[i]); free(vomses[i]); } free(vomses); } else if (S_ISDIR(file_stat.st_mode)) { DIR *dp = opendir(path); if (dp != NULL) { struct dirent *entry; while ((entry = readdir(dp)) != NULL) { char *name = entry->d_name; if (name && (strcmp(name, ".") != 0) && (strcmp(name, "..") != 0)) { char * filepath = create_filepath(path, name); if (filepath != NULL) { load_vomses(filepath, array); free(filepath); filepath = NULL; } } } closedir(dp); } } return 0; }
static void carddav_sync_3(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nFN:Sylvain Berfini\r\nIMPP;TYPE=work:sip:[email protected]\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneCardDavContext *c = NULL; linphone_friend_list_set_uri(lfl, CARDDAV_SERVER); linphone_core_add_friend_list(manager->lc, lfl); linphone_friend_list_unref(lfl); c = linphone_carddav_context_new(lfl); BC_ASSERT_PTR_NOT_NULL_FATAL(c); unlink(friends_db); linphone_core_set_friends_database_path(manager->lc, friends_db); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); linphone_friend_unref(lf); linphone_carddav_set_user_data(c, stats); linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done); linphone_carddav_set_new_contact_callback(c, carddav_new_contact); linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact); linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact); linphone_carddav_synchronize(c); wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i"); ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_carddav_context_destroy(c); c = NULL; linphone_core_manager_destroy(manager); }
static void carddav_sync_2(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "\"Sylvain\" <sip:[email protected]>"); char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneCardDavContext *c = NULL; linphone_friend_list_set_uri(lfl, CARDDAV_SERVER); linphone_core_add_friend_list(manager->lc, lfl); linphone_friend_list_unref(lfl); c = linphone_carddav_context_new(lfl); BC_ASSERT_PTR_NOT_NULL_FATAL(c); unlink(friends_db); linphone_core_set_friends_database_path(manager->lc, friends_db); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); linphone_friend_unref(lf); linphone_carddav_set_user_data(c, stats); linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done); linphone_carddav_set_new_contact_callback(c, carddav_new_contact); linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact); linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact); linphone_carddav_synchronize(c); wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i"); wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i"); ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_carddav_context_destroy(c); linphone_core_manager_destroy(manager); }
static void friends_migration(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE); LpConfig *lpc = linphone_core_get_config(manager->lc); LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc); const MSList *friends = linphone_friend_list_get_friends(lfl); MSList *friends_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 0, int, "%i"); unlink(friends_db); linphone_core_set_friends_database_path(manager->lc, friends_db); lfl = linphone_core_get_default_friend_list(manager->lc); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d"); BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 1, int, "%i"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); unlink(friends_db); ms_free(friends_db); linphone_core_manager_destroy(manager); }
/** Returns: -1 - if we need to terminate (EOF or mapping is not readable) 0 - if the line was processed correctly */ static int readline(FILE * fp){ char c; /* char red */ char name[MAX_NAME+1]; /* name of file */ char output_filename[1024]; int i; /* reused in few places */ FILE *fdw = NULL; int ret = 0; if((c=getc(fp))==EOF) return -1; lineNum++; while(c=='\r') c=getc(fp); if(c=='\n') return 0; /* read name */ i = 0; while(1){ name[i++]=c; if(i==MAX_NAME){ /* out of buffer - cut the name */ name[i]='\0'; break; } if((c=getc(fp))==EOF) return -1; if(c=='\n') return 0; /* ignore - not complete line */ while(c=='\r') c=getc(fp); if(c==FIELDS_DELIMITER){ name[i] = '\0'; break; } } /* skip the rest, 5 tabs, until genome. Exit in case of EOL and EOL */ for(i=0; i<5; i++){ while(1){ c=getc(fp); while(c=='\r') c=getc(fp); if(c==EOF) return -1; if(c=='\n') return 0; if(c==FIELDS_DELIMITER){ break; } } } /* Here we have genome ahead, so we can create the file */ create_filepath(name, output_filename); if(debug) printf("%s\n", output_filename); if((fdw = fopen(output_filename, "w")) == NULL){ fprintf(stderr, "Can't open output file %s. Please create target directory and verify write permissions\n", output_filename); return -1; } if(fputs(header(), fdw)<0){ fprintf(stderr, "Can't write into file: %s\n", strerror(errno)); return -1; } else{ ret = read_genome(fp, fdw); } fclose(fdw); return ret; }
static void friends_sqlite_storage(void) { LinphoneCoreVTable *v_table = linphone_core_v_table_new(); LinphoneCore* lc = NULL; LinphoneFriendList *lfl = NULL; LinphoneFriend *lf = NULL; LinphoneFriend *lf2 = NULL; LinphoneVcard *lvc = linphone_vcard_new(); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const MSList *friends = NULL; MSList *friends_from_db = NULL; MSList *friends_lists_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); v_table->friend_list_created = friend_list_created_cb; v_table->friend_list_removed = friend_list_removed_cb; lc = linphone_core_new(v_table, NULL, NULL, NULL); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); lfl = linphone_core_create_friend_list(lc); linphone_friend_list_set_user_data(lfl, stats); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); unlink(friends_db); linphone_core_set_friends_database_path(lc, friends_db); friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); linphone_vcard_set_etag(lvc, "\"123-456789\""); linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf"); lf = linphone_friend_new_from_vcard(lvc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_core_add_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i"); linphone_friend_list_unref(lfl); linphone_friend_list_set_display_name(lfl, "Test"); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i"); linphone_friend_unref(lf); BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d"); BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d"); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc); BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d"); friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends; BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_PTR_NOT_NULL(lf2->lc); BC_ASSERT_PTR_NOT_NULL(lf2->friend_list); friends_lists_from_db = ms_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf)); BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, int, "%i"); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_address_as_string(linphone_friend_get_address(lf2)), linphone_address_as_string(linphone_friend_get_address(lf))); linphone_friend_edit(lf); linphone_friend_set_name(lf, "Margaux"); linphone_friend_done(lf); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); linphone_friend_list_remove_friend(lfl, lf); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); linphone_core_remove_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i"); end: ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_address_unref(addr); linphone_core_destroy(lc); }