Esempio n. 1
0
boost::filesystem::path executable_directory() {
#if defined __APPLE__
    char buffer[1024];
    unsigned int size = sizeof(buffer);
    if (_NSGetExecutablePath(buffer, &size) != 0)
        BOOST_THROW_EXCEPTION(file_not_found(executable_path_failure));

    return boost::filesystem::path(buffer).parent_path();

#elif defined __unix__
    char buffer[1024];

    // try via proc first
    ssize_t result = ::readlink(linux_proc.c_str(), buffer, sizeof(buffer) - 1);
    if (result < 0)
        result = ::readlink(freebsd_proc.c_str(), buffer, sizeof(buffer) - 1);

    if (result < 0)
        result = ::readlink(solaris_proc.c_str(), buffer, sizeof(buffer) - 1);

    if (result <= 0)
        BOOST_THROW_EXCEPTION(file_not_found(readlink_not_found));

    buffer[result] = '\0';
    return boost::filesystem::path(buffer).parent_path();

#elif defined _WIN32
    char buffer[MAX_PATH];
    ::GetModuleFileName(NULL, buffer, MAX_PATH);
    return boost::filesystem::path(buffer).parent_path();
#else
    BOOST_THROW_EXCEPTION(file_not_found(unsupported_operative_system));
#endif
}
void Registry::loadTrackerLibrary(const boost::filesystem::path &path) {
    typedef void (*RegisterFunction)();

    if (!boost::filesystem::exists(path)) {
        throw file_not_found("Could not find file " + path.string());
    }

    std::vector<std::string> parts;
    boost::split(parts, path.string(), boost::is_any_of("."));

    /* expect filename to be of form: name.tracker.ext */
    if (parts.size() < 3) {
        throw std::invalid_argument("Filename must obey pattern $name.tracker.$ext");
    }

    const std::string ext(parts[parts.size() - 1]);
    if (ext == "so" || ext == "dylib" || ext == "dll") {
        QLibrary trackerLibrary(QString::fromStdString(path.string()));
        auto registerFunction = static_cast<RegisterFunction>
                                (trackerLibrary.resolve("registerTracker"));

        if (!registerFunction) {
            throw invalid_tracker_lib_error(trackerLibrary.errorString().toStdString());
        }
        registerFunction();
    } else if (ext == "zmq") {
        registerZmqTracker(Zmq::ZmqInfoFile(path));
    } else {

    }
}
Esempio n. 3
0
std::shared_ptr<FIBITMAP> load_image(const std::wstring& filename)
{
	if(!boost::filesystem::exists(filename))
		BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename)));

	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	fif = FreeImage_GetFileTypeU(filename.c_str(), 0);
	if(fif == FIF_UNKNOWN) 
		fif = FreeImage_GetFIFFromFilenameU(filename.c_str());
		
	if(fif == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif)) 
		BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));
		
	auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_LoadU(fif, filename.c_str(), 0), FreeImage_Unload);
		  
	if(FreeImage_GetBPP(bitmap.get()) != 32)
	{
		bitmap = std::shared_ptr<FIBITMAP>(FreeImage_ConvertTo32Bits(bitmap.get()), FreeImage_Unload);
		if(!bitmap)
			BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));			
	}

	//PNG-images need to be premultiplied with their alpha
	if(fif == FIF_PNG)
	{
		image_view<bgra_pixel> original_view(FreeImage_GetBits(bitmap.get()), FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get()));
		premultiply(original_view);
	}
	
	return bitmap;
}
Esempio n. 4
0
static void run_tests()
{
    file_not_found();
    reject_duplicates();
    disable_eof_check();
    decode_any();
    load_wrong_args();
    position();
}
Esempio n. 5
0
violet::ConfigFile::ConfigFile(boost::filesystem::path filename, std::string delimiter,
		std::string comment, std::string sentry) :
	myDelimiter(delimiter), myComment(comment), mySentry(sentry) {
	// Construct a ConfigFile, getting keys and values from given file

	boost::filesystem::ifstream in(filename);

	if (!in)
		throw file_not_found(filename);

	in >> (*this);
}
Esempio n. 6
0
static void run_tests()
{
    file_not_found();
    very_long_file_name();
    reject_duplicates();
    disable_eof_check();
    decode_any();
    decode_int_as_real();
    allow_nul();
    load_wrong_args();
    position();
}
Esempio n. 7
0
int
jcf_open_exact_case (const char *filename, int oflag)
{
  int filename_len = strlen (filename);
  int found_file_len;
  HANDLE found_file_handle;
  WIN32_FIND_DATA fd;
  
  /* See if we can find this file. */
  found_file_handle = FindFirstFile (filename, &fd);
  if (found_file_handle == INVALID_HANDLE_VALUE)
    return file_not_found ();
  FindClose (found_file_handle);

  found_file_len = strlen (fd.cFileName);
  
  /* This should never happen. */
  if (found_file_len > filename_len)
    return file_not_found ();
  
  /* Here, we're only actually comparing the filename and not
     checking the case of any containing directory components.
     Although we're not fully obeying our contract, checking
     all directory components would be tedious and time-consuming
     and it's a pretty safe assumption that mixed-case package
     names are a fringe case.... */
  if (strcmp (filename + filename_len - found_file_len, fd.cFileName))
    {
      /* Reject this because it is not a perfect-case match. */
      /* printf("************\nRejected:\n%s\n%s\n************\n\n", filename, fd.cFileName); */
      return file_not_found ();
    }
  else
    {
      return open (filename, oflag);
    }
}
Esempio n. 8
0
safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const core::parameters& params)
{	
	auto producer = do_create_producer(my_frame_factory, params, g_factories);
	auto key_producer = frame_producer::empty();
	
	std::wstring resource_name = L"";
	auto tokens = parameters::protocol_split(params.at_original(0));
	if (tokens[0].empty())
	{
		resource_name = params.at_original(0);
	}

	if(!resource_name.empty()) {
	try // to find a key file.
	{
		auto params_copy = params;
		if(params_copy.size() > 0)
		{
			auto resource_name = params_copy.at_original(0);
			params_copy.set(0, resource_name + L"_A");
			key_producer = do_create_producer(my_frame_factory, params_copy, g_factories);			
			if(key_producer == frame_producer::empty())
			{
				params_copy.set(0, resource_name + L"_ALPHA");
				key_producer = do_create_producer(my_frame_factory, params_copy, g_factories);	
			}
		}
	}
	catch(...){}
	}

	if(producer != frame_producer::empty() && key_producer != frame_producer::empty())
		return create_separated_producer(producer, key_producer);
	
	if(producer == frame_producer::empty())
	{
		std::wstring str = params.get_original_string();
		BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(narrow(str)));
	}

	return producer;
}
Esempio n. 9
0
boost::filesystem::path data_files_directory() {
    const auto ed(executable_directory());

    // shouldn't really happen, but just in case.
    auto r = boost::filesystem::absolute(ed / in_current_dir);
    if (boost::filesystem::exists(r))
        return r;

    // build directory
    r = boost::filesystem::absolute(ed / in_dir_above);
    if (boost::filesystem::exists(r))
        return r;

    // Windows, OSX, linux opt install
    r = boost::filesystem::absolute(ed / in_share_data_dir);
    if (boost::filesystem::exists(r))
        return r;

    // linux distributor, versioned install
    r = boost::filesystem::absolute(ed / in_share_neurite_versioned_dir);
    if (boost::filesystem::exists(r))
        return r;

    // linux distributor, non-versioned install
    r = boost::filesystem::absolute(ed / in_share_neurite_dir);
    if (boost::filesystem::exists(r))
        return r;

    std::ostringstream s;
    s << "Could not find data directory. Base directory: " << ed.string()
      << ". Locations searched: "
      << in_current_dir.string() << " "
      << in_dir_above.string() << " "
      << in_share_data_dir.string() << " "
      << in_share_neurite_versioned_dir.string() << " "
      << in_share_neurite_dir.string() << " ";

    BOOST_THROW_EXCEPTION(file_not_found(s.str()));
}
Esempio n. 10
0
	string string_from_file(const char * fileName) {
		ifstream file;
		file.open(fileName);
		if (!file)
			throw file_not_found(fileName);
		// determine file size
		file.seekg(0,ios::end);
		auto length = file.tellg();
		if (length == 0)
			throw runtime_error_ex("The file ('%s') is empty", fileName);
		// read the whole file the result
		file.seekg(0,ios::beg);
		const size_t bufSize = (unsigned int) length + 1;
		string result;
		result.reserve(bufSize);
		char c;
		file.get(c);
		do {
			result += c;
			file.get(c);
		} while (file.good());
		return result;
	}
