Example #1
0
RewriteCond::RewriteCond( const RewriteCond& rhs )
    : LinkedObj()
    , m_pattern( rhs.m_pattern )
    , m_testStringFormat( rhs.m_testStringFormat )
    , m_opcode( rhs.m_opcode )
    , dummy( rhs.dummy )
    , m_flag( rhs.m_flag )
{
    if ( m_opcode == COND_OP_REGEX )
    {
        compilePattern();
    }
}
Example #2
0
RewriteRule::RewriteRule( const RewriteRule & rhs )
    : LinkedObj()
    , m_conds( rhs.m_conds )
    , m_targetFormat( rhs.m_targetFormat )
    , m_sMimeType( rhs.m_sMimeType )
    , m_action( rhs.m_action )
    , m_flag( rhs.m_flag )
    , m_statusCode( rhs.m_statusCode )
    , m_skipRules( rhs.m_skipRules )
    , m_env( rhs.m_env )
    , m_pattern( rhs.m_pattern )
{
    compilePattern();
}
Example #3
0
int RewriteCond::parse( const char * pRuleStr, const char * pEnd, const RewriteMapList * pMaps )
{
    if ( parseTestString( pRuleStr, pEnd, pMaps ) )
        return -1;
    if ( parseCondPattern( pRuleStr, pEnd ) )
        return -1;
    if ( praseFlag( pRuleStr, pEnd ) )
        return -1;
    while(( pRuleStr < pEnd )&&( isspace( *pRuleStr )))
        ++pRuleStr;
    if (( pRuleStr != pEnd )&&( *pRuleStr != '#' ))
    {
        return 0;
    }
    if ( m_opcode == COND_OP_REGEX )
    {
        return compilePattern();
    }
    return 0;
}
Example #4
0
word_t Regex_constructor(CrocThread* t)
{
	croc_hfield(t, 0, _Ptrs);

	if(!croc_isNull(t, -1))
		croc_eh_throwStd(t, "StateError", "Attempting to call constructor on an already-initialized Regex");

	auto pat = checkCrocstrParam(t, 1);
	auto attrs = parseAttrs(optCrocstrParam(t, 2, ""));
	auto re = compilePattern(t, pat, attrs);

	const char* error;
	auto extra = pcre_study(re, 0, &error);

	if(error != nullptr)
	{
		(*pcre_free)(re);
		croc_eh_throwStd(t, "ValueError", "Error compiling regex: %s", error);
	}

	croc_memblock_new(t, sizeof(PtrStruct));
	auto ptrs = cast(PtrStruct*)croc_memblock_getData(t, -1);
	ptrs->re = re;
	ptrs->extra = extra;
	croc_hfielda(t, 0, _Ptrs);

	int numGroups;
	pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &numGroups);

	croc_memblock_new(t, sizeof(int) * ((numGroups + 1) * 3));
	croc_hfielda(t, 0, _GroupIdx);

	getNameTable(t, re, extra);
	croc_hfielda(t, 0, _Names);

	return 0;
}
Example #5
0
/**
 * An internal function for checking cyclic reference dependency error.
 *
 * ==========
 * Returns 1 if cyclic dependency is found, 0 if otherwise
 */
static int isCyclicError(const Worksheet *worksheet, const char *visitedCells, CellReference *cellRef)
{
    pcre2_match_data *match_data = NULL;
    char *saveptr = NULL;
    int rc = 0;

    MatrixLocation *m = convertToMatrixLocation(cellRef);  
    
    char *cellValue = NULL;
    getValue2(worksheet, &cellValue, m->row, m->col);
    free(m);

    if (cellValue == NULL)
    {
        return 0;
    }

    // do work on working copy
    char *token = NULL;
    token = strtok_r(cellValue, " ", &saveptr);
    pcre2_code *re = getCellReferencePattern();
    while(token != NULL)
    {
        match_data = pcre2_match_data_create(20, NULL);
        int subjectLength = strlen(token);
        rc = pcre2_match(re, (PCRE2_SPTR) token, subjectLength, 0, 0, match_data, NULL); 

        if (rc > 0)
        {
            // search if current cellref is in the visited cells
            pcre2_code *searchVal = compilePattern(token);
            int isCyclicDependency = pcre2_match(searchVal, (PCRE2_SPTR) visitedCells, strlen(visitedCells), 0, 0, match_data, NULL);
            if (isCyclicDependency > 0)
            {
                free(cellValue);
                free(match_data);
                free(searchVal);
                free(re);
                return 1;
            }
            
            free(searchVal);

            //length of existing visitedCells + space character + length of cellRef to be appended + null terminator
            char *newVisitedCells = malloc(sizeof(char) * (strlen(visitedCells) + 1 + strlen(cellRef->cellReference)) + 1);
            strcpy(newVisitedCells, visitedCells);
            strcat(newVisitedCells, " ");
            strcat(newVisitedCells, cellRef->cellReference);
        
            CellReference *tokenCellRef = malloc(sizeof(CellReference));
            tokenCellRef->cellReference = token;

            if(isCyclicError(worksheet, (const char *) newVisitedCells, tokenCellRef))
            {        
                free(cellValue);
                free(newVisitedCells);
                free(match_data);
                free(re);
                return 1;
            }   
      
            free(newVisitedCells);
            free(tokenCellRef);
        }
        token = strtok_r(NULL, " ", &saveptr);
        free(match_data);
    }

    free(cellValue);
    free(re);
    return 0;
}