static int stormfs_rename(const char *from, const char *to) { int result; struct stat st; DEBUG("rename: %s -> %s\n", from, to); if((result = valid_path(from)) != 0) return result; if((result = valid_path(to)) != 0) return result; if((result = stormfs_getattr(from, &st)) != 0) return result; if((result = proxy_rename(from, to, &st)) != 0) return result; // FIXME: cache_rename cache_invalidate_dir(from); cache_invalidate_dir(to); return result; }
static int stormfs_truncate(const char *path, off_t size) { int fd; int result; struct stat st; struct file *f; DEBUG("truncate: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = stormfs_getattr(path, &st)) != 0) return -result; f = cache_get(path); if(cache_file_valid(f)) { char *cp = cache_path(f); if((result = truncate(cp, size)) != 0) perror("truncate"); free(cp); } else { fd = cache_create_file(f); close(fd); } pthread_mutex_lock(&f->lock); f->st->st_size = get_blocks(size); cache_touch(f); pthread_mutex_unlock(&f->lock); return 0; }
static bool has_valid_session(request_rec *r, modauthopenid_config *s_cfg) { // test for valid session - if so, return DECLINED std::string session_id = ""; modauthopenid::get_session_id(r, std::string(s_cfg->cookie_name), session_id); if(session_id != "" && s_cfg->use_cookie) { modauthopenid::debug("found session_id in cookie: " + session_id); modauthopenid::session_t session; modauthopenid::SessionManager sm(std::string(s_cfg->db_location)); sm.get_session(session_id, session); sm.close(); // if session found if(std::string(session.identity) != "") { std::string uri_path; modauthopenid::base_dir(std::string(r->uri), uri_path); std::string valid_path(session.path); // if found session has a valid path if(valid_path == uri_path.substr(0, valid_path.size()) && apr_strnatcmp(session.hostname.c_str(), r->hostname)==0) { const char* idchar = std::string(session.identity).c_str(); APDEBUG(r, "setting REMOTE_USER to \"%s\"", idchar); r->user = apr_pstrdup(r->pool, idchar); return true; } else { APDEBUG(r, "session found for different path or hostname (cooke was for %s)", session.hostname.c_str()); } } } return false; };
static int stormfs_create(const char *path, mode_t mode, struct fuse_file_info *fi) { int result; struct stat st; struct file *f; DEBUG("create: %s\n", path); if((result = valid_path(path)) != 0) return result; cache_invalidate_dir(path); f = cache_get(path); fi->fh = cache_create_file(f); st.st_gid = getgid(); st.st_uid = getuid(); st.st_mode = mode; st.st_ctime = time(NULL); st.st_mtime = time(NULL); if((result = proxy_create(path, &st)) != 0) return result; pthread_mutex_lock(&f->lock); if(f->st == NULL) f->st = g_new0(struct stat, 1); memcpy(f->st, &st, sizeof(struct stat)); cache_touch(f); pthread_mutex_unlock(&f->lock); return result; }
int test_everything(struct fact_table *ft, void *data) { struct world_list *worlds = data; if (check_for_initial_fact(ft, worlds) != TEST_OK) return NO_INITIAL_FACT; if (check_for_extra_fact(ft, worlds) != TEST_OK) return EXTRA_FACTS; if (duplicate_fact(ft)) return DUPLICATE_FACTS; if (check_unknown_id(ft, worlds) != TEST_OK) return UNKNOWN_ID; if (check_incorrect(ft, worlds) != TEST_OK) return INCORRECT_WIN_RECORD; if (check_end_of_field(ft, worlds) != TEST_OK) return NO_END_OF_FIELD; if (check_invalid_start_path(ft, worlds) != TEST_OK) return INVALID_PATH_START; if (valid_path(ft, worlds) != TEST_OK) return NO_SUCH_PATH; return TEST_OK; }
static int stormfs_chmod(const char *path, mode_t mode) { int result; struct file *f; struct stat st; DEBUG("chmod: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = stormfs_getattr(path, &st)) != 0) return result; st.st_mode = mode; st.st_ctime = time(NULL); st.st_mtime = time(NULL); if((result = proxy_chmod(path, &st)) != 0) return result; f = cache_get(path); if(cache_valid(f) && f->st != NULL) { pthread_mutex_lock(&f->lock); f->st->st_mode = mode; f->st->st_ctime = st.st_ctime; f->st->st_mtime = st.st_mtime; cache_touch(f); pthread_mutex_unlock(&f->lock); } return result; }
static int stormfs_utimens(const char *path, const struct timespec ts[2]) { int result; struct file *f; struct stat st; DEBUG("utimens: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = stormfs_getattr(path, &st)) != 0) return result; st.st_mtime = ts[1].tv_sec; if((result = proxy_utimens(path, &st)) != 0) return result; f = cache_get(path); if(cache_valid(f) && f->st != NULL) { pthread_mutex_lock(&f->lock); f->st->st_mtime = st.st_mtime; cache_touch(f); pthread_mutex_unlock(&f->lock); } return result; }
void arrow::set_style(const std::string& style) { style_ = style; if (valid_path(path_)) { update_symbols(); } }
void arrow::set_color(std::string const& color) { color_ = color; if (valid_path(path_)) { update_symbols(); } }
void arrow::set_path(arrow_path_t const& path) { if (valid_path(path)) { previous_path_ = path_; path_ = path; invalidate_arrow_path(previous_path_); update_symbols(); notify_arrow_changed(); } }
static int stormfs_symlink(const char *from, const char *to) { int result; struct stat st; DEBUG("symlink: %s -> %s\n", from, to); if((result = valid_path(from)) != 0) return result; if((result = valid_path(to)) != 0) return result; st.st_mode = S_IFLNK; st.st_mtime = time(NULL); if((result = proxy_symlink(from, to, &st)) != 0) return result; cache_invalidate_dir(to); return result; }
static int stormfs_open(const char *path, struct fuse_file_info *fi) { FILE *fp; int fd; int result; struct file *f; DEBUG("open: %s\n", path); if((result = valid_path(path)) != 0) return result; if(fi->flags & O_TRUNC) if((result = stormfs_truncate(path, 0)) != 0) return result; f = cache_get(path); if(cache_file_valid(f)) { char *cp = cache_path(f); fp = fopen(cp, "a+"); free(cp); if(fp == NULL) return -errno; if((fd = fileno(fp)) == -1) return -errno; fi->fh = fd; return 0; } // file not available in cache, download it. if((fd = cache_create_file(f)) == -1) return -1; // FIXME: need to return proper errors here. if((fp = fdopen(fd, "a+")) == NULL) return -errno; if((result = proxy_open(path, fp)) != 0) { fclose(fp); return result; } fi->fh = fd; return result; }
static int stormfs_rmdir(const char *path) { int result = 0; DEBUG("rmdir: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = proxy_rmdir(path)) != 0) return result; cache_invalidate_dir(path); return result; }
int stormfs_unlink(const char *path) { int result; DEBUG("unlink: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = proxy_unlink(path)) != 0) return result; cache_invalidate_dir(path); return result; }
void writer::set_path() { //create a tempory path std::string tempPath; std::cout << "Enter a path for the output:" << std::ends; //set the path do { //clear it if it hasn't already tempPath.clear(); //get a path std::cout << std::flush; std::getline(std::cin, tempPath); } while (!valid_path(tempPath)); //loop till they enter a valid path std::cout << std::flush; //if it is valid set the path of the object path = tempPath; }
/** * @arg int * tour : partial path to search under * @arg int num_of_cities : total number of cities possible * @arg int ** city_dist : distance matrix * @arg int current_size : current tour length * @arg int local_best : best length according to the caller */ int *dfs(int *tour, const int num_of_cities, int **city_dist, const int current_size, int local_best) { int *my_best_path = malloc((unsigned long) num_of_cities * sizeof(int)); // Check to see if we've reached the max size, just return the last tour possible if (current_size == num_of_cities) { memcpy(my_best_path, tour, (unsigned long) num_of_cities * sizeof(int)); } else { int my_best = local_best; memcpy(my_best_path, tour, (unsigned long) num_of_cities * sizeof(int)); // just assume best path is the current tour // If we're still alive, generate all of the subproblems int **subproblems; subproblems = generate_subproblems(my_best_path, current_size, num_of_cities); const int num_subproblems = num_of_cities - current_size; // the number of possible subs remaining // Now loop over all of the subproblems for (int i = 0; i < num_subproblems; i++) { // calculate the sub path cost for path at i const int sub_path_cost = calculate_tour_distance(subproblems[i], current_size, city_dist, num_of_cities); if (sub_path_cost > my_best) continue; // if it exceeds the cost continue // otherwise get the best path from my subproblem int *path; path = dfs(subproblems[i], num_of_cities, city_dist, current_size + 1, my_best); // if the best of my subproblem is better than local best int tempCost = calculate_full_tour_distance(path, city_dist, num_of_cities); if (tempCost < my_best && valid_path(path, num_of_cities)) { memcpy(my_best_path, path, (unsigned long) num_of_cities * sizeof(int)); // copy it into best path my_best = tempCost; } free(path); } free(subproblems[0]); free(subproblems); } return my_best_path; }
static int stormfs_mkdir(const char *path, mode_t mode) { int result; struct stat st; DEBUG("mkdir: %s\n", path); if((result = valid_path(path)) != 0) return result; cache_invalidate_dir(path); st.st_mode = mode; st.st_uid = getuid(); st.st_gid = getgid(); st.st_ctime = time(NULL); st.st_mtime = time(NULL); return proxy_mkdir(path, &st); }
void assign_reachability(maze_t *maze) { int i, j, start; for(start=0; start<(maze->col_count); start++) { if (maze->maze[0][start] == PATH) { maze->maze[0][start] = CORR_PATH; j = start; i = 1; while ((i < maze->row_count) && (i >= 0) && (j <= maze->col_count) && (j >= 0) && (!is_deadend(maze, i, j))) { maze->maze[i][j] = CORR_PATH; valid_path(maze, &i, &j); } if ((i == (maze->row_count-1)) && (maze->maze[i][j] = CORR_PATH)) { maze->hassoln = 1; } } } for(i=0; i<(maze->row_count); i++) { for(j=0; j<(maze->col_count); j++) { if (maze->maze[i][j] == PATH) { if (maze->maze[i-1][j] == CORR_PATH){ maze->maze[i][j] = CORR_PATH; } else if (maze->maze[i+1][j] == CORR_PATH){ maze->maze[i][j] = CORR_PATH; } else if (maze->maze[i][j-1] == CORR_PATH){ maze->maze[i][j] = CORR_PATH; } else if (maze->maze[i][j+1] == CORR_PATH){ maze->maze[i][j] = CORR_PATH; } else { maze->maze[i][j] = UNUSED; } } } } }
int stormfs_getattr(const char *path, struct stat *stbuf) { int result; struct file *f = NULL; DEBUG("getattr: %s\n", path); if((result = valid_path(path)) != 0) return result; if(strcmp(path, "/") == 0) { stbuf->st_mode = stormfs.root_mode | S_IFDIR; return 0; } f = cache_get(path); if(cache_valid(f) && f->st != NULL) { memcpy(stbuf, f->st, sizeof(struct stat)); return 0; } if((result = proxy_getattr(path, stbuf)) != 0) return result; stbuf->st_nlink = 1; if(S_ISREG(stbuf->st_mode)) stbuf->st_blocks = get_blocks(stbuf->st_size); pthread_mutex_lock(&f->lock); if(f->st == NULL) f->st = g_new0(struct stat, 1); memcpy(f->st, stbuf, sizeof(struct stat)); cache_touch(f); pthread_mutex_unlock(&f->lock); return 0; }
static int stormfs_mknod(const char *path, mode_t mode, dev_t rdev) { int result; int fd; struct file *f; struct stat st; DEBUG("mknod: %s\n", path); if((result = valid_path(path)) != 0) return result; cache_invalidate_dir(path); f = cache_get(path); fd = cache_mknod(f, mode, rdev); st.st_gid = getgid(); st.st_uid = getuid(); st.st_mode = mode; st.st_rdev = rdev; st.st_ctime = time(NULL); st.st_mtime = time(NULL); if((result = proxy_mknod(path, &st)) != 0) return result; pthread_mutex_lock(&f->lock); if(f->st == NULL) f->st = g_new0(struct stat, 1); memcpy(f->st, &st, sizeof(struct stat)); cache_touch(f); pthread_mutex_unlock(&f->lock); return result; }
static int stormfs_chown(const char *path, uid_t uid, gid_t gid) { int result = 0; struct file *f; struct stat st; DEBUG("chown: %s\n", path); if((result = valid_path(path)) != 0) return result; if((result = stormfs_getattr(path, &st)) != 0) return result; st.st_uid = uid; st.st_gid = gid; st.st_ctime = time(NULL); st.st_mtime = time(NULL); if((result = proxy_chown(path, &st)) != 0) return result; f = cache_get(path); if(cache_valid(f) && f->st != NULL) { pthread_mutex_lock(&f->lock); f->st->st_uid = uid; f->st->st_gid = gid; f->st->st_ctime = st.st_ctime; f->st->st_mtime = st.st_mtime; cache_touch(f); pthread_mutex_unlock(&f->lock); } return result; }
void arrow::update_symbols() { if (!valid_path(path_)) { WRN_ARR << "arrow::update_symbols called with invalid path\n"; return; } symbols_map_.clear(); invalidate_arrow_path(path_); std::string const mods = "~RC(FF00FF>"+ color_ + ")"; //magenta to current color std::string const dirname = "arrows/"; map_location::DIRECTION exit_dir = map_location::NDIRECTIONS; map_location::DIRECTION enter_dir = map_location::NDIRECTIONS; std::string prefix = ""; std::string suffix = ""; std::string image_filename = ""; arrow_path_t::const_iterator const arrow_start_hex = path_.begin(); arrow_path_t::const_iterator const arrow_pre_end_hex = path_.end() - 2; arrow_path_t::const_iterator const arrow_end_hex = path_.end() - 1; bool start = false; bool pre_end = false; bool end = false; bool teleport_out = false; bool teleport_in = false; arrow_path_t::iterator hex; for (hex = path_.begin(); hex != path_.end(); ++hex) { prefix = ""; suffix = ""; image_filename = ""; start = pre_end = end = false; // teleport in if we teleported out last hex teleport_in = teleport_out; teleport_out = false; // Determine some special cases if (hex == arrow_start_hex) start = true; if (hex == arrow_pre_end_hex) pre_end = true; else if (hex == arrow_end_hex) end = true; if (hex != arrow_end_hex && !tiles_adjacent(*hex, *(hex + 1))) teleport_out = true; // calculate enter and exit directions, if available enter_dir = map_location::NDIRECTIONS; if (!start && !teleport_in) { enter_dir = hex->get_relative_dir(*(hex-1)); } exit_dir = map_location::NDIRECTIONS; if (!end && !teleport_out) { exit_dir = hex->get_relative_dir(*(hex+1)); } // Now figure out the actual images if (teleport_out) { prefix = "teleport-out"; if (enter_dir != map_location::NDIRECTIONS) { suffix = map_location::write_direction(enter_dir); } } else if (teleport_in) { prefix = "teleport-in"; if (exit_dir != map_location::NDIRECTIONS) { suffix = map_location::write_direction(exit_dir); } } else if (start) { prefix = "start"; suffix = map_location::write_direction(exit_dir); if (pre_end) { suffix = suffix + "_ending"; } } else if (end) { prefix = "end"; suffix = map_location::write_direction(enter_dir); } else { std::string enter, exit; enter = map_location::write_direction(enter_dir); exit = map_location::write_direction(exit_dir); if (pre_end) { exit = exit + "_ending"; } assert(abs(enter_dir - exit_dir) > 1); //impossible turn? if (enter_dir < exit_dir) { prefix = enter; suffix = exit; } else //(enter_dir > exit_dir) { prefix = exit; suffix = enter; } } image_filename = dirname + style_ + "/" + prefix; if (suffix != "") { image_filename += ("-" + suffix); } image_filename += ".png"; assert(image_filename != ""); image::locator image = image::locator(image_filename, mods); if (!image.file_exists()) { ERR_ARR << "Image " << image_filename << " not found.\n"; image = image::locator(game_config::images::missing); } symbols_map_[*hex] = image; } }
static int stormfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { int result; struct file *dir; GList *files = NULL, *head = NULL, *next = NULL; DEBUG("readdir: %s\n", path); if((result = valid_path(path)) != 0) return result; filler(buf, ".", 0, 0); filler(buf, "..", 0, 0); dir = cache_get(path); if(cache_valid(dir) && dir->dir != NULL) { pthread_mutex_lock(&dir->lock); head = g_list_first(dir->dir); while(head != NULL) { next = head->next; struct file *f = head->data; filler(buf, (char *) f->name, f->st, 0); head = next; } pthread_mutex_unlock(&dir->lock); return 0; } if((result = proxy_readdir(path, &files)) != 0) return result; result = proxy_getattr_multi(path, files); pthread_mutex_lock(&dir->lock); head = g_list_first(files); while(head != NULL) { next = head->next; // FIXME: list_bucket is using the same structure (file) as // the cache which makes the code below confusing. struct file *file = head->data; char *fullpath = get_path(path, file->name); struct file *f = cache_get(fullpath); free(fullpath); pthread_mutex_lock(&f->lock); if(f->st == NULL) f->st = g_new0(struct stat, 1); memcpy(f->st, file->st, sizeof(struct stat)); f->st->st_nlink = 1; cache_touch(f); pthread_mutex_unlock(&f->lock); filler(buf, (char *) f->name, f->st, 0); dir->dir = g_list_append(dir->dir, f); head = next; } pthread_mutex_unlock(&dir->lock); free_files(files); return result; }
static int stormfs_readlink(const char *path, char *buf, size_t size) { int fd; FILE *fp = NULL; int result; struct stat st; struct file *f; DEBUG("readlink: %s\n", path); if((result = valid_path(path)) != 0) return result; if(size <= 0) return 0; --size; // save the null byte f = cache_get(path); if(cache_file_valid(f)) { char *cp = cache_path(f); fp = fopen(cp, "a+"); free(cp); if(fp == NULL) return -errno; if((fd = fileno(fp)) == -1) return -errno; } else { // file not available in cache, download it. if((fd = cache_create_file(f)) == -1) return -EIO; if((fp = fdopen(fd, "a+")) == NULL) return -errno; if((result = proxy_open(path, fp)) != 0) { fclose(fp); return result; } } if(fstat(fd, &st) != 0) { close(fd); return -errno; } if(st.st_size < (off_t) size) size = st.st_size; if(pread(fd, buf, size, 0) == -1) { close(fd); return -errno; } buf[size] = 0; if(close(fd) != 0) return -errno; return 0; }
static int check_valid_cookie_attribute(request_rec *r, const char *value) { char *pstat; char *pair; char *first_pair; char *domain_pair; char *path_pair; char *expire_pair; char *secure_pair; char *p; DBG(r, "start check_valid_cookie_attribute() value:[%s]", value); domain_pair = path_pair = expire_pair = secure_pair = NULL; p = apr_pstrdup(r->pool, value); /* pass first pair */ first_pair = apr_strtok(p, ";", &pstat); for (;;) { pair = apr_strtok(NULL, ";", &pstat); if (! pair) break; pair = qs_trim_string(r->pool, pair); if (STRNCASEEQ('d','D',"domain", pair, sizeof("domain")-1)) { domain_pair = apr_pstrdup(r->pool, pair); } else if (STRNCASEEQ('p','P',"path", pair, sizeof("path")-1)) { path_pair = apr_pstrdup(r->pool, pair); } else if (STRNCASEEQ('e','E',"expires", pair, sizeof("expires")-1)) { expire_pair = apr_pstrdup(r->pool, pair); } else if (STRNCASEEQ('s','S',"secure", pair, sizeof("secure")-1)) { secure_pair = apr_pstrdup(r->pool, pair); } } if (domain_pair) { if (!valid_domain(r, domain_pair)) { DBG(r, "invalid domain. domain_pair:[%s]", domain_pair); return CHXJ_FALSE; } } if (path_pair) { if (!valid_path(r, path_pair)) { DBG(r, "invalid path. path_pair:[%s]", path_pair); return CHXJ_FALSE; } } if (expire_pair) { if (!valid_expires(r, expire_pair)) { DBG(r, "invalid expire. expire_pair:[%s]", expire_pair); return CHXJ_FALSE; } } if (secure_pair) { if (!valid_secure(r, secure_pair)) { DBG(r, "invalid secure. secure_pair:[%s]", secure_pair); return CHXJ_FALSE; } } DBG(r, "end check_valid_cookie_attribute() value:[%s]", value); return CHXJ_TRUE; }