Esempio n. 11
0
safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)
{
	if(params.empty())
		BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));
	
	auto consumer = frame_consumer::empty();
	std::any_of(g_factories.begin(), g_factories.end(), [&](const consumer_factory_t& factory) -> bool
		{
			try
			{
				consumer = factory(params);
			}
			catch(...)
			{
				CASPAR_LOG_CURRENT_EXCEPTION();
			}
			return consumer != frame_consumer::empty();
		});

	if(consumer == frame_consumer::empty())
		BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));

	return consumer;
}
Esempio n. 12
0
int send_server_resp(int client_sockfd, HTTPMessage ** client_rqst_ptr, 
					char * buf, int size)
{
  /* Method Check; File Check */
  if(method_not_implem(client_sockfd, *client_rqst_ptr) || 
	 file_not_found(client_sockfd, *client_rqst_ptr)||
         version_not_sup(client_sockfd, *client_rqst_ptr))
    {
	  //dest_HTTPMessage(client_rqst);
	  free(*client_rqst_ptr);
	  client_rqst_ptr  = NULL;
	  *client_rqst_ptr = NULL;
	  return -1;
    }

  /* Request is OK */
  char good_resp_form[HTTP_MSG_SZ] = "HTTP/1.1 200 OK\n"           // Status Line
			             "Content-Type: %s\n"        // Header
			             "Content-Length: %ld\n"   // Header
			             "Content-Language: en-US\n\n"; 
			  //"%s";                       // Body
  char response_buffer[HTTP_MSG_SZ];
  memset(response_buffer, 0, HTTP_MSG_SZ);
  HTTPMessage * response = init_HTTPMessage(SERVER_RESP, response_buffer);
  long int filelen;

  /* Open up the File to Write */
  char content_type[5];
  memset(content_type, 0, 5);
  char * begin_ext = strchr((*(client_rqst_ptr))->msg_line_f2, '.');
    if(begin_ext == NULL)
    {
	strcpy(content_type, "text/html");
    }
    else
    {
	begin_ext += 1;
  if(strncmp(begin_ext, "jpg", 3) == 0 || strncmp(begin_ext, "jpe",3)==0)
  {
    strcpy(content_type, "image/jpeg");
  }
  else if(strncmp(begin_ext, "htm", 3) == 0)
  {
    strcpy(content_type, "text/html");
  }
  else if(strncmp(begin_ext, "gif", 3) == 0)
  {
    strcpy(content_type, "image/gif");
  }
    }

  FILE * file      = fopen((*(client_rqst_ptr))->msg_line_f2, "r");
  fseek(file,0L, SEEK_END);
  filelen = ftell(file);
  fseek(file,0L, SEEK_SET);

  snprintf(response->msg_buffer,HTTP_MSG_SZ, good_resp_form,content_type,filelen);

  int n = write(client_sockfd,response->msg_buffer,strlen(response->msg_buffer));
  if(n<0)
    error("ERROR WRITING TO CLIENT SOCKET");
  printf("***Server Response***\n%s", response->msg_buffer);

  char * file_buffer = (char *) malloc(filelen);
  fread(file_buffer, 1, filelen, file);
 
  n = write(client_sockfd, file_buffer, filelen);
  if(n<0)
    error("ERROR WRITING TO CLIENT SOCKET");
  printf("%s\n***End***\n--------------------\n\n", file_buffer);

  free(file_buffer);
  file_buffer = NULL;
  return 1;
}
Esempio n. 13
0
int cmd_more(char file[])
{

kol_struct70	k70;
kol_struct_BDVK	bdvk;
unsigned	result, filesize, pos, i;
char		buf[81]; //буфер
char		temp[256];
unsigned	flags;

if (strlen(file)<1)
	{
	#if LANG_ENG
		printf ("  more <filename>\n\r");
	#elif LANG_RUS
		printf ("  more <имя файла>\n\r");
	#endif
	return TRUE;
	}

if ( '/' == file[0])
	{
	strcpy(temp, file);

	if ( !file_check(temp) )
		{
		file_not_found(file);
		return FALSE;
		}
	}
else
	{
	strcpy(temp, cur_dir);
	if (temp[strlen(temp)-1] != '/') 
		strcat(temp, "/"); // add slash
	strcat(temp, file);
	
	if ( !file_check(temp) )
		{
		file_not_found(file);
		return FALSE;
		}
	}

k70.p00 = 5;
k70.p04 = k70.p08 = k70.p12 = 0;
k70.p16 = (unsigned) &bdvk;
k70.p20 = 0;
k70.p21 = temp;

result = kol_file_70(&k70); // получаем информацию о файле
if ( 0 != result ) 
	return FALSE;

filesize = bdvk.p32[0]; // получаем размер файла

buf[80]=0;
flags = con_get_flags();

for (pos=0;pos<filesize;pos+=80)
	{

	memset(buf, 0, 80);

	k70.p00 = 0;
	k70.p04 = pos;
	k70.p08 = 0;
	k70.p12 = 80;
	k70.p16 = (unsigned) buf;
	k70.p20 = 0;
	k70.p21 = temp;

	result = kol_file_70(&k70); // чтение 80 символов
	for (i=0; i<80; i++)
		{

		if (27 == buf[i])
			con_set_flags(flags|0x100);
		else con_set_flags(flags);

		printf ("%c", buf[i]);
		}
	if ( 0 != result ) 
		{
		con_set_flags(flags);
		printf ("\n\r");
		return TRUE;	
		}

	}
con_set_flags(flags);
printf ("\n\r");
return TRUE;
}
Esempio n. 14
0
void client_request(int clientsd, char * timec, char * clientip) 
{
	FILE * requestfile;
	FILE * logfile;
	char read_output[BUFFER_SIZE] = {0};
	char method[80];
	char dir[80];
	char http[80];
	char line[100];
	char finaldir[BUFFER_SIZE] = {0};
	struct stat buf;
	int httpint;
	int readint;
	int totalsize;
	char totalsizec[20];
	int totalwrite;
	char totalwritec[20];
	char okstr[80];

	logfile = fopen(logdir, "a");

	readint = read_request(clientsd, read_output);
	
	if (readint == -1)
	{
		internal_server_error(clientsd, timec);
		return;
	}

	getlinec(read_output, line);
	httpint = is_http_get(line, method, dir, http);
	
	if (httpint == -1)
	{
		bad_request(clientsd, timec);
		write_log(timec, line, "400 Bad Request", logfile, clientip);
		return;
	}
	
	getdir(docdir, dir, finaldir);

	requestfile = fopen(finaldir, "r");
	
	if (requestfile == NULL)
	{
		file_not_found(clientsd, timec);
		write_log(timec, line, "404 Not Found", logfile, clientip);
		return;
	}

	if (errno = EACCES)
	{
		forbidden(clientsd, timec);
		write_log(timec, line, "403 Forbidden", logfile, clientip);
		return;
	}
	/*
	 * Gets file size from buffer file to be used as total write size
	 * for ok response
	 *
	 * Code adapted from
	 * http://stackoverflow.com/a/238644
	 */
	fstat(requestfile, &buf);
	totalsize = buf.st_size;
	/*
	 * Converts int to char
	 *
	 * Code adapted from
	 * http://stackoverflow.com/a/1114752
	 */
	sprintf(totalsizec, "%d", totalsize);
	totalwrite = ok(clientsd, timec, requestfile, totalsizec);
	sprintf(totalwritec, "%d", totalwrite);
	strncat(okstr, "200 OK ", sizeof(okstr));	
	strncat(okstr, totalwritec, sizeof(okstr));
	strncat(okstr, "/", sizeof(okstr));
	strncat(okstr, totalsizec, sizeof(okstr));
	write_log(timec, line, okstr, logfile, clientip);
	return;

}