MtpObjectHandle MtpStorage::beginSendObject(const char* path, MtpObjectFormat format, MtpObjectHandle parent, uint64_t size, time_t modified) { MTPD("MtpStorage::beginSendObject(), path: '%s', parent: %u, format: %04x\n", path, parent, format); iter it = mtpmap.find(parent); if (it == mtpmap.end()) { MTPE("parent node not found, returning error\n"); return kInvalidObjectHandle; } Tree* tree = it->second; std::string pathstr(path); size_t slashpos = pathstr.find_last_of('/'); if (slashpos == std::string::npos) { MTPE("path has no slash, returning error\n"); return kInvalidObjectHandle; } std::string parentdir = pathstr.substr(0, slashpos); std::string basename = pathstr.substr(slashpos + 1); if (parent != 0 && parentdir != getNodePath(tree)) { MTPE("beginSendObject into path '%s' but parent tree has path '%s', returning error\n", parentdir.c_str(), getNodePath(tree).c_str()); return kInvalidObjectHandle; } MTPD("MtpStorage::beginSendObject() parentdir: %s basename: %s\n", parentdir.c_str(), basename.c_str()); // note: for directories, the mkdir call is done later in MtpServer, here we just reserve a handle bool isDir = format == MTP_FORMAT_ASSOCIATION; Node* node = addNewNode(isDir, tree, basename); handleCurrentlySending = node->Mtpid(); // suppress inotify for this node while sending return node->Mtpid(); }
static std::string get_exe_location() { HMODULE hModule = GetModuleHandleW(NULL); WCHAR path[MAX_PATH]; GetModuleFileNameW(hModule, path, MAX_PATH); std::wstring pathstr(path); return std::string(pathstr.begin(), pathstr.end()); }
QoreHashNode* qore_httpclient_priv::sendMessageAndGetResponse(const char* meth, const char* mpath, const QoreHashNode& nh, const void* data, unsigned size, const ResolvedCallReferenceNode* send_callback, QoreHashNode* info, bool with_connect, int timeout_ms, int& code, bool& aborted, ExceptionSink* xsink) { QoreString pathstr(msock->socket->getEncoding()); const char* msgpath = with_connect ? mpath : getMsgPath(mpath, pathstr); if (!connected) { if (persistent) { xsink->raiseException("PERSISTENCE-ERROR", "the current connection has been temporarily marked as persistent, but has been disconnected"); return 0; } if (connect_unlocked(xsink)) { // if we have an info hash then write the request-uri key for reporting/logging purposes if (info) info->setKeyValue("request-uri", new QoreStringNodeMaker("%s %s HTTP/%s", meth, msgpath && msgpath[0] ? msgpath : "/", http11 ? "1.1" : "1.0"), 0); return 0; } } // send the message int rc = msock->socket->priv->sendHttpMessage(xsink, info, meth, msgpath, http11 ? "1.1" : "1.0", &nh, data, size, send_callback, QORE_SOURCE_HTTPCLIENT, timeout_ms, &msock->m, &aborted); //sendHTTPMessage(xsink, info, meth, msgpath, http11 ? "1.1" : "1.0", &nh, data, size, QORE_SOURCE_HTTPCLIENT, timeout_ms); if (rc) { assert(*xsink); if (rc == QSE_NOT_OPEN) disconnect_unlocked(); return 0; } QoreHashNode* ah = 0; while (true) { ReferenceHolder<QoreHashNode> ans(msock->socket->readHTTPHeader(xsink, info, timeout, QORE_SOURCE_HTTPCLIENT), xsink); if (!(*ans)) { disconnect_unlocked(); assert(*xsink); return 0; } // check HTTP status code AbstractQoreNode* v = ans->getKeyValue("status_code"); if (!v) { xsink->raiseException("HTTP-CLIENT-RECEIVE-ERROR", "no HTTP status code received in response"); return 0; } code = v->getAsInt(); // continue processing if "100 Continue" response received (ignore this response) if (code == 100) continue; ah = ans.release(); break; } return ah; }
// Push all pathnames of the subdirectories in slist and push them // onto the recursion stack. void push_subdir (slist_ref slist, char *path) { stack_slistdir (slist); for (;;) { if (has_empty_dirstack (slist)) break; DEBUGF ('f',""); char *ename = pop_slistdir (slist); char buffer[MAX_BUFFER_SIZE]; pathstr (buffer, path, ename); push_stack (stack, buffer); } }
// Insert a directory entry if it is not a hidden file. void insert (slist_ref slist, char *path, char *ename) { char buffer[MAX_BUFFER_SIZE]; pathstr (buffer, path, ename); struct stat fs; int stat_rc = stat (buffer, &fs); if (stat_rc >= 0) { slist_node node = new_slistnode (&fs, ename); if (! is_hidden (node)) insert_slist (slist, node); else free_slistnode (node); }else { print_error (ename, strerror (errno)); } }
status_t TrashFile(BEntry *src) { // Move a file to the Trash. If the name exists, rename the entry before moving if(!src) return B_ERROR; status_t status; BPath path; BEntry dest; BString pathstr("/boot/home/Desktop/Trash/"); BDirectory dir(pathstr.String()); char newname[B_FILE_NAME_LENGTH]; src->GetName(newname); pathstr+=newname; dest.SetTo(pathstr.String()); GetValidName(&dest); dest.GetPath(&path); BPath srcpath; src->GetPath(&srcpath); BNode node(srcpath.Path()); if(node.InitCheck()==B_OK) { node.WriteAttr("_trk/original_path",B_STRING_TYPE,0, srcpath.Path(),strlen(srcpath.Path())+1); } status=src->MoveTo(&dir,path.Path(),false); if(status==B_CROSS_DEVICE_LINK) { BPath srcpath; src->GetPath(&srcpath); BString command("mv "),srcstring(srcpath.Path()),deststring(path.Path()); srcstring.CharacterEscape(" ",'\\'); deststring.CharacterEscape(" ",'\\'); command+=srcstring; command+=" "; command+=deststring; system(command.String()); } return status; }
void bLSM::init_stasis(const char *path) { dataPage::register_stasis_page_impl(); // stasis_buffer_manager_hint_writes_are_sequential = 1; std::string pathstr(path); if (pathstr.length() != 0) { if (pathstr[pathstr.length()-1] != '/') pathstr += "/"; } bLSM::log_path = pathstr; std::string storefilepath = pathstr+"storefile.txt"; char *ssfn = (char*)malloc(sizeof(char)*storefilepath.size()); strcpy(ssfn, storefilepath.c_str()); stasis_store_file_name = ssfn; //printf("Store file: %s \n", stasis_store_file_name); stasis_log_factory = bLSM::stasis_log_path_factory; printf("Ignoring path: %s \n", path); Tinit(); }
void MailingList::CheckInFolder() { //always called in the context of a MailWorker //manually check through in dir to see if there are any emails BDirectory indir(fListInDirectoryPath.c_str()); if (indir.InitCheck()!=B_OK) { LogError("ERROR: Could not do manual scan of in folder ("+fListInDirectoryPath+") as there was an error reading the folder (BDirectory InitCheck() failed)"); fApp->LogError("ERROR: List ("+fListName+") could not do manual scan of in folder ("+fListInDirectoryPath+") as there was an error reading the folder (BDirectory InitCheck() failed)"); } entry_ref eref; BEntry filebentry; while(indir.GetNextEntry(&filebentry) == B_NO_ERROR) { BMessage msg(ORG_SIMPLE_MAILMISTRESS_PROCESSFILE); BPath filebpath; filebentry.GetPath(&filebpath); std::string pathstr(filebpath.Path()); msg.AddString("FilePathStr",pathstr.c_str()); ((MailMistressApplication*) be_app)->PostMessage(&msg); } }
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load) { UINT32 open_plan[4]; int i; bool softload = FALSE; m_from_swlist = FALSE; // if the path contains no period, we are using softlists, so we won't create an image astring pathstr(path); bool filename_has_period = (pathstr.rchr(0, '.') != -1) ? TRUE : FALSE; /* first unload the image */ unload(); /* clear any possible error messages */ clear_error(); /* we are now loading */ m_is_loading = TRUE; /* record the filename */ m_err = set_image_filename(path); if (m_err) goto done; /* Check if there's a software list defined for this device and use that if we're not creating an image */ if (!filename_has_period && !just_load) { softload = load_software_part( device().machine().options(), this, path, &m_software_info_ptr, &m_software_part_ptr, &m_full_software_name, &m_software_list_name ); // if we had launched from softlist with a specified part, e.g. "shortname:part" // we would have recorded the wrong name, so record it again based on software_info if (m_software_info_ptr && m_full_software_name) m_err = set_image_filename(m_full_software_name); m_from_swlist = TRUE; } if (is_create || filename_has_period) { /* determine open plan */ determine_open_plan(is_create, open_plan); /* attempt to open the file in various ways */ for (i = 0; !m_file && open_plan[i]; i++) { /* open the file */ m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } /* Copy some image information when we have been loaded through a software list */ if ( m_software_info_ptr ) { m_longname = m_software_info_ptr->longname; m_manufacturer = m_software_info_ptr->publisher; m_year = m_software_info_ptr->year; //m_playable = m_software_info_ptr->supported; } /* did we fail to find the file? */ if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } /* call device load or create */ m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } /* success! */ done: if (just_load) { if(m_err) clear(); return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); else mame_printf_error("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if (device().machine().time() > attotime::zero && is_reset_on_load()) device().machine().schedule_hard_reset(); else { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else mame_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, util::option_resolution *create_args, bool just_load) { UINT32 open_plan[4]; int i; bool softload = FALSE; m_from_swlist = FALSE; // if the path contains no period, we are using softlists, so we won't create an image std::string pathstr(path); bool filename_has_period = (pathstr.find_last_of('.') != -1) ? TRUE : FALSE; // first unload the image unload(); // clear any possible error messages clear_error(); // we are now loading m_is_loading = TRUE; // record the filename m_err = set_image_filename(path); if (m_err) goto done; if (core_opens_image_file()) { // Check if there's a software list defined for this device and use that if we're not creating an image if (!filename_has_period && !just_load) { softload = load_software_part(path, m_software_part_ptr); if (softload) { m_software_info_ptr = &m_software_part_ptr->info(); m_software_list_name.assign(m_software_info_ptr->list().list_name()); m_full_software_name.assign(m_software_part_ptr->info().shortname()); // if we had launched from softlist with a specified part, e.g. "shortname:part" // we would have recorded the wrong name, so record it again based on software_info if (m_software_info_ptr && !m_full_software_name.empty()) m_err = set_image_filename(m_full_software_name.c_str()); // check if image should be read-only const char *read_only = get_feature("read_only"); if (read_only && !strcmp(read_only, "true")) { make_readonly(); } m_from_swlist = TRUE; } } if (is_create || filename_has_period) { // determine open plan determine_open_plan(is_create, open_plan); // attempt to open the file in various ways for (i = 0; !m_file && open_plan[i]; i++) { // open the file m_err = load_image_by_path(open_plan[i], path); if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) goto done; } } // Copy some image information when we have been loaded through a software list if ( m_software_info_ptr ) { // sanitize if (m_software_info_ptr->longname().empty() || m_software_info_ptr->publisher().empty() || m_software_info_ptr->year().empty()) fatalerror("Each entry in an XML list must have all of the following fields: description, publisher, year!\n"); // store m_longname = m_software_info_ptr->longname(); m_manufacturer = m_software_info_ptr->publisher(); m_year = m_software_info_ptr->year(); //m_playable = m_software_info_ptr->supported(); } // did we fail to find the file? if (!is_loaded() && !softload) { m_err = IMAGE_ERROR_FILENOTFOUND; goto done; } } // call device load or create m_create_format = create_format; m_create_args = create_args; if (m_init_phase==FALSE) { m_err = (image_error_t)finish_load(); if (m_err) goto done; } // success! done: if (just_load) { if(m_err) clear(); return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; } if (m_err!=0) { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Error: Unable to %s image '%s': %s", is_create ? "create" : "load", path, error()); else osd_printf_error("Error: Unable to %s image '%s': %s\n", is_create ? "create" : "load", path, error()); } clear(); } else { /* do we need to reset the CPU? only schedule it if load/create is successful */ if (device().machine().time() > attotime::zero && is_reset_on_load()) device().machine().schedule_hard_reset(); else { if (!m_init_phase) { if (device().machine().phase() == MACHINE_PHASE_RUNNING) device().popmessage("Image '%s' was successfully %s.", path, is_create ? "created" : "loaded"); else osd_printf_info("Image '%s' was successfully %s.\n", path, is_create ? "created" : "loaded"); } } } return m_err ? IMAGE_INIT_FAIL : IMAGE_INIT_PASS; }
// returns a list of directory names in the given directory, *without* the source dir. // if getting the dir list recursively, all paths are added, except *again* the top source dir beeing queried. void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */) { #if !_WIN32 DIR * dirp; struct dirent * dp; dirp = opendir(path); if(dirp) { std::string pathstr(path); MakeSlashTerminated(pathstr); while((dp = readdir(dirp))) // assignment is intentional { if (_IsDir(path, dp)) // only add if it is a directory { if(strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { dirs.push_back(dp->d_name); if (recursive) // needing a better way to do that { std::string d = dp->d_name; std::string subdir = pathstr + d; MakeSlashTerminated(d); StringList newdirs; GetDirList(subdir.c_str(), newdirs, true); for(std::deque<std::string>::iterator it = newdirs.begin(); it != newdirs.end(); ++it) dirs.push_back(d + *it); } } } } closedir(dirp); } #else std::string pathstr(path); MakeSlashTerminated(pathstr); WIN32_FIND_DATA fil; HANDLE hFil = FindFirstFile((pathstr + '*').c_str(),&fil); if(hFil != INVALID_HANDLE_VALUE) { do { if( fil.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { if (!strcmp(fil.cFileName, ".") || !strcmp(fil.cFileName, "..")) continue; dirs.push_back(fil.cFileName); if (recursive) // need a better way to do that { std::string d = fil.cFileName; std::string subdir = pathstr + d; MakeSlashTerminated(d); StringList newdirs; GetDirList(subdir.c_str(), newdirs, true); for(std::deque<std::string>::iterator it = newdirs.begin(); it != newdirs.end(); ++it) dirs.push_back(d + *it); } } } while(FindNextFile(hFil, &fil)); FindClose(hFil); } #endif }
// static LLURI LLURI::buildHTTP(const std::string& prefix, const LLSD& path) { LLURI result; // TODO: deal with '/' '?' '#' in host_port if (prefix.find("://") != prefix.npos) { // it is a prefix result = LLURI(prefix); } else { // it is just a host and optional port result.mScheme = "http"; result.mEscapedAuthority = escapeHostAndPort(prefix); } if (path.isArray()) { // break out and escape each path component for (LLSD::array_const_iterator it = path.beginArray(); it != path.endArray(); ++it) { LL_DEBUGS() << "PATH: inserting " << it->asString() << LL_ENDL; result.mEscapedPath += "/" + escapePathComponent(it->asString()); } } else if (path.isString()) { std::string pathstr(path); // Trailing slash is significant in HTTP land. If caller specified, // make a point of preserving. std::string last_slash; std::string::size_type len(pathstr.length()); if (len && pathstr[len-1] == '/') { last_slash = "/"; } // Escape every individual path component, recombining with slashes. for (boost::split_iterator<std::string::const_iterator> ti(pathstr, boost::first_finder("/")), tend; ti != tend; ++ti) { // Eliminate a leading slash or duplicate slashes anywhere. (Extra // slashes show up here as empty components.) This test also // eliminates a trailing slash, hence last_slash above. if (! ti->empty()) { result.mEscapedPath += "/" + escapePathComponent(std::string(ti->begin(), ti->end())); } } // Reinstate trailing slash, if any. result.mEscapedPath += last_slash; } else if(path.isUndefined()) { // do nothing } else { LL_WARNS() << "Valid path arguments to buildHTTP are array, string, or undef, you passed type" << path.type() << LL_ENDL; } result.mEscapedOpaque = "//" + result.mEscapedAuthority + result.mEscapedPath; return result; }