int enc_file(const char* path){ const char* tmp_name; const char* new_path = rewritepath(path); FILE *enc_fp, *dec_fp; if(getencattr(new_path) != 0) return 1; /* Open decrypted copy */ dec_fp = fopen(new_path, "r"); /* Make encrypted copy at tmp_name */ tmp_name = tmp_path(new_path); enc_fp = fopen(tmp_name, "w"); do_crypt(dec_fp, enc_fp, 1, xmp_data->xmp_key); /* Close both copies */ fclose(dec_fp); fclose(enc_fp); /* Remove the decrypted copy */ remove(new_path); /* Rename encrypted copy to original name */ rename(tmp_name, new_path); fprintf(stderr, "Enc! New: %s Tmp: %s\n", new_path, tmp_name); /* Set the encryption attr */ setencattr(new_path, 1); free((void*)new_path); free((void*)tmp_name); return 0; }
static int xmp_getattr(const char *path, struct stat *stbuf) { int res; time_t atime, mtime, ctime; mode_t mode; const char* new_path = rewritepath(path); const char* tmp_name; res = lstat(new_path, stbuf); if (res == -1) return -errno; if(S_ISREG(stbuf->st_mode)){ atime = stbuf->st_atime; mtime = stbuf->st_mtime; ctime = stbuf->st_ctime; mode = stbuf->st_mode; tmp_name = tmp_path(new_path); res = lstat(tmp_name, stbuf); if(res == -1){ return -errno; } stbuf->st_atime = atime; stbuf->st_mtime = mtime; stbuf->st_ctime = ctime; stbuf->st_mode = mode; remove(tmp_name); free((void*) new_path); free((void*) tmp_name); } return 0; }
int ProtoBufFile::save(const google::protobuf::Message* message, bool sync) { std::string tmp_path(_path); tmp_path.append(".tmp"); butil::File::Error e; FileAdaptor* file = _fs->open(tmp_path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, NULL, &e); if (!file) { LOG(WARNING) << "open file failed, path: " << _path << ": " << butil::File::ErrorToString(e); return -1; } std::unique_ptr<FileAdaptor, DestroyObj<FileAdaptor> > guard(file); // serialize msg butil::IOBuf header_buf; butil::IOBuf msg_buf; butil::IOBufAsZeroCopyOutputStream msg_wrapper(&msg_buf); message->SerializeToZeroCopyStream(&msg_wrapper); // write len int32_t header_len = butil::HostToNet32(msg_buf.length()); header_buf.append(&header_len, sizeof(int32_t)); if (sizeof(int32_t) != file->write(header_buf, 0)) { LOG(WARNING) << "write len failed, path: " << tmp_path; return -1; } ssize_t len = msg_buf.size(); if (len != file->write(msg_buf, sizeof(int32_t))) { LOG(WARNING) << "write failed, path: " << tmp_path; return -1; } // sync if (sync) { if (!file->sync()) { LOG(WARNING) << "sync failed, path: " << tmp_path; return -1; } } // rename if (!_fs->rename(tmp_path, _path)) { LOG(WARNING) << "rename failed, old: " << tmp_path << " , new: " << _path; return -1; } return 0; }
void ScavTaskColorShirt::callback_human_detection(const PointCloud::ConstPtr& msg) { int color_cnt = 0; switch (color) { case RED: baseline = Rgb(255.0, 0.0, 0.0); break; case BLUE: baseline = Rgb(0.0, 0.0, 255.0); break; case GREEN: baseline = Rgb(0.0, 255.0, 0.0); break; case YELLOW: baseline = Rgb(255.0, 255.0, 0.0); break; case ORANGE: baseline = Rgb(191.0, 87.0, 0.0); break; } BOOST_FOREACH (const pcl::PointXYZRGB& pt, msg->points) { // here we assume the waist height is 90cm, and neck height is 160cm; // the robot sensor's height is 60cm if (pt.y > SHIRT_HEIGHT_BOTTOM and pt.y < SHIRT_HEIGHT_TOP and this->getColorDistance( &pt, &baseline) < DISTANCE_TO_COLOR) { color_cnt++; } } float ratio = (float) color_cnt / (float) msg->points.size(); ROS_INFO("ratio is %f", ratio); if (ratio > COLOR_RATIO && ros::ok()) { ROS_INFO_STREAM("person wearing" << color << "shirt detected"); boost::posix_time::ptime curr_time = boost::posix_time::second_clock::local_time(); std::string time_str = boost::posix_time::to_simple_string(curr_time); cv_bridge::CvImageConstPtr cv_ptr = cv_bridge::toCvShare(image, sensor_msgs::image_encodings::BGR8); if (false == boost::filesystem::is_directory(directory)) { boost::filesystem::path tmp_path(directory); boost::filesystem::create_directory(tmp_path); } path_to_image = directory + "color_shirt_" + time_str; cv::imwrite(path_to_image, cv_ptr->image); } }
/* * Does the store contain this path? */ bool store_contains(const char * path, bool check_tmp) { char* storePath = prefix_path(storeLocation, path); char* tmpPath = tmp_path(path); struct stat st; if(lstat(storePath, &st) == 0) { return true; } else if(check_tmp && lstat(tmpPath, &st) == 0) { return true; } else { return false; } }
int SMTPFileSystem::getattr(const char *path, struct stat *buf) { memset(buf, 0, sizeof(struct stat)); struct fuse_context *fc = fuse_get_context(); buf->st_uid = fc->uid; buf->st_gid = fc->gid; if (path == std::string("/")) { buf->st_mode = S_IFDIR | 0775; buf->st_nlink = 2; return 0; } else { std::string tmp_path(smtpfs_dirname(path)); std::string tmp_file(smtpfs_basename(path)); const TypeDir *content = m_device.dirFetchContent(tmp_path); if (!content) { return -ENOENT; } if (content->dir(tmp_file)) { const TypeDir *dir = content->dir(tmp_file); buf->st_ino = dir->id(); buf->st_mode = S_IFDIR | 0775; buf->st_nlink = 2; buf->st_mtime = dir->modificationDate(); } else if (content->file(tmp_file)) { const TypeFile *file = content->file(tmp_file); buf->st_ino = file->id(); buf->st_size = file->size(); buf->st_blocks = (file->size() / 512) + (file->size() % 512 > 0 ? 1 : 0); buf->st_nlink = 1; buf->st_mode = S_IFREG | 0644; buf->st_mtime = file->modificationDate(); buf->st_ctime = buf->st_mtime; buf->st_atime = buf->st_mtime; } else { return -ENOENT; } } return 0; }
// //////////////////////////////////////////////////////////////////////////// void LogHandlerFileBase::OpenFile(const char *base_name, const char *dir_name, const MLB::Utility::TimeT &start_time) { std::string file_name; if ((base_name == NULL) || (!(*base_name))) file_name = "LogFile."; else { file_name = base_name; if (base_name[strlen(base_name) - 1] != '.') file_name += '.'; } std::string tmp_date_time(start_time.ToString()); tmp_date_time[10] = '.'; tmp_date_time[13] = '.'; tmp_date_time[16] = '.'; file_name += tmp_date_time + "." + GetHostNameCanonical() + "." + AnyToString(CurrentProcessId()) + ".log"; boost::filesystem::path tmp_file(file_name, boost::filesystem::native); if ((dir_name != NULL) && *dir_name) { std::string tmp_dir_name; ResolveFilePathGeneral(dir_name, tmp_dir_name, "", true, true, false); boost::filesystem::path tmp_path(tmp_dir_name, boost::filesystem::native); boost::filesystem::path this_file; this_file = tmp_path / tmp_file; file_name = this_file.native_file_string(); } else { if (!tmp_file.has_root_path()) tmp_file = boost::filesystem::system_complete(tmp_file); file_name = tmp_file.native_file_string(); } OpenFile(file_name); }
void ScavTaskWhiteBoard::callback_human_detected(const geometry_msgs::PoseStamped::ConstPtr& msg) { Pose a1 = Pose(-30.88, 0.06); Pose b1 = Pose(-29.48, 0.06); Pose c1 = Pose(-30.89, -3.16); Pose a2 = Pose(-8.25, -5.99); Pose b2 = Pose(-6.83, -6.05); Pose c2 = Pose(-8.21, -11.26); Pose pose = Pose(msg->pose.position.x, msg->pose.position.y); if (inRectangle(pose, a1, b1, c1) or inRectangle(pose, a2, b2, c2)) { ROS_INFO("People detected near a white board, saving picture..."); cv_bridge::CvImageConstPtr cv_ptr; cv_ptr = cv_bridge::toCvShare(wb_image, sensor_msgs::image_encodings::BGR8); boost::posix_time::ptime curr_time = boost::posix_time::second_clock::local_time(); // std::string time_str = boost::posix_time::to_simple_string(curr_time); std::string time_str = boost::posix_time::to_iso_extended_string(curr_time); if (false == boost::filesystem::is_directory(directory)) { boost::filesystem::path tmp_path(directory); boost::filesystem::create_directory(tmp_path); } wb_path_to_image = directory + "white_board_" + time_str + ".PNG"; cv::imwrite(wb_path_to_image, cv_ptr->image); search_planner->setTargetDetection(true); // change status to terminate the motion thread ROS_INFO_STREAM("Finished saving picture: " << wb_path_to_image); task_completed = true; } }
static int xmp_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { int fd; int res; const char* new_path = rewritepath(path); const char* tmp_name = tmp_path(new_path); (void) fi; dec_file_copy(path, tmp_name); fd = open(tmp_name, O_RDONLY); if (fd == -1) return -errno; res = pread(fd, buf, size, offset); if (res == -1) res = -errno; close(fd); remove(tmp_name); free((void*)new_path); free((void*)tmp_name); return res; }
String Get(Key key) { switch(key) { case FILE_EXE: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC // Executable path can have relative references ("..") depending on // how the app was launched. uint32_t executable_length = 0; _NSGetExecutablePath(NULL, &executable_length); std::string executable_path(executable_length, '\0'); char* executable_path_c = (char*)executable_path.c_str(); int rv = _NSGetExecutablePath(executable_path_c, &executable_length); assert(rv == 0); if ((rv != 0) || (executable_path.empty())) return ""; // _NSGetExecutablePath will return whatever gets execed, so if // the command line is ./foo, you'll get the '.'. We use the // aggressive mode here to handle '..' parts that could interfere // with finding other paths that start from FILE_EXE. return canonicalize(executable_path, true); #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX // boost::filesystem can't chase symlinks, do it manually const char* selfExe = "/proc/self/exe"; char bin_dir[MAX_PATH + 1]; int bin_dir_size = readlink(selfExe, bin_dir, MAX_PATH); if (bin_dir_size < 0 || bin_dir_size > MAX_PATH) { SILOG(core,fatal,"Couldn't read self symlink to setup dynamic loading paths."); return ""; } bin_dir[bin_dir_size] = 0; return String(bin_dir, bin_dir_size); #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS char system_buffer[MAX_PATH]; system_buffer[0] = 0; GetModuleFileName(NULL, system_buffer, MAX_PATH); return String(system_buffer); #else return ""; #endif } break; case DIR_EXE: { String exe_file = Get(FILE_EXE); if (exe_file.empty()) return ""; boost::filesystem::path exe_file_path(exe_file); return exe_file_path.parent_path().string(); } break; case DIR_EXE_BUNDLE: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX // Windows and Linux don't have bundles return Get(DIR_EXE); #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC // On mac we need to detect that we're in a .app. We assume this // only applies if the binaries are in the standard location, // i.e. foo.app/Contents/MacOS/bar_binary String exe_dir = Get(DIR_EXE); boost::filesystem::path exe_dir_path(exe_dir); // Work our way back up verifying the path names, finally // returning if we actually find the .app. if (exe_dir_path.has_filename() && exe_dir_path.filename() == "MacOS") { exe_dir_path = exe_dir_path.parent_path(); if (exe_dir_path.has_filename() && exe_dir_path.filename() == "Contents") { exe_dir_path = exe_dir_path.parent_path(); if (exe_dir_path.has_filename()) { String app_dir_name = exe_dir_path.filename(); if (app_dir_name.substr(app_dir_name.size()-4, 4) == ".app") return exe_dir_path.parent_path().string(); } } } // Otherwise dump the original return exe_dir; #endif } break; case DIR_CURRENT: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX char system_buffer[MAX_PATH] = ""; if (!getcwd(system_buffer, sizeof(system_buffer))) { return ""; } return String(system_buffer); #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS char system_buffer[MAX_PATH]; system_buffer[0] = 0; DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); if (len == 0 || len > MAX_PATH) return ""; return String(system_buffer); #else return "."; #endif } break; case DIR_USER: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC uid_t uid = getuid(); passwd* pw = getpwuid(uid); if (pw != NULL && pw->pw_dir != NULL) { boost::filesystem::path homedir(pw->pw_dir); if (boost::filesystem::exists(homedir) && boost::filesystem::is_directory(homedir)) return homedir.string(); } #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS char system_buffer[MAX_PATH]; system_buffer[0] = 0; if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, system_buffer))) return ""; std::string appdata_str(system_buffer); boost::filesystem::path user_appdata(appdata_str); user_appdata /= "Sirikata"; if (!boost::filesystem::exists(user_appdata)) boost::filesystem::create_directory(user_appdata); if (boost::filesystem::exists(user_appdata) && boost::filesystem::is_directory(user_appdata)) return user_appdata.string(); #endif // Last resort (and default for unknown platform) is to try to use // the current directory return "."; } break; case DIR_USER_HIDDEN: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS // On windows there's no difference from the user-specific data directory since that's already hidden. return Get(DIR_USER); #else // We just compute this as an offset from the user directory boost::filesystem::path user_dir(Get(DIR_USER)); user_dir /= ".sirikata"; if (!boost::filesystem::exists(user_dir)) boost::filesystem::create_directory(user_dir); if (boost::filesystem::exists(user_dir) && boost::filesystem::is_directory(user_dir)) return user_dir.string(); #endif return "."; } case DIR_TEMP: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC // On Mac and Linux we try to work under tmp using our own directory boost::filesystem::path tmp_path("/tmp"); if (boost::filesystem::exists(tmp_path) && boost::filesystem::is_directory(tmp_path)) { tmp_path /= "sirikata"; // If it doesn't exist, try creating it if (!boost::filesystem::exists(tmp_path)) boost::filesystem::create_directory(tmp_path); if (boost::filesystem::exists(tmp_path) && boost::filesystem::is_directory(tmp_path)) return tmp_path.string(); } #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS // Windows doesn't seem to suggest a good location for this, so we // put it under the app data directory in its own temp directory boost::filesystem::path sirikata_temp_dir = boost::filesystem::path(Get(DIR_USER_HIDDEN)) / "temp"; if (!boost::filesystem::exists(sirikata_temp_dir)) boost::filesystem::create_directory(sirikata_temp_dir); if (boost::filesystem::exists(sirikata_temp_dir) && boost::filesystem::is_directory(sirikata_temp_dir)) return sirikata_temp_dir.string(); #endif // Last resort (and default for unknown platform) is to try to use // the current directory return "."; } break; case DIR_SYSTEM_CONFIG: { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC // This is sirikata specific, so we're looking for more // than just /etc. if (boost::filesystem::exists("/etc") && boost::filesystem::is_directory("/etc") && boost::filesystem::exists("/etc/sirikata") && boost::filesystem::is_directory("/etc/sirikata")) return "/etc/sirikata"; return ""; #else // Other platforms don't have an equivalent? return ""; #endif } break; case RESOURCE: { SILOG(core,fatal,"Can't request RESOURCE without specifiying an in-tree path and path to resource."); assert(key != RESOURCE); return ""; } break; default: return ""; } }
bool init_getpic(const char* rt_path) { //using namespace xsetpic; if(!rt_path || 0==&vShmKey) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid parameter !"); return false; } if(!AutoMove(boost::filesystem::exists(AutoMove(boost::filesystem::path(rt_path))))) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid runtime path,not exists !"); return false; } else { if(!AutoMove(boost::filesystem::is_directory(AutoMove(boost::filesystem::path(rt_path))))) { std::fprintf(stderr, "****init_getpic error :%s\n","invalid runtime path,is not a directory !"); return false; } } boost::filesystem::path tmp_path(rt_path); boost::filesystem::path tmp_path2(boost::filesystem::system_complete(tmp_path));; //std::string str_strart_up_dir(strart_up_dir.string()); boost::filesystem::path _rt_path(tmp_path2); char vir_dir_sub[256]; std::memset(vir_dir_sub,0x00,sizeof(vir_dir_sub)); std::sprintf(vir_dir_sub,"%s/%s",_rt_path.string().c_str(),"map"); vir_dir_sub[sizeof(vir_dir_sub)-1]='\0'; boost::filesystem::path dir_map(std::string(vir_dir_sub).c_str()); if(!boost::filesystem::exists(dir_map)) { boost::filesystem::create_directories(dir_map); } else { if(!boost::filesystem::is_directory(dir_map)) { boost::filesystem::remove(dir_map); boost::filesystem::create_directories(dir_map); } } std::list<boost::filesystem::path> list_shm_lua_file_path; list_shm_lua_file_path.clear(); int32_t n_max_shared_memory_count(16); vShmKey.clear(); vShmKey.reserve(16); while(n_max_shared_memory_count>0) { char _sz_file_path[256]; std::memset(_sz_file_path,0x00,sizeof(_sz_file_path)); std::sprintf(_sz_file_path,"%s/%d.lua",dir_map.string().c_str(),n_max_shared_memory_count-1); const boost::filesystem::path shminfo_path(std::string(_sz_file_path).c_str()); lable_recheck_shminfo_file_flag: if(boost::filesystem::exists(shminfo_path)) { if(!boost::filesystem::is_directory(shminfo_path)) { //bool b_over_write(false); uint32_t set_pic_base(_SETPIC_IPC_FLAG_); key_t real_key(ftok(shminfo_path.string().c_str(),set_pic_base)); lua_script shm_info_script(shminfo_path.string().c_str()); std::string _shm_file_path("."); //key_t shm_info_id(0); long shm_info_id(0); shm_info_script.get<std::string>("path",&_shm_file_path); shm_info_script.get<long>("id",&shm_info_id); if(0!=std::strcmp(_shm_file_path.c_str(),shminfo_path.string().c_str()) || real_key!=shm_info_id) { std::fstream _file_shm_info(shminfo_path.c_str(),std::ios::out); if(_file_shm_info) { try { std::string _shm_info_open_app( "#!/usr/bin/env lua\n"); _file_shm_info<<_shm_info_open_app<<std::endl; std::string _shm_info_open_tip( "--[[\n\n" " ATTENTION : THIS FILE IS AUTO CREATED BY CAMERA SERVICE SETPIC V3 ,USING FOR SHARED MEMORY.\n" "DO NOT CHANGE OR MOVE IT . ANY CHANGED IN THIS FILE MAY MAKE SHARED MEMORY NOT WORK .\n\n" " wangbin <*****@*****.**>\n" "]]--\n"); _file_shm_info<<_shm_info_open_tip<<std::endl; _file_shm_info<<"path =\""<<shminfo_path.string()<<"\""<<std::endl; _file_shm_info<<"id ="<<real_key; char _shm_info_delete_function[512]; std::memset(_shm_info_delete_function,0x00,sizeof(_shm_info_delete_function)); std::sprintf(_shm_info_delete_function,"\n\n--delete command: ipcrm -m shmid \n" "function delete_this_shared_memory(...)\n" " io.write(tostring(_VERSION) .. tostring(\"\\t\") .. tostring(os.date()) .. tostring(\"\\n\"))\n" " if os.getenv [[USER]] ~= tostring(\"root\") then\n" " io.write(tostring(\"For Better Execute,Suggest You Login As \\\"root\\\"\\n\"))\n" " end\n" " os.execute(\"ipcrm -m %ld\")\n" "end\n" ,real_key); _shm_info_delete_function[sizeof(_shm_info_delete_function)-1]='\0'; _file_shm_info<<std::string(_shm_info_delete_function)<<std::endl; } catch(std::exception& e) { std::fprintf(stderr, "%s\n",e.what()); } _file_shm_info.close(); } } else { vShmKey.push_back(real_key); --n_max_shared_memory_count; } } else // exist ,but is dir { boost::filesystem::remove_all(shminfo_path);//recursive delete dir std::fstream _file_shm_info(shminfo_path.string().c_str(),std::ios::out); if(_file_shm_info) { _file_shm_info.close(); } goto lable_recheck_shminfo_file_flag; } } else //not exists { std::fstream _file_shm_info(shminfo_path.string().c_str(),std::ios::out); if(_file_shm_info) { _file_shm_info.close(); } goto lable_recheck_shminfo_file_flag; } } std::reverse(vShmKey.begin(),vShmKey.end()); for(std::vector<long>::const_iterator _iter(vShmKey.begin());_iter!=vShmKey.end();++_iter) { std::fprintf(stderr, "%ld\n",*_iter); } return true; }
/* This function gets certain characteristics of a file like size and stores them in a struct called stat */ static int enc_getattr(const char *path, struct stat *stbuf) { int res; int crypt_action = PASS_THROUGH; ssize_t valsize = 0; char *tmpval = NULL; time_t atime; /* time of last access */ time_t mtime; /* time of last modification */ time_t tctime; /* time of last status change */ dev_t t_dev; /* ID of device containing file */ ino_t t_ino; /* inode number */ mode_t mode; /* protection */ nlink_t t_nlink; /* number of hard links */ uid_t t_uid; /* user ID of owner */ gid_t t_gid; /* group ID of owner */ dev_t t_rdev; /* device ID (if special file) */ char fpath[PATH_MAX]; enc_fullpath(fpath, path); res = lstat(fpath, stbuf); if (res == -1){ return -errno; } /* is it a regular file? */ if (S_ISREG(stbuf->st_mode)){ /* These file characteristics don't change after decryption so just storing them */ atime = stbuf->st_atime; mtime = stbuf->st_mtime; tctime = stbuf->st_ctime; t_dev = stbuf->st_dev; t_ino = stbuf->st_ino; mode = stbuf->st_mode; t_nlink = stbuf->st_nlink; t_uid = stbuf->st_uid; t_gid = stbuf->st_gid; t_rdev = stbuf->st_rdev; /* Get size of flag value and value itself */ valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, NULL, 0); tmpval = malloc(sizeof(*tmpval)*(valsize)); valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, tmpval, valsize); //fprintf(stderr, "Xattr Value: %s\nXattr size: %zu\n", tmpval, sizeof(*tmpval)*(valsize)); fprintf(stderr, "Xattr Value: %s\n", tmpval); /* If the specified attribute doesn't exist or it's set to false */ if (valsize < 0 || memcmp(tmpval, "false", 5) == 0){ if(errno == ENOATTR){ fprintf(stderr, "No %s attribute set\n", XATRR_ENCRYPTED_FLAG); } //fprintf(stderr, "file is unencrypted, leaving crypt_action as pass-through\n valsize is %zu\n", valsize); fprintf(stderr, "file is unencrypted, leaving crypt_action as pass-through\n"); } /* If the attribute exists and is true then we need to get size of decrypted file */ else if (memcmp(tmpval, "true", 4) == 0){ //fprintf(stderr, "file is encrypted, need to decrypt\nvalsize is %zu\n", valsize); fprintf(stderr, "file is encrypted, need to decrypt\n"); crypt_action = DECRYPT; } const char *tmpPath = tmp_path(fpath, SUFFIXGETATTR); FILE *tmpFile = fopen(tmpPath, "wb+"); FILE *f = fopen(fpath, "rb"); fprintf(stderr, "fpath: %s\ntmpPath: %s\n", fpath, tmpPath); if(!do_crypt(f, tmpFile, crypt_action, ENC_DATA->password)){ fprintf(stderr, "getattr do_crypt failed\n"); } fclose(f); fclose(tmpFile); /* Get size of decrypted file and store in stat struct */ res = lstat(tmpPath, stbuf); if (res == -1){ return -errno; } /* Put info about file we did not want to change back into stat struct*/ stbuf->st_atime = atime; stbuf->st_mtime = mtime; stbuf->st_ctime = tctime; stbuf->st_dev = t_dev; stbuf->st_ino = t_ino; stbuf->st_mode = mode; stbuf->st_nlink = t_nlink; stbuf->st_uid = t_uid; stbuf->st_gid = t_gid; stbuf->st_rdev = t_rdev; free(tmpval); remove(tmpPath); } return 0; }
/* Write contents to encrypted or unencrypted file * Echo was used to write to files. See bottom of README, IMPORTANT NOTES. */ static int enc_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { (void) fi; (void) offset; int res; int fd; int crypt_action = PASS_THROUGH; ssize_t valsize = 0; char *tmpval = NULL; char fpath[PATH_MAX]; enc_fullpath(fpath, path); valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, NULL, 0); tmpval = malloc(sizeof(*tmpval)*(valsize)); valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, tmpval, valsize); fprintf(stderr, " WRITE: Xattr Value: %s\n", tmpval); if (valsize < 0 || memcmp(tmpval, "false", 5) == 0){ if(errno == ENOATTR){ fprintf(stderr, "WRITE: No %s attribute set\n", XATRR_ENCRYPTED_FLAG); } fprintf(stderr, "WRITE: file is unencrypted, leaving crypt_action as pass-through\n"); }/* If the attribute exists and is true then we need to get size of decrypted file */ else if (memcmp(tmpval, "true", 4) == 0){ fprintf(stderr, "WRITE: file is encrypted, need to decrypt\n"); crypt_action = DECRYPT; } fprintf(stderr, "crypt_action is set to %d\n", crypt_action); /* If the file to be written to is encrypted */ if (crypt_action == DECRYPT){ fprintf(stderr, "WRITE: File to be written is encrypted\n"); FILE *f = fopen(fpath, "rb+"); const char *tmpPath = tmp_path(fpath, SUFFIXWRITE); FILE *tmpFile = fopen(tmpPath, "wb+"); fprintf(stderr, "path of original file %s\n", fpath); fseek(f, 0, SEEK_END); size_t original = ftell(f); fseek(f, 0, SEEK_SET); fprintf(stderr, "Size of original file %zu\n", original); fprintf(stderr, "Decrypting contents of original file to tmpFile for writing\n"); if(!do_crypt(f, tmpFile, DECRYPT, ENC_DATA->password)){ fprintf(stderr, "WRITE: do_crypt failed\n"); } fseek(f, 0, SEEK_SET); size_t tmpFilelen = ftell(tmpFile); fprintf(stderr, "Size to be written to tmpFile %zu\n", size); fprintf(stderr, "size of tmpFile %zu\n", tmpFilelen); fprintf(stderr, "Writing to tmpFile\n"); res = fwrite(buf, 1, size, tmpFile); if (res == -1) res = -errno; tmpFilelen = ftell(tmpFile); fprintf(stderr, "Size of tmpFile after write %zu\n", tmpFilelen); fseek(tmpFile, 0, SEEK_SET); fprintf(stderr, "Encrypting new contents of tmpFile into original file\n"); if(!do_crypt(tmpFile, f, ENCRYPT, ENC_DATA->password)){ fprintf(stderr, "WRITE: do_crypt failed\n"); } fclose(f); fclose(tmpFile); remove(tmpPath); }/* If the file to be written to is unencrypted */ else if (crypt_action == PASS_THROUGH){ fprintf(stderr, "File to be written is unencrypted"); fd = open(fpath, O_WRONLY); if (fd == -1) return -errno; res = pwrite(fd, buf, size, offset); if (res == -1) res = -errno; close(fd); } free(tmpval); return res; }
/* This function reads file contents into application window */ static int enc_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { (void)fi; int res; int crypt_action = PASS_THROUGH; ssize_t valsize = 0; char *tmpval = NULL; char fpath[PATH_MAX]; enc_fullpath(fpath, path); valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, NULL, 0); tmpval = malloc(sizeof(*tmpval)*(valsize)); valsize = getxattr(fpath, XATRR_ENCRYPTED_FLAG, tmpval, valsize); fprintf(stderr, " Read: Xattr Value: %s\n", tmpval); /* If the specified attribute doesn't exist or it's set to false */ if (valsize < 0 || memcmp(tmpval, "false", 5) == 0){ if(errno == ENOATTR){ fprintf(stderr, "Read: No %s attribute set\n", XATRR_ENCRYPTED_FLAG); } fprintf(stderr, "Read: file is unencrypted, leaving crypt_action as pass-through\n"); }/* If the attribute exists and is true then we need to get size of decrypted file */ else if (memcmp(tmpval, "true", 4) == 0){ fprintf(stderr, "Read: file is encrypted, need to decrypt\n"); crypt_action = DECRYPT; } const char *tmpPath = tmp_path(fpath, SUFFIXREAD); FILE *tmpFile = fopen(tmpPath, "wb+"); FILE *f = fopen(fpath, "rb"); fprintf(stderr, "Read: fpath: %s\ntmpPath: %s\n", fpath, tmpPath); if(!do_crypt(f, tmpFile, crypt_action, ENC_DATA->password)){ fprintf(stderr, "Read: do_crypt failed\n"); } fseek(tmpFile, 0, SEEK_END); size_t tmpFilelen = ftell(tmpFile); fseek(tmpFile, 0, SEEK_SET); fprintf(stderr, "Read: size given by read: %zu\nsize of tmpFile: %zu\nsize of offset: %zu\n", size, tmpFilelen, offset); /* Read the decrypted contents of original file to the application widow */ res = fread(buf, 1, tmpFilelen, tmpFile); if (res == -1) res = -errno; fclose(f); fclose(tmpFile); remove(tmpPath); free(tmpval); return res; }
Py::Object pysvn_client::cmd_diff_peg( const Py::Tuple &a_args, const Py::Dict &a_kws ) { static argument_description args_desc[] = { { true, name_tmp_path }, { true, name_url_or_path }, { false, name_peg_revision }, { false, name_revision_start }, { false, name_revision_end }, { false, name_recurse }, { false, name_ignore_ancestry }, { false, name_diff_deleted }, #if defined( PYSVN_HAS_CLIENT_DIFF_PEG2 ) { false, name_ignore_content_type }, #endif #if defined( PYSVN_HAS_CLIENT_DIFF_PEG3 ) { false, name_header_encoding }, { false, name_diff_options }, #endif #if defined( PYSVN_HAS_CLIENT_DIFF_PEG4 ) { false, name_depth }, { false, name_relative_to_dir }, { false, name_changelists }, #endif { false, NULL } }; FunctionArguments args( "diff_peg", args_desc, a_args, a_kws ); args.check(); std::string tmp_path( args.getUtf8String( name_tmp_path ) ); std::string path( args.getUtf8String( name_url_or_path ) ); svn_opt_revision_t revision_start = args.getRevision( name_revision_start, svn_opt_revision_base ); svn_opt_revision_t revision_end = args.getRevision( name_revision_end, svn_opt_revision_working ); svn_opt_revision_t peg_revision = args.getRevision( name_peg_revision, revision_end ); SvnPool pool( m_context ); #if defined( PYSVN_HAS_CLIENT_DIFF_PEG4 ) svn_depth_t depth = args.getDepth( name_depth, name_recurse, svn_depth_infinity, svn_depth_infinity, svn_depth_files ); std::string std_relative_to_dir; const char *relative_to_dir = NULL; if( args.hasArg( name_relative_to_dir ) ) { std_relative_to_dir = args.getBytes( name_relative_to_dir ); relative_to_dir = std_relative_to_dir.c_str(); } apr_array_header_t *changelists = NULL; if( args.hasArg( name_changelists ) ) { changelists = arrayOfStringsFromListOfStrings( args.getArg( name_changelists ), pool ); } #else bool recurse = args.getBoolean( name_recurse, true ); #endif bool ignore_ancestry = args.getBoolean( name_ignore_ancestry, true ); bool diff_deleted = args.getBoolean( name_diff_deleted, true ); #if defined( PYSVN_HAS_CLIENT_DIFF_PEG2 ) bool ignore_content_type = args.getBoolean( name_ignore_content_type, false ); #endif #if defined( PYSVN_HAS_CLIENT_DIFF_PEG3 ) std::string header_encoding( args.getUtf8String( name_header_encoding, empty_string ) ); const char *header_encoding_ptr = APR_LOCALE_CHARSET; if( !header_encoding.empty() ) header_encoding_ptr = header_encoding.c_str(); apr_array_header_t *options = NULL; if( args.hasArg( name_diff_options ) ) { options = arrayOfStringsFromListOfStrings( args.getArg( name_diff_options ), pool ); } else { options = apr_array_make( pool, 0, sizeof( const char * ) ); } #else apr_array_header_t *options = apr_array_make( pool, 0, sizeof( const char * ) ); #endif bool is_url = is_svn_url( path ); revisionKindCompatibleCheck( is_url, peg_revision, name_peg_revision, name_url_or_path ); revisionKindCompatibleCheck( is_url, revision_start, name_revision_start, name_url_or_path ); revisionKindCompatibleCheck( is_url, revision_end, name_revision_end, name_url_or_path ); svn_stringbuf_t *stringbuf = NULL; try { std::string norm_tmp_path( svnNormalisedIfPath( tmp_path, pool ) ); std::string norm_path( svnNormalisedIfPath( path, pool ) ); checkThreadPermission(); PythonAllowThreads permission( m_context ); pysvn_apr_file output_file( pool ); pysvn_apr_file error_file( pool ); output_file.open_unique_file( norm_tmp_path ); error_file.open_unique_file( norm_tmp_path ); // std::cout << "peg_revision " << peg_revision.kind << " " << peg_revision.value.number << std::endl; // std::cout << "revision_start " << revision_start.kind << " " << revision_start.value.number << std::endl; // std::cout << "revision_end " << revision_end.kind << " " << revision_end.value.number << std::endl; #if defined( PYSVN_HAS_CLIENT_DIFF_PEG4 ) svn_error_t *error = svn_client_diff_peg4 ( options, norm_path.c_str(), &peg_revision, &revision_start, &revision_end, relative_to_dir, depth, ignore_ancestry, !diff_deleted, ignore_content_type, header_encoding_ptr, output_file.file(), error_file.file(), changelists, m_context, pool ); #elif defined( PYSVN_HAS_CLIENT_DIFF_PEG3 ) svn_error_t *error = svn_client_diff_peg3 ( options, norm_path.c_str(), &peg_revision, &revision_start, &revision_end, recurse, ignore_ancestry, !diff_deleted, ignore_content_type, header_encoding_ptr, output_file.file(), error_file.file(), m_context, pool ); #elif defined( PYSVN_HAS_CLIENT_DIFF_PEG2 ) svn_error_t *error = svn_client_diff_peg2 ( options, norm_path.c_str(), &peg_revision, &revision_start, &revision_end, recurse, ignore_ancestry, !diff_deleted, ignore_content_type, output_file.file(), error_file.file(), m_context, pool ); #else svn_error_t *error = svn_client_diff_peg ( options, norm_path.c_str(), &peg_revision, &revision_start, &revision_end, recurse, ignore_ancestry, !diff_deleted, output_file.file(), error_file.file(), m_context, pool ); #endif permission.allowThisThread(); if( error != NULL ) throw SvnException( error ); output_file.close(); output_file.open_tmp_file(); error = svn_stringbuf_from_aprfile( &stringbuf, output_file.file(), pool ); if( error != NULL ) throw SvnException( error ); } catch( SvnException &e ) { // use callback error over ClientException m_context.checkForError( m_module.client_error ); throw_client_error( e ); } // cannot convert to Unicode as we have no idea of the encoding of the bytes return Py::String( stringbuf->data, (int)stringbuf->len ); }
int main (int argc, char **argv) { if (!(pcl::console::find_argument (argc, argv, "-f") > 0)) { std::cerr << "no input cloud specified" << std::endl; usage (argc, argv); return EXIT_FAILURE; } std::string hole_file_name; pcl::console::parse_argument (argc, argv, "-f", hole_file_name); fs::path tmp_path (hole_file_name); if (!fs::is_regular_file (tmp_path)) { std::cerr << "Specified input file '" << tmp_path.string () << "' "; if (!fs::exists (tmp_path)) { std::cerr << "does not exist."; } else { std::cerr << "apparently is not a regular file but perhaps" << " a directory."; } std::cerr << " Exiting." << std::endl; return EXIT_FAILURE; } else { std::string extension_string = tmp_path.extension ().string (); boost::algorithm::to_lower (extension_string); if (extension_string.compare (".pcd") != 0) { std::cerr << "Specified input file '" << tmp_path.string () << "' is no .pcd file. Exiting" << std::endl; return EXIT_FAILURE; } } std::string cloud_frame = "/cam"; if (pcl::console::find_argument (argc, argv, "--frame") > 0) { std::string tmp_string; pcl::console::parse_argument (argc, argv, "--frame", tmp_string); if (tmp_string.substr (0,1).compare ("/") != 0) { ROS_WARN ("frame %s should start with '/'. Ignoring input and publishing in default-fram %s", tmp_string.c_str (), cloud_frame.c_str ()); } else { cloud_frame = tmp_string; } } ros::init (argc, argv, "hole_test_pub"); ros::NodeHandle n_handle; pub = n_handle.advertise<sensor_msgs::PointCloud2> ("/hole", 1); ros::Rate loop_rate (0.25); sensor_msgs::PointCloud2 pc2; // TODO: fill pc2 with content and set header frame id pcl::PCDReader reader; // read in a hole_cloud CloudPtr input (new Cloud); if (reader.read<PointType> (hole_file_name, *input) < 0) { ROS_ERROR ("Error reading specified pcd file '%s'.", hole_file_name.c_str ()); return EXIT_FAILURE; } ROS_INFO ("Succesfully read input pcd file containing %lu points", input->points.size ()); pcl::PCLPointCloud2 tmp_cloud; pcl::toPCLPointCloud2 (*input, tmp_cloud); pcl_conversions::fromPCL (tmp_cloud, pc2); pc2.header.frame_id = cloud_frame; while (ros::ok ()) { pc2.header.stamp = ros::Time::now (); pub.publish (pc2); ROS_INFO ("published hole cloud on topic /hole"); loop_rate.sleep (); ros::spinOnce (); } return EXIT_SUCCESS; }
int main (int argc, char **argv) { if (!(pcl::console::find_argument (argc, argv, "-f") > 0)) { std::cerr << "no input cloud specified" << std::endl; usage (argc, argv); return EXIT_FAILURE; } std::string hole_file_name; pcl::console::parse_argument (argc, argv, "-f", hole_file_name); fs::path tmp_path (hole_file_name); if (!fs::is_regular_file (tmp_path)) { std::cerr << "Specified input file '" << tmp_path.string () << "' "; if (!fs::exists (tmp_path)) { std::cerr << "does not exist."; } else { std::cerr << "apparently is not a regular file but perhaps" << " a directory."; } std::cerr << " Exiting." << std::endl; return EXIT_FAILURE; } else { std::string extension_string = tmp_path.extension ().string (); boost::algorithm::to_lower (extension_string); if (extension_string.compare (".pcd") != 0) { std::cerr << "Specified input file '" << tmp_path.string () << "' is no .pcd file. Exiting" << std::endl; return EXIT_FAILURE; } } ros::init (argc, argv, "label_cloud_test_pub"); ros::NodeHandle n_handle; pub = n_handle.advertise<LabelCloud> ("/fused_cloud", 1); ros::Rate loop_rate (0.25); pcl::PCDReader reader; // read in a hole_cloud LabelCloudPtr input (new LabelCloud); if (reader.read<LabelPoint> (hole_file_name, *input) < 0) { ROS_ERROR ("Error reading specified pcd file '%s'.", hole_file_name.c_str ()); return EXIT_FAILURE; } ROS_INFO ("Succesfully read input pcd file containing %lu points", input->points.size ()); std_msgs::Header header; header.frame_id = "/cam"; while (ros::ok ()) { header.stamp = ros::Time::now (); pcl_conversions::toPCL (header, input->header); pub.publish (input); ROS_INFO ("published fused cloud on topic /fused_cloud"); loop_rate.sleep (); ros::spinOnce (); } return EXIT_SUCCESS; }