예제 #1
0
/** Trim whitespace and quotes from the start/end of a string.
 * Edits the value in-place.
 *
 * @param value [inout]: the value to trim
 * */
void trimWhitespaceAndQuotes(QString &value) {
  // Remember original value
  const auto valueIn = value;

  // Trim whitespace
  value = value.trimmed();

  // Trim double/single quotes
  trimQuotes(value, '"', '\\');
  trimQuotes(value, '\'', '\\');

  // If trimming was done, recurse to remove any nested quotes/whitespace
  if (value.size() > 0 && value != valueIn)
    trimWhitespaceAndQuotes(value);
}
예제 #2
0
파일: vsopen.cpp 프로젝트: Adglgmut/frisk
static void trimAllQuotes(StringList &l)
{
	for(StringList::iterator it = l.begin(); it != l.end(); ++it)
    {
        trimQuotes(*it);
    }
}
예제 #3
0
파일: cParser.cpp 프로젝트: xytis/DoI
 bool cParser::include(std::stringstream & params)
 {
     std::string filename;
     std::getline(params, filename);
     trimSpaces(filename);
     trimQuotes(filename);
     return parse(filename);
 }
예제 #4
0
void MemoryDump::init()
{
#define memDumpInitError(e) \
    genericError("Failed to initialize this MemoryDump instance with " \
                 "required run-time values from the dump. Error was: " + \
                 e.message)


    // Open virtual memory for reading
    if (!_vmem->open(QIODevice::ReadOnly))
        throw IOException(
                QString("Error opening virtual memory (filename=\"%1\")").arg(_fileName),
                __FILE__,
                __LINE__);

    // The virtual address translation depends on the runtime
    // value of "high_memory". We need to query its value and add it to
    // _specs.vmallocStart before we can translate paged addresses.
    try {
        Instance highMem = queryInstance("high_memory");
        _specs.highMemory = (_specs.sizeofPointer == 4) ?
                    (quint64)highMem.toUInt32() : highMem.toUInt64();
    }
    catch (QueryException& e) {
        if (!_factory->findVarByName("high_memory")) {
            // This is a failure for 32-bit systems
            if (_specs.arch & MemSpecs::ar_i386)
                memDumpInitError(e);
            // Resort to the failsafe value for 64-bit systems
            else {
                debugmsg("Variable \"high_memory\" not found, resorting to "
                         "failsafe default value");
                _specs.highMemory = HIGH_MEMORY_FAILSAFE_X86_64;
            }
        }
        else
            memDumpInitError(e);
    }

    if (_specs.arch & MemSpecs::ar_i386) {
        // This symbol only exists depending on the kernel version
        QString ve_name("vmalloc_earlyreserve");
        if (_factory->findVarByName(ve_name)) {
            try {
                Instance ve = queryInstance(ve_name);
                _specs.vmallocEarlyreserve = ve.toUInt32();
            }
            catch (QueryException& e) {
                genericError("Failed to initialize this MemoryDump instance with "
                        "required run-time values from the dump. Error was: " + e.message);
            }
        }
        else
            _specs.vmallocEarlyreserve = 0;
    }

    // Compare the Linux kernel version to the parsed symbols
    QString uts_ns_name("init_uts_ns");
    if (!_specs.version.release.isEmpty() &&
        _factory->findVarByName(uts_ns_name))
    {
        try {
            struct MemSpecs::Version ver;
            Instance uts_ns = queryInstance(uts_ns_name);
            uts_ns = getNextInstance("name", uts_ns, ksNone);
            // Read in all version information
            if (!_specs.version.machine.isEmpty())
                ver.machine = trimQuotes(
                            uts_ns.member("machine",
                                          BaseType::trLexical).toString());
            if (!_specs.version.release.isEmpty())
                ver.release = trimQuotes(
                            uts_ns.member("release",
                                          BaseType::trLexical).toString());
            if (!_specs.version.sysname.isEmpty())
                ver.sysname = trimQuotes(
                            uts_ns.member("sysname",
                                          BaseType::trLexical).toString());
            if (!_specs.version.version.isEmpty())
                ver.version = trimQuotes(
                            uts_ns.member("version",
                                          BaseType::trLexical).toString());

            if (!_specs.version.equals(ver)) {
                Console::errMsg("WARNING",
                                QString("The memory in '%0' belongs to a "
                                        "different kernel version than the "
                                        "loaded symbols!\n"
                                        "  Kernel symbols: %1\n"
                                        "  Memory file:    %2")
                                .arg(ShellUtil::shortFileName(_fileName))
                                .arg(_specs.version.toString())
                                .arg(ver.toString()));
            }
        }
        catch (QueryException& e) {
            genericError("Failed to retrieve kernel version information of "
                         "this memory dump. Error was: " + e.message);
        }
    }

    // Initialization done
    _specs.initialized = true;
}
예제 #5
0
int
parseParameters( boost::program_options::variables_map _vm, int ruleGen, execMyRuleInp_t *execMyRuleInp, char *inBuf ) {
    strArray_t strArray;
    int status, i, j;
    char *value;
    char line[MAX_NAME_LEN];
    int promptF = 0;
    int labelF = 0;

    if ( inBuf == NULL || strcmp( inBuf, "null" ) == 0 ) {
        execMyRuleInp->inpParamArray = NULL;
        return 0;
    }

    memset( &strArray, 0, sizeof( strArray ) );

    status = splitMultiStr( inBuf, &strArray );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "parseMsInputParam: parseMultiStr error, status = %d", status );
        execMyRuleInp->inpParamArray = NULL;
        return status;
    }

    status = 0;

    resizeStrArray( &strArray, MAX_NAME_LEN );
    value = strArray.value;

    if ( _vm.count( "file" ) ) {
        if ( _vm.count( "parameters" ) ) {
            std::vector< std::string > parameters;
            try {
                parameters = _vm["parameters"].as< std::vector< std::string > >();
            } catch ( boost::bad_any_cast& e ) {
                std::cerr << "Bad parameter list provided to parseParameters\n";
                std::cerr << "Use -h or --help for help\n";
                return -1;
            }

            for ( size_t inx = 0; inx < parameters.size(); ++inx ) {
                std::string param = parameters.at(inx);
                /* using the values from the input line following -F <filename> */
                /* each string is supposed to have to format label=value */

                if ( param == "prompt" ) {
                    promptF = 1;
                    break;
                }

                if ( param == "default" || param.length() == 0 ) {
                    continue;
                }
                else if ( param.at(0) == '*' ) {
                    size_t eqInx;
                    std::string tmpStr;
                    if ( inx > 0 && labelF == 0 ) {
                        return CAT_INVALID_ARGUMENT;
                    }
                    labelF = 1;
                    if ( ( eqInx = param.find( "=" ) ) == std::string::npos ) {
                        return CAT_INVALID_ARGUMENT;
                    }

                    tmpStr = param.substr( 0, eqInx );
                    for ( j = 0; j < strArray.len; j++ ) {
                        if ( strstr( &value[j * strArray.size], tmpStr.c_str() ) == &value[j * strArray.size] ) {
                            char *val = quoteString( param.c_str(), _vm.count( "string" ), 1 );
                            rstrcpy( &value[j * strArray.size], val, strArray.size );
                            free( val );
                            break;
                        }
                    }
                    if ( j == strArray.len ) {
                        printf( "Ignoring Argument \"%s\"\n", param.c_str() );
                    }
                } else {
                    char *valPtr = &value[inx * strArray.size];
                    char *tmpPtr;

                    if ( labelF == 1 ) {
                        return CAT_INVALID_ARGUMENT;
                    }
                    if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
                        tmpPtr++;
                        char *val = quoteString( param.c_str(), _vm.count( "string" ), 0 );
                        rstrcpy( tmpPtr, val,
                                strArray.size - ( tmpPtr - valPtr + 1 ) );
                        free( val );
                    }
                }
            }
        }
    }

    for ( i = 0; i < strArray.len; i++ ) {
        char *valPtr = &value[i * strArray.size];
        char *tmpPtr;

        if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
            *tmpPtr = '\0';
            tmpPtr++;
            if ( *tmpPtr == '$' ) {
                /* If $ is used as a value in the input file for label=value then
                 the remaining command line arguments are taken as values.
                 If no command line arguments are given then the user is prompted
                 for the input value
                 */
                printf( "Default %s=%s\n    New %s=", valPtr, tmpPtr + 1, valPtr );
                if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) {
                    return CAT_INVALID_ARGUMENT;
                }
                size_t line_len = strlen( line );
                if ( line_len > 0 && '\n' == line[line_len - 1] ) {
                    line[line_len - 1] = '\0';
                    line_len--;
                }
                char *val = line_len > 0 ?
                            quoteString( line, _vm.count( "string" ) && ruleGen, 0 ) :
                            strdup( tmpPtr + 1 );
                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            val, NULL );
            }
            else if ( promptF == 1 ) {
                /* the user has asked for prompting */
                printf( "Current %s=%s\n    New %s=", valPtr, tmpPtr, valPtr );
                if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) {
                    return CAT_INVALID_ARGUMENT;
                }
                size_t line_len = strlen( line );
                if ( line_len > 0 && '\n' == line[line_len - 1] ) {
                    line[line_len - 1] = '\0';
                    line_len--;
                }
                char *val = line_len > 0 ?
                            quoteString( line, _vm.count( "string" ) && ruleGen, 0 ) :
                            strdup( tmpPtr );
                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            val, NULL );
            }
            else if ( *tmpPtr == '\\' ) {
                /* first '\'  is skipped.
                 If you need to use '\' in the first letter add an additional '\'
                 if you have to use '$' in the first letter add a '\'  before that
                 */
                tmpPtr++;
                char *param = quoteString( tmpPtr, _vm.count( "string" ) && ruleGen, 0 );
                if ( !ruleGen ) {
                    trimQuotes( param );
                }

                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            param, NULL );
            }
            else {
                char *param = quoteString( tmpPtr, _vm.count( "string" ) && ruleGen, 0 );
                if ( !ruleGen ) {
                    trimQuotes( param );
                }

                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            param, NULL );
            }
        }
        else {
            rodsLog( LOG_ERROR,
                     "parseMsInputParam: inpParam %s format error", valPtr );
            status = CAT_INVALID_ARGUMENT;
        }
    }

    return status;
}
예제 #6
0
int
parseMsInputParam( int argc, char **argv, int optInd, int ruleGen, int string,
                   execMyRuleInp_t *execMyRuleInp, char *inBuf ) {
    strArray_t strArray;
    int status, i, j;
    char *value;
    int nInput;
    char line[MAX_NAME_LEN];
    int promptF = 0;
    int labelF = 0;
    if ( inBuf == NULL || strcmp( inBuf, "null" ) == 0 ) {
        execMyRuleInp->inpParamArray = NULL;
        return ( 0 );
    }

    nInput = argc - optInd;
    memset( &strArray, 0, sizeof( strArray ) );

    status = splitMultiStr( inBuf, &strArray );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "parseMsInputParam: parseMultiStr error, status = %d", status );
        execMyRuleInp->inpParamArray = NULL;
        return ( status );
    }

    resizeStrArray( &strArray, MAX_NAME_LEN );
    value = strArray.value;

    /* each string is supposed to have to format label=value */
    for ( i = 0; i < nInput; i++ ) {
        /* using the values from the input line following -F <filename> */
        if ( !strcmp( argv[optInd + i], "prompt" ) ) {
            promptF = 1;
            break;
        }
        if ( !strcmp( argv[optInd + i], "default" ) || strlen( argv[optInd + i] ) == 0 ) {
            continue;
        }
        else if ( *argv[optInd + i] == '*' ) {
            char *tmpPtr;
            if ( i > 0 && labelF == 0 ) {
                return( CAT_INVALID_ARGUMENT );
            }
            labelF = 1;
            if ( ( tmpPtr = strstr( argv[optInd + i], "=" ) ) == NULL ) {
                return( CAT_INVALID_ARGUMENT );
            }
            *tmpPtr = '\0';
            for ( j = 0; j < strArray.len; j++ ) {
                if ( strstr( &value[j * strArray.size], argv[optInd + i] ) == &value[j * strArray.size] ) {
                    *tmpPtr = '=';
                    char *val = quoteString( argv[optInd + i], string, 1 );
                    rstrcpy( &value[j * strArray.size], val, strArray.size );
                    free( val );
                    break;
                }
            }
            if ( j == strArray.len ) {
                printf( "Ignoring Argument \"%s\"", argv[optInd + i] );
            }
        }
        else {
            char *valPtr = &value[i * strArray.size];
            char *tmpPtr;
            if ( labelF == 1 ) {
                return( CAT_INVALID_ARGUMENT );
            }
            if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
                tmpPtr++;
                char *val = quoteString( argv[optInd + i], string, 0 );
                rstrcpy( tmpPtr, val,
                         strArray.size - ( tmpPtr - valPtr + 1 ) );
                free( val );
            }
        }
    }

    for ( i = 0; i < strArray.len; i++ ) {
        char *valPtr = &value[i * strArray.size];
        char *tmpPtr;

        if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
            *tmpPtr = '\0';
            tmpPtr++;
            /** RAJA Jul 12 2007 changed it so that it can take input values from terminal
            addMsParam (execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                    strdup (tmpPtr), NULL);
             ** RAJA Jul 12 2007 changed it so that it can take input values from terminal **/
            if ( *tmpPtr == '$' ) {
                /* If $ is used as a value in the input file for label=value then
                 the remaining command line arguments are taken as values.
                 If no command line arguments are given then the user is prompted
                 for the input value
                 */
                printf( "Default %s=%s\n    New %s=", valPtr, tmpPtr + 1, valPtr );
                if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) {
                    return( CAT_INVALID_ARGUMENT );
                }
                if ( ( line[strlen( line ) - 1] = '\n' ) ) {
                    line[strlen( line ) - 1] = '\0';
                }
                char *val;
                if ( strlen( line ) == 0 ) {
                    val = strdup( tmpPtr + 1 );
                }
                else {
                    val = quoteString( line, string && ruleGen, 0 );
                }
                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            val, NULL );
            }
            else if ( promptF == 1 ) {
                /* the user has asked for prompting */
                printf( "Current %s=%s\n    New %s=", valPtr, tmpPtr, valPtr );
                if ( fgets( line, MAX_NAME_LEN, stdin ) == NULL ) {
                    return( CAT_INVALID_ARGUMENT );
                }
                if ( ( line[strlen( line ) - 1] = '\n' ) ) {
                    line[strlen( line ) - 1] = '\0';
                }
                char *val;
                if ( strlen( line ) == 0 ) {
                    val = strdup( tmpPtr );
                }
                else {
                    val = quoteString( line, string && ruleGen, 0 );
                }
                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            val, NULL );
            }
            else if ( *tmpPtr == '\\' ) {
                /* first '\'  is skipped.
                 If you need to use '\' in the first letter add an additional '\'
                 if you have to use '$' in the first letter add a '\'  before that
                 */
                tmpPtr++;
                char *param = quoteString( tmpPtr, string && ruleGen, 0 );
                if ( !ruleGen ) {
                    trimQuotes( param );
                }

                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            param, NULL );
            }
            else {
                char *param = quoteString( tmpPtr, string && ruleGen, 0 );
                if ( !ruleGen ) {
                    trimQuotes( param );
                }

                addMsParam( execMyRuleInp->inpParamArray, valPtr, STR_MS_T,
                            param, NULL );
            }
        }
        else {
            rodsLog( LOG_ERROR,
                     "parseMsInputParam: inpParam %s format error", valPtr );
        }
    }

    return ( 0 );
}