/** char* upload_pick(void* data) If applicable, brings up a file chooser in which the user selects a file to upload for a particular task. If the file is valid for the given action, returns the string to the full path filename, else returns NULL. Data is the load filter for the type of file as defined in LLFilePicker. **/ const char* upload_pick(void* data) { if( gAgent.cameraMouselook() ) { gAgent.changeCameraToDefault(); // This doesn't seem necessary. JC // display(); } LLFilePicker::ELoadFilter type; if(data) { type = (LLFilePicker::ELoadFilter)((intptr_t)data); } else { type = LLFilePicker::FFLOAD_ALL; } LLFilePicker& picker = LLFilePicker::instance(); if (!picker.getOpenFile(type)) { llinfos << "Couldn't import objects from file" << llendl; return NULL; } const char* filename = picker.getFirstFile(); const char* ext = strrchr(filename, '.'); //strincmp doesn't like NULL pointers if (ext == NULL) { const char* short_name = strrchr(filename, *gDirUtilp->getDirDelimiter().c_str()); // No extension LLStringBase<char>::format_map_t args; args["[FILE]"] = LLString(short_name + 1); gViewerWindow->alertXml("NoFileExtension", args); return NULL; } else { //so there is an extension //loop over the valid extensions and compare to see //if the extension is valid //now grab the set of valid file extensions const char* valids = build_extensions_string(type); std::string valid_extensions = std::string(valids); BOOL ext_valid = FALSE; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); tokenizer tokens(valid_extensions, sep); tokenizer::iterator token_iter; //now loop over all valid file extensions //and compare them to the extension of the file //to be uploaded for( token_iter = tokens.begin(); token_iter != tokens.end() && ext_valid != TRUE; ++token_iter) { const char* cur_token = token_iter->c_str(); if (0 == strnicmp(cur_token, ext, strlen(cur_token)) || /* Flawfinder: ignore */ 0 == strnicmp(cur_token, "*.*", strlen(cur_token))) /* Flawfinder: ignore */ { //valid extension //or the acceptable extension is any ext_valid = TRUE; } }//end for (loop over all tokens) if (ext_valid == FALSE) { //should only get here if the extension exists //but is invalid LLStringBase<char>::format_map_t args; args["[EXTENSION]"] = ext; args["[VALIDS]"] = valids; gViewerWindow->alertXml("InvalidFileExtension", args); return NULL; } }//end else (non-null extension) //valid file extension //now we check to see //if the file is actually a valid image/sound/etc. if (type == LLFilePicker::FFLOAD_WAV) { // pre-qualify wavs to make sure the format is acceptable char error_msg[MAX_STRING]; /* Flawfinder: ignore */ if (check_for_invalid_wav_formats(filename,error_msg)) { llinfos << error_msg << ": " << filename << llendl; LLStringBase<char>::format_map_t args; args["[FILE]"] = filename; gViewerWindow->alertXml( error_msg, args ); return NULL; } }//end if a wave/sound file return filename; }
/** char* upload_pick(void* data) If applicable, brings up a file chooser in which the user selects a file to upload for a particular task. If the file is valid for the given action, returns the string to the full path filename, else returns NULL. Data is the load filter for the type of file as defined in LLFilePicker. **/ const std::string upload_pick(void* data) { if( gAgent.cameraMouselook() ) { gAgent.changeCameraToDefault(); // This doesn't seem necessary. JC // display(); } LLFilePicker::ELoadFilter type; if(data) { type = (LLFilePicker::ELoadFilter)((intptr_t)data); } else { type = LLFilePicker::FFLOAD_ALL; } LLFilePicker& picker = LLFilePicker::instance(); if (!picker.getOpenFile(type)) { llinfos << "Couldn't import objects from file" << llendl; return std::string(); } const std::string& filename = picker.getFirstFile(); std::string ext = gDirUtilp->getExtension(filename); //strincmp doesn't like NULL pointers if (ext.empty()) { std::string short_name = gDirUtilp->getBaseFileName(filename); // No extension LLSD args; args["FILE"] = short_name; LLNotifications::instance().add("NoFileExtension", args); return std::string(); } else { //so there is an extension //loop over the valid extensions and compare to see //if the extension is valid //now grab the set of valid file extensions std::string valid_extensions = build_extensions_string(type); BOOL ext_valid = FALSE; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); tokenizer tokens(valid_extensions, sep); tokenizer::iterator token_iter; //now loop over all valid file extensions //and compare them to the extension of the file //to be uploaded for( token_iter = tokens.begin(); token_iter != tokens.end() && ext_valid != TRUE; ++token_iter) { const std::string& cur_token = *token_iter; if (cur_token == ext || cur_token == "*.*") { //valid extension //or the acceptable extension is any ext_valid = TRUE; } }//end for (loop over all tokens) if (ext_valid == FALSE) { //should only get here if the extension exists //but is invalid LLSD args; args["EXTENSION"] = ext; args["VALIDS"] = valid_extensions; LLNotifications::instance().add("InvalidFileExtension", args); return NULL; } }//end else (non-null extension) //valid file extension //now we check to see //if the file is actually a valid image/sound/etc. if (type == LLFilePicker::FFLOAD_WAV) { // pre-qualify wavs to make sure the format is acceptable std::string error_msg; if (check_for_invalid_wav_formats(filename,error_msg)) { llinfos << error_msg << ": " << filename << llendl; LLSD args; args["FILE"] = filename; LLNotifications::instance().add( error_msg, args ); return std::string(); } }//end if a wave/sound file return filename; }
bool AIFileUpload::is_valid(std::string const& filename, ELoadFilter type) { std::string ext = gDirUtilp->getExtension(filename); //strincmp doesn't like NULL pointers if (ext.empty()) { std::string short_name = gDirUtilp->getBaseFileName(filename); // No extension LLSD args; args["FILE"] = short_name; LLNotificationsUtil::add("NoFileExtension", args); return false; } else { //so there is an extension //loop over the valid extensions and compare to see //if the extension is valid //now grab the set of valid file extensions std::string valid_extensions = build_extensions_string(type); BOOL ext_valid = FALSE; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" "); tokenizer tokens(valid_extensions, sep); tokenizer::iterator token_iter; //now loop over all valid file extensions //and compare them to the extension of the file //to be uploaded for( token_iter = tokens.begin(); token_iter != tokens.end() && ext_valid != TRUE; ++token_iter) { const std::string& cur_token = *token_iter; if (cur_token == ext || cur_token == "*.*") { //valid extension //or the acceptable extension is any ext_valid = TRUE; } }//end for (loop over all tokens) if (ext_valid == FALSE) { //should only get here if the extension exists //but is invalid LLSD args; args["EXTENSION"] = ext; args["VALIDS"] = valid_extensions; LLNotificationsUtil::add("InvalidFileExtension", args); return false; } }//end else (non-null extension) //valid file extension //now we check to see //if the file is actually a valid image/sound/etc. //Consider completely disabling this, see how SL handles it. Maybe we can get full song uploads again! -HgB if (type == FFLOAD_WAV) { // pre-qualify wavs to make sure the format is acceptable std::string error_msg; if (check_for_invalid_wav_formats(filename,error_msg)) { llinfos << error_msg << ": " << filename << llendl; LLSD args; args["FILE"] = filename; LLNotifications::instance().add( error_msg, args ); return false; } }//end if a wave/sound file return true; }