/** * @brief replace a dns by a new * @param old_dns the old dns * @param new_dns the new dns * @return Return 1 if the dns is replace, else 0 */ int exalt_dns_replace(const char* old_dns, const char* new_dns) { char buf[1024], buf2[1024], buf3[1024];; FILE* fw, *fr; EXALT_ASSERT_RETURN(old_dns!=NULL); EXALT_ASSERT_RETURN(new_dns!=NULL); EXALT_ASSERT_RETURN(exalt_is_address(new_dns)); ecore_file_cp(EXALT_RESOLVCONF_FILE, EXALT_TEMP_FILE); fr = fopen(EXALT_TEMP_FILE, "ro"); EXALT_ASSERT_RETURN(fr!=NULL); fw = fopen(EXALT_RESOLVCONF_FILE, "w"); EXALT_ASSERT_ADV(fw!=NULL,EXALT_FCLOSE(fr);return 0,"f!=NULL failed"); sprintf(buf,"nameserver %s\n",old_dns); sprintf(buf3,"nameserver %s\n",new_dns); while(fgets(buf2,1024,fr)) if( strcmp(buf,buf2) != 0) fwrite( buf2, sizeof(char), strlen(buf2), fw); else fwrite( buf3, sizeof(char), strlen(buf3), fw); EXALT_FCLOSE(fr); EXALT_FCLOSE(fw); remove(EXALT_TEMP_FILE); return 1; }
char *utils_file_move_in_pres(const char *file) { const char *pres_file = eyelight_object_presentation_file_get(pres); char *dir = ecore_file_dir_get(pres_file); char *res; int ok = 1; int i; //test if file is in a subdirectory of dir for(i=0;i<strlen(dir);i++) { if(i >= strlen(file) || dir[i] != file[i]) { ok = 0; break; } else i++; } if(!ok) { const char* file_name = ecore_file_file_get(file); char buf[PATH_MAX]; res = calloc(PATH_MAX, sizeof(char)); snprintf(buf, PATH_MAX, "%s/images/", dir); if(!ecore_file_exists(buf)) ecore_file_mkdir(buf); snprintf(buf, PATH_MAX, "%s/images/%s", dir, file_name); ecore_file_cp(file, buf); snprintf(res,PATH_MAX,"images/%s", file_name); } else { const char *_file = file + strlen(dir) + 1; res = strdup(_file); } EYELIGHT_FREE(dir); return res; }
/** * @brief delete a dns * @param dns the dns * @return Return 1 if the dns is delete, else 0 */ int exalt_dns_delete(const char* dns) { char buf[1024], buf2[1024]; FILE* fw, *fr; EXALT_ASSERT_RETURN(dns!=NULL); ecore_file_cp(EXALT_RESOLVCONF_FILE, EXALT_TEMP_FILE); fr = fopen(EXALT_TEMP_FILE, "ro"); EXALT_ASSERT_RETURN(fr!=NULL); fw = fopen(EXALT_RESOLVCONF_FILE, "w"); EXALT_ASSERT_ADV(fw!=NULL,EXALT_FCLOSE(fr);return 0,"f!=NULL failed"); sprintf(buf,"nameserver %s\n",dns); while(fgets(buf2,1024,fr)) if( strcmp(buf,buf2) != 0) fwrite( buf2, sizeof(char), strlen(buf2), fw); EXALT_FCLOSE(fr); EXALT_FCLOSE(fw); remove(EXALT_TEMP_FILE); return 1; }
static void _make_config(const char *config_file) { Eet_File *ef; FILE *f; int textlen; char *text; /* Create default config path and file */ if (!config_file) { conf_filename = eina_stringshare_add(ems_config_filename_default_get()); if (!ecore_file_is_dir(ems_config_dirname_get())) ecore_file_mkpath(ems_config_dirname_get()); } else if (!ecore_file_exists(config_file)) { conf_filename = eina_stringshare_add(config_file); ecore_file_mkpath(ecore_file_dir_get(config_file)); } else { conf_filename = eina_stringshare_add(config_file); } INF("Config file : %s", conf_filename); if (!ecore_file_is_dir(ems_config_tmp_dirname_get())) ecore_file_mkdir(ems_config_tmp_dirname_get()); ef = eet_open(ems_config_tmp_filename_get(), EET_FILE_MODE_READ_WRITE); if (!ef) ef = eet_open(ems_config_tmp_filename_get(), EET_FILE_MODE_WRITE); f = fopen(conf_filename, "rb"); if (!f) { WRN("Could not open '%s', setup default config.", ems_config_filename_get()); if (ecore_file_exists(ems_config_default_filename_get())) { ecore_file_cp(ems_config_default_filename_get(), ems_config_filename_get()); f = fopen(ems_config_filename_get(), "rb"); if (!f) return; } else return; } fseek(f, 0, SEEK_END); textlen = ftell(f); rewind(f); text = (char *)malloc(textlen); if (!text) { fclose(f); eet_close(ef); return; } if (fread(text, textlen, 1, f) != 1) { free(text); fclose(f); eet_close(ef); return; } fclose(f); if (eet_data_undump(ef, "config", text, textlen, 1)) INF("Updating configuration %s", conf_filename); free(text); eet_close(ef); }
/** * @brief Download the given url to the given destination. * * @param url The complete url to download. * @param dst The local file to save the downloaded to. * @param completion_cb A callback called on download complete. * @param progress_cb A callback called during the download operation. * @param data User data passed to both callbacks. * @param job_ret Job used to abort the download. * @return EINA_TRUE if the download start or EINA_FALSE on failure * * This function starts the download of the URL @p url and saves it to * @p dst. @p url must provide the protocol, including 'http://', * 'ftp://' or 'file://'. Ecore_File must be compiled with CURL to * download using http and ftp protocols. If @p dst is ill-formed, or * if it already exists, the function returns EINA_FALSE. When the * download is complete, the callback @p completion_cb is called and * @p data is passed to it. The @p status parameter of @p completion_cb * will be filled with the status of the download (200, 404,...). The * @p progress_cb is called during the download operation, each time a * packet is received or when CURL wants. It can be used to display the * percentage of the downloaded file. Return 0 from this callback, if provided, * to continue the operation or anything else to abort the download. The only * operations that can be aborted are those with protocol 'http' or 'ftp'. In * that case @p job_ret can be filled. It can be used with * ecore_file_download_abort() or ecore_file_download_abort_all() to * respectively abort one or all download operations. This function returns * EINA_TRUE if the download starts, EINA_FALSE otherwise. */ EAPI Eina_Bool ecore_file_download(const char *url, const char *dst, Ecore_File_Download_Completion_Cb completion_cb, Ecore_File_Download_Progress_Cb progress_cb, void *data, Ecore_File_Download_Job **job_ret) { #ifdef BUILD_ECORE_CON char *dir = ecore_file_dir_get(dst); if (!ecore_file_is_dir(dir)) { EINA_LOG_ERR("%s is not a directory", dir); free(dir); return EINA_FALSE; } free(dir); if (ecore_file_exists(dst)) { EINA_LOG_ERR("%s already exists", dst); return EINA_FALSE; } if (!strncmp(url, "file://", 7)) { /* FIXME: Maybe fork? Might take a while to copy. * Check filesize? */ /* Just copy it */ url += 7; /* skip hostname */ url = strchr(url, '/'); return ecore_file_cp(url, dst); } # ifdef HAVE_CURL else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) || (!strncmp(url, "ftp://", 6))) { /* download */ Ecore_File_Download_Job *job; job = _ecore_file_download_curl(url, dst, completion_cb, progress_cb, data); if(job_ret) *job_ret = job; if(job) return EINA_TRUE; else { EINA_LOG_ERR("no job returned\n"); return EINA_FALSE; } return job ? EINA_TRUE : EINA_FALSE; } # else else if ((!strncmp(url, "http://", 7)) || (!strncmp(url, "https://", 8)) || (!strncmp(url, "ftp://", 6))) { (void)completion_cb; (void)progress_cb; (void)data; (void)job_ret; return EINA_FALSE; } # endif else { return EINA_FALSE; } #else completion_cb = NULL; progress_cb = NULL; data = NULL; return EINA_FALSE; #endif /* BUILD_ECORE_CON */ }