Ejemplo n.º 1
0
static int
create_basename(const char *url, size_t maxlength, char *mountpoint,
				char *basename)
{
    const char *namestart;
    char *slash;
    char realmountdir[MAXPATHLEN];
    int error = 0;
    
    /* Find the real name of mountdir, by removing all ".", ".." and symlink components.
     * Any extra "/" characters (including any trailing "/") are removed.
     */
    if (realpath(mountpoint, realmountdir) == NULL) {
		error = errno;
		goto errorexit;
    }
	
    /* Check for obvious error cases first: */
    if ((strlen(realmountdir)) + 1 > maxlength) {
        return(ENAMETOOLONG);
    }
	
    namestart = url;
	
    /* First pick out a name we can use */
	
    if (strncasecmp (url, HTTP_PREFIX, sizeof(HTTP_PREFIX) - 1) == 0 ||
		strncasecmp (url, HTTPS_PREFIX, sizeof(HTTPS_PREFIX) - 1) == 0) {
        /* path starts with http or https so lets skip that */
#if DEBUG_TRACE
		syslog(LOG_DEBUG, "WebDAV create_basename: stripping off HTTP(S)_PREFIX...\n");
#endif
        slash = strchr(url,'/');
        if (slash) {
			namestart = slash + 1;
			while (*namestart == '/') {
				++namestart;
			}
        }
#if DEBUG_TRACE
        syslog(LOG_DEBUG, "WebDAV create_basename: resulting name = '%s'...\n", namestart);
#endif
    }
	
    /* create a basename from the path*/
    error = basename_from_path(namestart, basename, maxlength);
    if ( error != 0 ) {
		return ( error );
    }
    
#if DEBUG_TRACE
		syslog(LOG_DEBUG, "WebDAV create_basename: uniquename = '%s'...\n", basename);
#endif
	
errorexit:
	
    return(error);
} /* create_basename */
Ejemplo n.º 2
0
    /**
     * \brief          User defined constructor for PyAlgo.
     * \param[in]    file_path         The path of the algorithm python script/module.
     * \param[in]    class_name         Name of the algorithm class.
     */
    PyAlgo( const std::string file_path, const std::string &class_name )
        : base_t()
        , mFilePath( file_path )
        , mClassName( class_name )
	    , m_module( nullptr )
	    , m_class( nullptr )
	    , m_instance( nullptr )
	{
        if ( !IsFile(mFilePath.c_str()) )
            throw e_file_not_found;

        std::string modulePath = dir_from_filepath( file_path );
        std::string moduleName = basename_from_path( file_path );

		// Add the directory (with module) to the python sys.path

        PyObject *sysPath = PySys_GetObject("path");                        //TODO Py_DECREF sysPath???
        PyObject *path    = PyUnicode_FromString( modulePath.c_str() );     //TODO Py_DECREF path???
		if ( PyList_Insert(sysPath, 0, path))
            throw e_error_add_module_dir_syspath;

		// Build the name object and load the module object

        PyObject *pName   = PyUnicode_FromString( moduleName.c_str() );
		m_module = PyImport_Import(pName);
        Py_DECREF(pName);
		if (PyErr_Occurred()){
			PyErr_Print();
			throw e_error_loading_module;
		}

		std::cout << "- Loaded python Module object " + moduleName + " at " << m_module << std::endl;

	    // Build the name of a callable class

		m_class = PyObject_GetAttrString( m_module, mClassName.c_str() );


		// Create an instance of the class

		if (m_class && PyCallable_Check(m_class))
		{
			m_instance = PyObject_CallObject(m_class, NULL);

            std::cout << "-- Loaded a python Class object " + mClassName + " at " << m_class << std::endl;
		}
		else {
			if (PyErr_Occurred())
				PyErr_Print();
			throw e_class_not_found;
		}
    }