Commit e42c3452 authored by root's avatar root

first commit on github

parent e45561e7
/*
Copyright (c) 2012 Unixmedia S.r.l. <info@unixmedia.it>
Copyright (c) 2012 Franco (nextime) Lanza <franco@unixmedia.it>
Domotika System Domain utils [http://trac.unixmedia.it]
This file is part of DMDomain.
DMDomain is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DMDOMAIN_C
#define __DMDOMAIN_C
#if defined(__GNUC__)
#include <string.h>
#include <stdio.h>
#define PRN_BOOL(VAR) (VAR ? "True" : "False")
#endif
#if defined(__18CXX)
#include "DomotikaIncludes.h"
#endif
//#if defined(__GNUC__)
//typedef unsigned char BYTE;
//#endif
#include "DMDomain.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1U
#endif
#define DOMAIN_NEGATION (0x21) // !
#define DOMAIN_LIST_START (0x5b) // [
#define DOMAIN_LIST_STOP (0x5d) // ]
#define DOMAIN_LIST_SEPARATOR (0x7c) // |
#define DOMAIN_SEPARATOR (0x2e) // .
#define DOMAIN_NULL (0x00) // \0
#define DOMAIN_STAR (0x2a) // *
#define DOMAIN_STATUS_HOME (0x00)
#define DOMAIN_STATUS_STAR (0x01)
#define DOMAIN_STATUS_LIST_START (0x02)
#define DOMAIN_STATUS_LIST_STOP (0x03)
#define DOMAIN_STATUS_LIST_SEPARATOR (0x04)
#define DOMAIN_STATUS_LIST_PARSE (0x05)
#define DOMAIN_STATUS_EQUAL (0x06)
#define DOMAIN_STATUS_NEGATE (0x07)
#define DOMAIN_STATUS_NEGATE_PARSE (0x08)
#define DOMAIN_STATUS_SEPARATOR (0x09)
#define DOMAIN_STATUS_LIST_STAR (0x0a)
#define DOMAIN_STATUS_LIST_STAR_STOP (0x0b)
#define DOMAIN_STATUS_LIST_NEGATE_START (0x0c)
#define DOMAIN_STATUS_LIST_NEGATE_PARSE (0x0d)
#define DOMAIN_STATUS_LIST_NEGATE_STOP (0x0e)
#define DOMAIN_STATUS_LIST_NEGATE_SEPARATOR (0x0f)
#define DOMAIN_STATUS_END (0x10)
#define DOMAIN_STATUS_LIST_TRUE (0x11)
#define DOMAIN_STATUS_STAR_NEGATION_END (0x12)
#define DOMAIN_CYCLE_MATCH (0xfe)
#define DOMAIN_CYCLE_CONTROL (0xff)
#define SUB_STATUS_NONE (0xff)
#define STAR_STATUS_CONTINUE (0xfe)
#define LIST_STATUS_START (0x0fd)
#define LIST_STATUS_CONTINUE (0x0fc)
#if defined(DOMAIN_VALIDATION_MATCH) || defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)
void ValidateDomainString(BYTE *DomainStr,
BYTE DomainType,
BYTE DomainLen)
{
BYTE DomainStatus=DOMAIN_STATUS_HOME;
BYTE DomainIdx=0u;
#if defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)
BYTE InvalidChar=FALSE;
#endif
if(DomainLen > DOMAIN_MAXLEN)
DomainLen=DOMAIN_MAXLEN;
#if defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)
if(DomainType==DOMAIN_TYPE_CONTROL)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: START\n");
#endif
while(DomainLen > DomainIdx)
{
switch(*(DomainStr+DomainIdx))
{
case DOMAIN_NULL:
switch(DomainStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_STAR:
case DOMAIN_STATUS_LIST_STOP:
case DOMAIN_STATUS_EQUAL:
case DOMAIN_STATUS_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: NULL TERMINATION\n");
#endif
return;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_SEPARATOR:
switch(DomainStatus)
{
case DOMAIN_STATUS_STAR:
case DOMAIN_STATUS_LIST_STOP:
case DOMAIN_STATUS_EQUAL:
case DOMAIN_STATUS_NEGATE_PARSE:
if(DomainIdx < DomainLen-1u)
{
DomainStatus=DOMAIN_STATUS_SEPARATOR;
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: SEPARATOR FOUND\n");
#endif
break;
}
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_STAR:
switch(DomainStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
if(DomainIdx>=2u && *(DomainStr+DomainIdx-2u)==DOMAIN_STAR)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: DOUBLE STAR SHIFTING\n");
#endif
*(DomainStr+DomainIdx-2u)=DomainIdx+1u;
while(*(DomainStr+DomainIdx-2u) < DomainLen
&& *(DomainStr+*(DomainStr+DomainIdx-2u))!=DOMAIN_NULL)
{
printf("Control Validation: DOUBLE STAR SHIFTING %d\n",
*(DomainStr+DomainIdx-2u));
*(DomainStr+*(DomainStr+DomainIdx-2u)-2u)=*(DomainStr+*(DomainStr+DomainIdx-2u));
*(DomainStr+DomainIdx-2u)+=1u;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: DOUBLE STAR SHIFTING END AT %d\n",
*(DomainStr+DomainIdx-2u));
#endif
*(DomainStr+*(DomainStr+DomainIdx-2u)-2u)=DOMAIN_NULL;
DomainLen-=2;
*(DomainStr+DomainIdx-2u)=DOMAIN_STAR;
DomainIdx-=2;
// SHIFT ARRAY!! SE C'E' UN'ALTRA STAR
}
DomainStatus=DOMAIN_STATUS_STAR;
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: STAR FOUND\n");
#endif
break;
case DOMAIN_STATUS_LIST_START:
if(DomainIdx < DomainLen-1u)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: LIST STAR FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_LIST_STAR;
break;
}
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_NEGATION:
switch(DomainStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
if(DomainIdx < DomainLen-1u)
{
DomainStatus=DOMAIN_STATUS_NEGATE;
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: NEGATE FOUND\n");
#endif
break;
}
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_LIST_START:
switch(DomainStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
if(DomainIdx < DomainLen-2u)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: LIST START FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_LIST_START;
break;
}
InvalidChar=TRUE;
break;
case DOMAIN_STATUS_NEGATE:
if(DomainIdx < DomainLen-3u)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: LIST NEGATE START FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_LIST_NEGATE_START;
break;
}
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_LIST_STOP:
switch(DomainStatus)
{
case DOMAIN_STATUS_LIST_PARSE:
case DOMAIN_STATUS_LIST_STAR:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: LIST STOP FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_LIST_STOP;
break;
default:
InvalidChar=TRUE;
}
break;
case DOMAIN_LIST_SEPARATOR:
switch(DomainStatus)
{
case DOMAIN_STATUS_LIST_PARSE:
if(DomainIdx < DomainLen-2u)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: LIST SEPARATOR FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_LIST_SEPARATOR;
break;
}
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
break;
default:
switch(DomainStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
DomainStatus=DOMAIN_STATUS_EQUAL;
break;
case DOMAIN_STATUS_LIST_START:
case DOMAIN_STATUS_LIST_NEGATE_START:
case DOMAIN_STATUS_LIST_SEPARATOR:
if(DomainIdx < DomainLen-1u)
{
DomainStatus=DOMAIN_STATUS_LIST_PARSE;
break;
}
InvalidChar=TRUE;
break;
case DOMAIN_STATUS_NEGATE:
if(DomainIdx < DomainLen)
{
DomainStatus=DOMAIN_STATUS_NEGATE_PARSE;
break;
}
InvalidChar=TRUE;
break;
case DOMAIN_STATUS_EQUAL:
break;
case DOMAIN_STATUS_NEGATE_PARSE:
if(DomainIdx < DomainLen)
break;
InvalidChar=TRUE;
break;
case DOMAIN_STATUS_LIST_PARSE:
case DOMAIN_STATUS_LIST_NEGATE_PARSE:
if(DomainIdx < DomainLen-1u)
break;
InvalidChar=TRUE;
break;
default:
InvalidChar=TRUE;
}
}
if(InvalidChar)
{
switch(DomainStatus)
{
case DOMAIN_STATUS_LIST_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH LIST_SEPARATOR\n");
#endif
*(DomainStr+DomainIdx-1)=DOMAIN_LIST_STOP;
*(DomainStr+DomainIdx)=DOMAIN_NULL;
return;
case DOMAIN_STATUS_LIST_STAR:
case DOMAIN_STATUS_LIST_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH LIST_PARSE or STAR\n");
#endif
*(DomainStr+DomainIdx)=DOMAIN_LIST_STOP;
if(DomainIdx+1u < DomainLen)
*(DomainStr+DomainIdx+1u)=DOMAIN_NULL;
return;
case DOMAIN_STATUS_LIST_START:
case DOMAIN_STATUS_NEGATE:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH LIST_START or NEGATE\n");
#endif
if(DomainIdx >= 2u)
*(DomainStr+DomainIdx-2u)=DOMAIN_NULL;
else
*(DomainStr)=DOMAIN_NULL;
return;
case DOMAIN_STATUS_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH SEPARATOR\n");
#endif
*(DomainStr+DomainIdx-1)=DOMAIN_NULL;
return;
case DOMAIN_STATUS_LIST_NEGATE_START:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH NEGATE_START\n");
#endif
if(DomainIdx >= 3u)
*(DomainStr+DomainIdx-3u)=DOMAIN_NULL;
else
*(DomainStr)=DOMAIN_NULL;
return;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH INVALID CHAR\n");
#endif
// DOMAIN_STATUS_HOME
// DOMAIN_STATUS_LIST_STOP
// DOMAIN_STATUS_EQUAL
// DOMAIN_STATUS_NEGATE_PARSE
//
*(DomainStr+DomainIdx)=DOMAIN_NULL;
return;
}
}
DomainIdx++;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("Control Validation: END WITH 32 CHAR\n");
#endif
}
#endif
#if (defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)) && defined(DOMAIN_VALIDATION_MATCH)
else
#endif
#if defined(DOMAIN_VALIDATION_MATCH)
if(DomainType==DOMAIN_TYPE_MATCH) {
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: START\n");
#endif
while(DomainLen > DomainIdx)
{
switch(*(DomainStr+DomainIdx))
{
case DOMAIN_STAR:
case DOMAIN_NEGATION:
case DOMAIN_LIST_START:
case DOMAIN_LIST_SEPARATOR:
case DOMAIN_LIST_STOP:
case DOMAIN_NULL:
if(DomainStatus==DOMAIN_STATUS_SEPARATOR && DomainIdx > 0)
{
*(DomainStr+DomainIdx-1u)=DOMAIN_NULL;
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: END WITH SEPARATOR\n");
#endif
} else {
*(DomainStr+DomainIdx)=DOMAIN_NULL;
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: END WITHOUT SEPARATOR\n");
#endif
}
return;
case DOMAIN_SEPARATOR:
if(DomainIdx==0u)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: FIRST CHAR SEPARATOR\n");
#endif
*(DomainStr+DomainIdx)=DOMAIN_NULL;
return;
} else if(DomainStatus==DOMAIN_STATUS_SEPARATOR) {
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: DOUBLE SEPARATOR\n");
#endif
*(DomainStr+DomainIdx-1u)=DOMAIN_NULL;
return;
} else {
if(DomainIdx==DomainLen-1u)
{
*(DomainStr+DomainIdx)=DOMAIN_NULL;
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: END WITH SEPARATOR\n");
#endif
return;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("Match Validation: SEPARATOR FOUND\n");
#endif
DomainStatus=DOMAIN_STATUS_SEPARATOR;
}
break;
default:
DomainStatus=DOMAIN_STATUS_EQUAL;
}
DomainIdx++;
}
}
#endif
}
#endif
BYTE DMDomainMatch( BYTE *ControlStr,
BYTE *MatchStr,
BYTE ControlLen)
{
BYTE ControlStatus=DOMAIN_STATUS_HOME;
BYTE ControlIdx=0u;
BYTE ControlStartIdx=0u;
BYTE DomainSaveStatus=DOMAIN_STATUS_HOME;
BYTE DomainStatus=DOMAIN_CYCLE_CONTROL;
BYTE MatchStatus=TRUE;
BYTE MatchIdx=0u;
BYTE MatchIdxSave=0u;
BYTE flag=0u;
BYTE specialflag=DOMAIN_NULL;
BYTE SubStatus=SUB_STATUS_NONE;
BYTE ControlSpecialIdx;
BYTE MatchSpecialIdx;
if(ControlLen > DOMAIN_MAXLEN)
ControlLen=DOMAIN_MAXLEN;
#if defined(__GNUC__)
if(ControlLen==0 || strlen((const char *)MatchStr)==0)
return FALSE;
#else
if(ControlLen==0 || strlen(MatchStr)==0)
return FALSE;
#endif
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch: START -> '%.*s', '%.*s'\n", (unsigned int)DOMAIN_MAXLEN,
ControlStr, (unsigned int)DOMAIN_MAXLEN, MatchStr);
#endif
while(ControlLen > ControlIdx || DOMAIN_MAXLEN > MatchIdx)
{
#if defined(__18CXX)
ClrWdt();
#endif
if((ControlIdx >= ControlLen || ControlStatus==DOMAIN_STATUS_END)
&& DomainStatus==DOMAIN_CYCLE_CONTROL)
{
DomainStatus=DOMAIN_CYCLE_MATCH;
DomainSaveStatus=ControlStatus;
ControlStatus=DOMAIN_STATUS_END;
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch: CONTROL STRING IS OVER AT CYCLE START %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
}
#if defined(__18CXX)
if(strlen(MatchStr) <= MatchIdx)
#else
if(strlen((const char *)MatchStr) <= MatchIdx)
#endif
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch: MATCH STRING IS OVER AT CYCLE START %d (%c) %d %d\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx),
(int)strlen((const char *)MatchStr), MatchIdx);
#endif
if(ControlStatus==DOMAIN_STATUS_END
&& (
(DomainStatus==TRUE && ControlIdx==ControlStartIdx)
|| (DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE && ControlIdx!=ControlStartIdx)
|| DomainSaveStatus==DOMAIN_STATUS_STAR
|| DomainSaveStatus==DOMAIN_STATUS_HOME
)
)
{
return TRUE;
}
if (ControlStatus==DOMAIN_STATUS_END
&& DomainStatus==DOMAIN_CYCLE_MATCH)
return MatchStatus;
if(*(ControlStr+ControlIdx)==DOMAIN_SEPARATOR)
return FALSE;
}
if(DomainStatus==DOMAIN_CYCLE_CONTROL)
{
if(MatchStatus==FALSE &&
DomainSaveStatus==DOMAIN_STATUS_STAR)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: Continue for STAR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
SubStatus=STAR_STATUS_CONTINUE;
} else if ( MatchStatus==TRUE )
{
SubStatus=SUB_STATUS_NONE;
}
// execute the Control parse part
switch(*(ControlStr+ControlIdx))
{
case DOMAIN_NULL:
switch(ControlStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_STAR:
case DOMAIN_STATUS_LIST_STAR_STOP:
case DOMAIN_STATUS_EQUAL:
case DOMAIN_STATUS_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_END %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
DomainStatus=DOMAIN_CYCLE_MATCH;
DomainSaveStatus=ControlStatus;
ControlStatus=DOMAIN_STATUS_END;
break;
case DOMAIN_STATUS_LIST_STOP:
case DOMAIN_STATUS_LIST_NEGATE_STOP:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_END LIST %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
if(MatchStatus==DOMAIN_STATUS_LIST_TRUE)
{
if(ControlStatus==DOMAIN_STATUS_LIST_STOP)
ControlStartIdx=ControlIdx;
else
ControlStartIdx++;
}
DomainStatus=DOMAIN_CYCLE_MATCH;
DomainSaveStatus=ControlStatus;
ControlStatus=DOMAIN_STATUS_END;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: NULL DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
break;
case DOMAIN_SEPARATOR:
switch(ControlStatus)
{
case DOMAIN_STATUS_STAR:
case DOMAIN_STATUS_LIST_STOP:
case DOMAIN_STATUS_LIST_NEGATE_STOP:
case DOMAIN_STATUS_LIST_STAR_STOP:
case DOMAIN_STATUS_EQUAL:
case DOMAIN_STATUS_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_SEPARATOR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
DomainStatus=DOMAIN_CYCLE_MATCH;
DomainSaveStatus=ControlStatus;
ControlStatus=DOMAIN_STATUS_SEPARATOR;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: SEPARATOR DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
break;
case DOMAIN_STAR:
switch(ControlStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_STAR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_STAR;
break;
case DOMAIN_STATUS_LIST_START:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_STAR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_STAR;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: STAR DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
break;
case DOMAIN_NEGATION:
switch(ControlStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
ControlStatus=DOMAIN_STATUS_NEGATE;
ControlStartIdx=ControlIdx+1u;
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_NEGATE %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: NEGATION DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
break;
case DOMAIN_LIST_START:
switch(ControlStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_START %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStartIdx=ControlIdx+1u;
ControlStatus=DOMAIN_STATUS_LIST_START;
break;
case DOMAIN_STATUS_NEGATE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_NEGATE_START %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStartIdx=ControlIdx+1u;
ControlStatus=DOMAIN_STATUS_LIST_NEGATE_START;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: LIST_START DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
MatchStatus=FALSE;
SubStatus=LIST_STATUS_START;
break;
case DOMAIN_LIST_STOP:
switch(ControlStatus)
{
case DOMAIN_STATUS_LIST_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_STOP %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_STOP;
break;
case DOMAIN_STATUS_LIST_STAR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_STAR_STOP %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_STAR_STOP;
break;
case DOMAIN_STATUS_LIST_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_NEGATE_STOP %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_NEGATE_STOP;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: LIST_STOP_DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
break;
case DOMAIN_LIST_SEPARATOR:
switch(ControlStatus)
{
case DOMAIN_STATUS_LIST_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_SEPARATOR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_SEPARATOR;
if(MatchStatus==DOMAIN_STATUS_LIST_TRUE)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST ALREADY TRUE AT SEPARATOR\n");
#endif
SubStatus=SUB_STATUS_NONE;
} else {
DomainSaveStatus=ControlStatus;
DomainStatus=DOMAIN_CYCLE_MATCH;
}
break;
case DOMAIN_STATUS_LIST_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_NEGATE_SEPARATOR %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx));
#endif
ControlStatus=DOMAIN_STATUS_LIST_NEGATE_SEPARATOR;
if(MatchStatus==DOMAIN_STATUS_LIST_TRUE)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_NEGATE_LIST ALREADY TRUE AT SEPARATOR\n");
#endif
SubStatus=SUB_STATUS_NONE;
} else {
DomainSaveStatus=ControlStatus;
DomainStatus=DOMAIN_CYCLE_MATCH;
}
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: LIST_SEPARATOR DEFAULT %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
return FALSE;
}
break;
default:
switch(ControlStatus)
{
case DOMAIN_STATUS_HOME:
case DOMAIN_STATUS_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_EQUAL %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
ControlStatus=DOMAIN_STATUS_EQUAL;
ControlStartIdx=ControlIdx;
break;
case DOMAIN_STATUS_LIST_START:
case DOMAIN_STATUS_LIST_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_PARSE %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
ControlStatus=DOMAIN_STATUS_LIST_PARSE;
break;
case DOMAIN_STATUS_NEGATE:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_NEGATE_PARSE %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
ControlStatus=DOMAIN_STATUS_NEGATE_PARSE;
break;
case DOMAIN_STATUS_LIST_NEGATE_START:
case DOMAIN_STATUS_LIST_NEGATE_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DOMAIN_STATUS_LIST_NEGATE_PARSE %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
ControlStatus=DOMAIN_STATUS_LIST_NEGATE_PARSE;
break;
case DOMAIN_STATUS_LIST_NEGATE_PARSE:
case DOMAIN_STATUS_NEGATE_PARSE:
case DOMAIN_STATUS_LIST_PARSE:
case DOMAIN_STATUS_EQUAL:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: CHAR PARSE %d (%c)\n",
ControlIdx, (unsigned int)*(ControlStr+ControlIdx) );
#endif
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Control: DEFAULT DEFAULT %d (%c)\n", ControlIdx,
(unsigned int)*(ControlStr+ControlIdx));
#endif
return FALSE;
}
}
} else {
if(DomainStatus==DOMAIN_CYCLE_MATCH)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("ENTERING MATCH CYCLE %d\n", DomainSaveStatus);
#endif
flag=FALSE;
MatchStatus=FALSE;
if(DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE
|| DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_SEPARATOR
|| DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP)
DomainStatus=FALSE;
else
DomainStatus=TRUE;
if(SubStatus==STAR_STATUS_CONTINUE)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("SAVING ControlStartIdx cause of STAR CONTINUE STATUS\n");
#endif
switch(DomainSaveStatus)
{
case DOMAIN_STATUS_LIST_NEGATE_STOP:
case DOMAIN_STATUS_LIST_NEGATE_SEPARATOR:
#if defined(__GNUC__) && defined(DEBUG)
printf("NEGATION LIST PRECEEDED BY A STAR\n");
#endif
case DOMAIN_STATUS_NEGATE_PARSE:
#if defined(__GNUC__) && defined(DEBUG)
printf("NEGATION PRECEEDED BY A STAR: SPECIAL CASE\n");
#endif
/*
- Count how many levels remain after the negation
on the control string
- count how many levels we have in the match string
to be parsed
- check if the negation string appears in the
difference between the control and the match remaining
levels, assuming the first is more than the second.
at this point, if the result is found, return FALSE,
if the result isn't found, continue as usual.
*/
// Count how many levels there are in the Match string
// staring from one as we are at the next level compared
// comparing to the control
SubStatus=1;
MatchSpecialIdx=MatchIdx;
while(MatchSpecialIdx<DOMAIN_MAXLEN)
{
if(*(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR)
{
SubStatus++;
} else if(*(MatchStr+MatchSpecialIdx)==DOMAIN_NULL)
break;
MatchSpecialIdx++;
}
// Substract the Control levels remaining after the negation
ControlSpecialIdx=ControlIdx;
specialflag=SubStatus;
while(ControlSpecialIdx<ControlLen)
{
if(!SubStatus)
break;
if(*(ControlStr+ControlSpecialIdx)==DOMAIN_SEPARATOR)
{
SubStatus--;
}
ControlSpecialIdx++;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("check negation for %d levels \n", SubStatus);
#endif
if(specialflag==SubStatus &&
(DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE ||
DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP))
{
// a special case in the special case.
// The negation is at the last level in the control string.
#if defined(__GNUC__) && defined(DEBUG)
printf("NEGATION IS IN THE LAST CONTROL LEVEL\n");
#endif
DomainSaveStatus=DOMAIN_STATUS_STAR_NEGATION_END;
}
// match all levels we have to check for negation
ControlSpecialIdx=ControlStartIdx;
MatchSpecialIdx=MatchIdx;
MatchStatus=TRUE;
specialflag=SubStatus;
while(SubStatus)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("level %d: %c - %c\n", SubStatus,
(unsigned int)*(ControlStr+ControlSpecialIdx),
(unsigned int)*(MatchStr+MatchSpecialIdx));
#endif
if(*(ControlStr+ControlSpecialIdx)==DOMAIN_SEPARATOR
|| *(ControlStr+ControlSpecialIdx)==DOMAIN_NULL
|| ControlSpecialIdx>=ControlLen
|| *(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_SEPARATOR
|| *(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_STOP
|| *(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR
|| *(MatchStr+MatchSpecialIdx)==DOMAIN_NULL
|| MatchSpecialIdx>=DOMAIN_MAXLEN)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("level separator or terminator found\n");
#endif
if(MatchStatus
&& (
(
(*(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR
|| *(MatchStr+MatchSpecialIdx)==DOMAIN_NULL
|| MatchSpecialIdx>DOMAIN_MAXLEN)
&& (*(ControlStr+ControlSpecialIdx)==DOMAIN_SEPARATOR
|| *(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_SEPARATOR
|| *(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_STOP))
||
(SubStatus<=1 &&
(*(ControlStr+ControlSpecialIdx)==DOMAIN_NULL
|| ControlSpecialIdx>=ControlLen)
)
)
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("NEGATION MATCH FOUND!\n");
#endif
return FALSE;
}
else
{
if((*(ControlStr+ControlSpecialIdx)==DOMAIN_NULL
|| ControlSpecialIdx>=ControlLen)
&& SubStatus<=1)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("NEGATION MATCH NOT FOUND AND CONTROL END!\n");
#endif
return TRUE;
}
MatchStatus=TRUE;
}
ControlSpecialIdx=ControlStartIdx;
SubStatus--;
if(*(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR)
MatchSpecialIdx++;
else
{
// Move Match cursor to the next level
while(TRUE)
{
if(*(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR)
{
MatchSpecialIdx++;
break;
} else if(*(MatchStr+MatchSpecialIdx)==DOMAIN_NULL
|| MatchSpecialIdx>=DOMAIN_MAXLEN)
{
break;
}
MatchSpecialIdx++;
}
}
} else {
if(*(MatchStr+MatchSpecialIdx)!=*(ControlStr+ControlSpecialIdx)
&& MatchStatus==TRUE)
MatchStatus=FALSE;
ControlSpecialIdx++;
MatchSpecialIdx++;
}
if(!SubStatus
&& (DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_SEPARATOR
|| DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP
)
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("Manage NEGATION LIST\n");
#endif
ControlSpecialIdx=ControlStartIdx;
while(TRUE)
{
if(*(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_SEPARATOR)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("LIST SEPARATOR, continue with negation list\n");
#endif
SubStatus=specialflag;
MatchSpecialIdx=MatchIdx;
ControlSpecialIdx++;
break;
}
if(*(ControlStr+ControlSpecialIdx)==DOMAIN_LIST_STOP)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("LIST STOP, done negation list\n");
#endif
ControlSpecialIdx++;
DomainSaveStatus=DOMAIN_STATUS_LIST_NEGATE_STOP;
break;
}
ControlSpecialIdx++;
}
//MatchSpecialIdx=MatchIdx;
if(ControlSpecialIdx>=ControlLen || *(ControlStr+ControlSpecialIdx)==DOMAIN_NULL)
DomainSaveStatus=DOMAIN_STATUS_STAR_NEGATION_END;
//else if(*(ControlStr+ControlSpecialIdx)==DOMAIN_SEPARATOR)
// ControlSpecialIdx++;
ControlStartIdx=ControlSpecialIdx;
ControlIdx=ControlSpecialIdx;
// NEXTIME
}
}
if(DomainSaveStatus==DOMAIN_STATUS_STAR_NEGATION_END)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("CONTROL LAST LEVEL AND CONTROL END\n");
#endif
return TRUE;
}
// If we are here the special case is over,
// and we don't have a match.
// So, we must continue to the next level!
// Move MatchIdx to the right level
#if defined(__GNUC__) && defined(DEBUG)
printf("SPECIAL CASE IS OVER, MOVING INDICES TO GO BACK IN NORMAL MODE (%c)\n",
(unsigned int)*(ControlStr+ControlSpecialIdx));
#endif
while(TRUE)
{
if(MatchSpecialIdx==0
|| *(MatchStr+MatchSpecialIdx)==DOMAIN_SEPARATOR)
break;
MatchSpecialIdx--;
}
MatchIdx=MatchSpecialIdx;
SubStatus=SUB_STATUS_NONE;
specialflag=ControlSpecialIdx;
MatchStatus=FALSE;
ControlStatus=DOMAIN_STATUS_SEPARATOR;
break;
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("NOT A SPECIAL CASE %d %d %d %d\n", ControlIdx, MatchIdx, ControlStartIdx, MatchSpecialIdx);
#endif
// Isn't a special case!
MatchStatus=FALSE;
specialflag=ControlStartIdx;
MatchIdxSave=MatchIdx;
//MatchIdx=MatchSpecialIdx;
}
} //else if(SubStatus==LIST_STATUS_START)
if(SubStatus==LIST_STATUS_START)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("SAVING MatchIdx cause of LIST_START STATUS\n");
#endif
//SubStatus=MatchIdx;
MatchIdxSave=MatchIdx;
}
}
// execute the Match parse part
switch(*(MatchStr+MatchIdx))
{
case DOMAIN_SEPARATOR:
if((ControlStatus==DOMAIN_STATUS_SEPARATOR && DomainStatus==TRUE)
|| (DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE && ControlIdx!=ControlStartIdx)
|| (DomainSaveStatus==DOMAIN_STATUS_STAR)
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: TRUE SEPARATOR %d %d %d \n", DomainStatus,
ControlStatus, DomainSaveStatus);
#endif
if(DomainSaveStatus==DOMAIN_STATUS_STAR)
MatchStatus=FALSE;
else
{
if(ControlStartIdx!=ControlIdx && DomainSaveStatus==DOMAIN_STATUS_EQUAL)
{
return FALSE;
}
MatchStatus=TRUE;
}
MatchIdx++;
DomainStatus=DOMAIN_CYCLE_CONTROL;
break;
} else if(DomainStatus==TRUE
&& ((DomainSaveStatus==DOMAIN_STATUS_LIST_SEPARATOR
&& ControlIdx==ControlStartIdx)
|| ( DomainSaveStatus==DOMAIN_STATUS_LIST_STOP
&& ControlIdx==ControlStartIdx+1u)))
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: LIST SEPARATOR/STOP TRUE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
if(*(ControlStr+ControlIdx)==DOMAIN_NULL
|| ControlIdx>=DOMAIN_MAXLEN) // XXX Uhmmm isn't there a better way?
return FALSE;
MatchStatus=DOMAIN_STATUS_LIST_TRUE;
DomainStatus=DOMAIN_CYCLE_CONTROL;
break;
} else if((DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_SEPARATOR
&& (DomainStatus==TRUE || ControlIdx!=ControlStartIdx))
|| (DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP
&& (DomainStatus==TRUE || ControlIdx!=ControlStartIdx+1u))
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: SEPARATOR LIST SEPARATOR/STOP TRUE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
if(*(ControlStr+ControlIdx)==DOMAIN_NULL
|| ControlIdx>=DOMAIN_MAXLEN) // XXX Uhmmm isn't there a better way?
return FALSE;
DomainStatus=DOMAIN_CYCLE_CONTROL;
if(DomainSaveStatus!=DOMAIN_STATUS_LIST_NEGATE_STOP)
MatchIdx=MatchIdxSave;
else
MatchIdx++;
ControlStartIdx++;
break;
} else if(ControlStatus==DOMAIN_STATUS_LIST_SEPARATOR)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: SEPARATOR LIST SEPARATOR FALSE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
MatchIdx=MatchIdxSave;
DomainStatus=DOMAIN_CYCLE_CONTROL;
ControlStartIdx=ControlIdx+1u;
break;
} else if(SubStatus==STAR_STATUS_CONTINUE)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: FALSE SEPARATOR BUT STAR %d %d %d \n", DomainStatus,
ControlStatus, DomainSaveStatus);
#endif
MatchStatus=FALSE;
ControlStartIdx=specialflag;
if(DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE)
DomainStatus=FALSE;
else
DomainStatus=TRUE;
break;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: FALSE SEPARATOR %d %d %d %d %d %d %d\n", DomainStatus,
ControlStatus, DomainSaveStatus, SubStatus, ControlIdx, ControlStartIdx, MatchIdx);
#endif
return FALSE;
case DOMAIN_NULL:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: NULL %d %d %d %d %d %d %d\n",
DomainStatus, ControlStatus, DomainSaveStatus, SubStatus,
ControlIdx, ControlStartIdx, MatchIdx);
#endif
if(ControlStatus==DOMAIN_STATUS_END
&& (
(DomainStatus==TRUE && ControlIdx==ControlStartIdx)
|| (DomainSaveStatus==DOMAIN_STATUS_NEGATE_PARSE && ControlIdx!=ControlStartIdx)
|| DomainSaveStatus==DOMAIN_STATUS_STAR
|| DomainSaveStatus==DOMAIN_STATUS_HOME
)
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: NULL TRUE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
return TRUE;
} else if(DomainStatus==TRUE
&& ((DomainSaveStatus==DOMAIN_STATUS_LIST_SEPARATOR
&& ControlIdx==ControlStartIdx)
|| ( DomainSaveStatus==DOMAIN_STATUS_LIST_STOP
&& ControlIdx==ControlStartIdx+1u)))
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: NULL LIST SEPARATOR/STOP TRUE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
if(*(ControlStr+ControlIdx)==DOMAIN_NULL
|| ControlIdx>=DOMAIN_MAXLEN) // XXX Uhmmm isn't there a better way?
return TRUE;
MatchStatus=DOMAIN_STATUS_LIST_TRUE;
DomainStatus=DOMAIN_CYCLE_CONTROL;
break;
} else if((DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_SEPARATOR
&& (DomainStatus==TRUE || ControlIdx!=ControlStartIdx))
|| (DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP
&& (DomainStatus==TRUE || ControlIdx!=ControlStartIdx+1u))
)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: NULL LIST NEGATE SEPARATOR TRUE %d %d %d %d %d\n",
ControlStartIdx, ControlIdx, DomainSaveStatus, DomainStatus, MatchIdx);
#endif
if((*(ControlStr+ControlIdx)==DOMAIN_NULL || ControlIdx>=DOMAIN_MAXLEN)
&& DomainSaveStatus==DOMAIN_STATUS_LIST_NEGATE_STOP)
{
return TRUE;
}
//MatchStatus=DOMAIN_STATUS_LIST_TRUE;
DomainStatus=DOMAIN_CYCLE_CONTROL;
ControlStartIdx++;
if(DomainSaveStatus!=DOMAIN_STATUS_LIST_NEGATE_STOP)
MatchIdx=MatchIdxSave;
break;
} else if(ControlStatus==DOMAIN_STATUS_LIST_SEPARATOR)
{
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: NULL LIST SEPARATOR FALSE %d %d %d %d\n", DomainStatus,
ControlIdx, ControlStartIdx, DomainSaveStatus);
#endif
MatchIdx=MatchIdxSave;
DomainStatus=DOMAIN_CYCLE_CONTROL;
ControlStartIdx=ControlIdx+1u;
break;
}
return FALSE;
case DOMAIN_STAR:
case DOMAIN_NEGATION:
case DOMAIN_LIST_START:
case DOMAIN_LIST_SEPARATOR:
case DOMAIN_LIST_STOP:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: INVALID CHAR %d\n", DomainStatus);
#endif
return FALSE;
default:
switch(DomainSaveStatus)
{
case DOMAIN_STATUS_LIST_STOP:
case DOMAIN_STATUS_LIST_SEPARATOR:
case DOMAIN_STATUS_EQUAL:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: DEFAULT STATUS_EQUAL %d (%c) - %d (%c)\n", MatchIdx,
(unsigned int)*(MatchStr+MatchIdx),
ControlStartIdx, (unsigned int)*(ControlStr+ControlStartIdx));
#endif
if(*(MatchStr+MatchIdx)!=*(ControlStr+ControlStartIdx))
DomainStatus=FALSE;
//MatchStatus=FALSE;
ControlStartIdx++;
if(MatchIdx>=DOMAIN_MAXLEN-1)
{
if(DomainStatus==TRUE)
MatchStatus=TRUE;
}
break;
case DOMAIN_STATUS_LIST_NEGATE_STOP:
case DOMAIN_STATUS_LIST_NEGATE_SEPARATOR:
case DOMAIN_STATUS_NEGATE_PARSE:
if( ControlStartIdx>2u
&& DomainSaveStatus!=DOMAIN_STATUS_NEGATE_PARSE
&& (*(ControlStr+ControlStartIdx-2u)==DOMAIN_LIST_SEPARATOR
|| *(ControlStr+ControlStartIdx-2u)==DOMAIN_LIST_SEPARATOR)
&& flag==FALSE)
{
ControlStartIdx--;
}
if(DomainSaveStatus!=DOMAIN_STATUS_NEGATE_PARSE)
flag=TRUE;
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: DEFAULT STATUS_NEGATE_PARSE %d (%c) - %d (%c)\n",
MatchIdx, (unsigned int)*(MatchStr+MatchIdx),
ControlStartIdx, (unsigned int)*(ControlStr+ControlStartIdx));
#endif
if(*(MatchStr+MatchIdx)!=*(ControlStr+ControlStartIdx))
{
DomainStatus=TRUE;
if(ControlStartIdx>=ControlLen)
MatchStatus=TRUE;
}
ControlStartIdx++;
break;
case DOMAIN_STATUS_STAR:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: DEFAULT STATUS_STAR %d (%c)- %d (%c)\n",
MatchIdx, (unsigned int)*(MatchStr+MatchIdx),
ControlStartIdx, (unsigned int)*(ControlStr+ControlStartIdx));
#endif
DomainStatus=TRUE;
MatchStatus=FALSE;
if(ControlStatus==DOMAIN_STATUS_END)
return TRUE;
ControlStartIdx++;
break;
case DOMAIN_STATUS_LIST_STAR_STOP:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: DEFAULT LIST_STAR_STOP %d (%c)- %d (%c)\n",
MatchIdx, (unsigned int)*(MatchStr+MatchIdx),
ControlStartIdx, (unsigned int)*(ControlStr+ControlStartIdx));
#endif
if(ControlStatus==DOMAIN_STATUS_END)
return TRUE;
MatchStatus=TRUE;
break;
/*
case DOMAIN_STATUS_LIST_NEGATE_STOP:
*/
default:
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch Match: DEFAULT DEFAULT %d (%c) - %d (%c)\n",
MatchIdx, (unsigned int)*(MatchStr+MatchIdx),
ControlStartIdx, (unsigned int)*(ControlStr+ControlStartIdx));
#endif
return FALSE;
}
}
}
if(DomainStatus==DOMAIN_CYCLE_CONTROL)
ControlIdx++;
else if(DomainStatus!=DOMAIN_CYCLE_MATCH)
MatchIdx++;
}
#if defined(__GNUC__) && defined(DEBUG)
printf("DMDomainMatch RETURN OUTSIDE MAIN LOOP\n");
#endif
return MatchStatus;
}
#if defined(__GNUC__)
int main(int argc, char *argv[])
{
BYTE IsValidMatchStr;
if(argc < 3)
{
printf("Not enough parameters: argc = %d\n", argc);
printf("usage: %s <ControlStr> <MatchStr>\n", argv[0]);
return 1;
}
#if defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)
//ValidateDomainString((BYTE *)argv[1], (BYTE)DOMAIN_TYPE_CONTROL, (BYTE)DOMAIN_MAXLEN);
ValidateDomainString((BYTE *)argv[1], (BYTE)DOMAIN_TYPE_CONTROL, (BYTE)strlen((const char *)argv[1]));
#endif
#if defined(DOMAIN_VALIDATION_MATCH)
//ValidateDomainString((BYTE *)argv[2], (BYTE)DOMAIN_TYPE_MATCH, (BYTE)DOMAIN_MAXLEN);
ValidateDomainString((BYTE *)argv[2], (BYTE)DOMAIN_TYPE_MATCH, (BYTE)strlen((const char *)argv[2]));
#endif
IsValidMatchStr = DMDomainMatch((BYTE *)argv[1], // control
(BYTE *)argv[2], // match
(BYTE)strlen((const char*)argv[1])); //DOMAIN_MAXLEN);
printf( "%s\n", PRN_BOOL( IsValidMatchStr ) );
return 0;
}
#endif // __GNUC__
#endif // __DMDOMAIN_C_
/*
Copyright (c) 2012 Unixmedia S.r.l. <info@unixmedia.it>
Copyright (c) 2012 Franco (nextime) Lanza <franco@unixmedia.it>
Domotika System Domain utils header [http://trac.unixmedia.it]
This file is part of DMDomain.
DMDomain is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DMDOMAIN_H
#define __DMDOMAIN_H
#define DOMAIN_VALIDATION_MATCH
#define DOMAIN_VALIDATION_CONTROL
#define DOMAIN_VALIDATION_CONTROL_SAVE
#ifndef DOMAIN_MAXLEN
#define DOMAIN_MAXLEN (32u)
#endif
#if defined(__GNUC__)
typedef unsigned char BYTE;
#endif
#if defined(DOMAIN_VALIDATION_MATCH) || defined(DOMAIN_VALIDATION_CONTROL) || defined(DOMAIN_VALIDATION_CONTROL_SAVE)
#define DOMAIN_TYPE_MATCH (0x00)
#define DOMAIN_TYPE_CONTROL (0x01)
void ValidateDomainString(BYTE *DomainStr, BYTE DomainType, BYTE DomainLen);
#endif
BYTE DMDomainMatch(BYTE *ControlStr, BYTE *MatchStr, BYTE ControlLen);
#endif
PYINCLUDE=$(shell python-config --includes)
PYINSTALL_PATH=$(shell python -c 'import sys; print [ i for i in sys.path if i.endswith("-packages") ][0]')
MYSQL_LIB=$(shell mysql_config --cflags --libs)
MYSQL_PLUGINDIR=$(shell mysql_config --plugindir)
command:
gcc -Wall -o dmdomain DMDomain.c
all: lib python command
lib:
gcc -Wall -fPIC -c -o libdmdomain.o DMDomain.c
gcc -Wall -shared -o libdmdomain.so libdmdomain.o
pymodulegen:
python modulegen.py > _DMDomain.c
patch -p0 < _DMDomain_fix.patch
python: lib
gcc -Wall -fPIC ${PYINCLUDE} -c -o _DMDomain.o _DMDomain.c
gcc -Wall -shared -o _DMDomain.so -L. -ldmdomain _DMDomain.o
mysql: lib
gcc -Wall ${MYSQL_LIB} -ldmdomain -fPIC -shared -o mysql_udf_dmdomain.so mysql_udf_dmdomain.c
mysql_install: lib_install
install -m 0644 mysql_udf_dmdomain.so ${MYSQL_PLUGINDIR}
lib_install:
install -m 0644 libdmdomain.so /usr/lib
ldconfig
install: lib_install
install -m 0755 dmdomain /usr/bin/
mkdir -p ${PYINSTALL_PATH}/DMDomain
install -m 0644 _DMDomain.so ${PYINSTALL_PATH}/DMDomain/_DMDomain.so
install -m 0644 py/* ${PYINSTALL_PATH}/DMDomain/
debug:
gcc -Wall -DDEBUG -o dmdomain DMDomain.c
clean:
rm -f dmdomain
rm -f libdmdomain*
rm -f _DMDomain.o
rm -f *.so
create function DMDOMAIN returns INTEGER soname 'mysql_udf_dmdomain.so';
/* This file was generated by PyBindGen 0.15.0 */
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stddef.h>
#if PY_VERSION_HEX < 0x020400F0
#define PyEval_ThreadsInitialized() 1
#define Py_CLEAR(op) \
do { \
if (op) { \
PyObject *tmp = (PyObject *)(op); \
(op) = NULL; \
Py_DECREF(tmp); \
} \
} while (0)
#define Py_VISIT(op) \
do { \
if (op) { \
int vret = visit((PyObject *)(op), arg); \
if (vret) \
return vret; \
} \
} while (0)
#endif
#if PY_VERSION_HEX < 0x020500F0
typedef int Py_ssize_t;
# define PY_SSIZE_T_MAX INT_MAX
# define PY_SSIZE_T_MIN INT_MIN
typedef inquiry lenfunc;
typedef intargfunc ssizeargfunc;
typedef intobjargproc ssizeobjargproc;
#endif
#if __GNUC__ > 2
# define PYBINDGEN_UNUSED(param) param __attribute__((__unused__))
#elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
# define PYBINDGEN_UNUSED(param) __attribute__((__unused__)) param
#else
# define PYBINDGEN_UNUSED(param) param
#endif /* !__GNUC__ */
typedef enum _PyBindGenWrapperFlags {
PYBINDGEN_WRAPPER_FLAG_NONE = 0,
PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED = (1<<0),
} PyBindGenWrapperFlags;
#include "DMDomain.h"
/* --- module functions --- */
PyObject *
_wrap__DMDomainValidateDomainString(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs)
{
PyObject *py_retval;
BYTE *DomainStr;
BYTE DomainType;
BYTE DomainLen;
const char *keywords[] = {"DomainStr", "DomainType", "DomainLen", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "scc", (char **) keywords, &DomainStr, &DomainType, &DomainLen)) {
return NULL;
}
ValidateDomainString(DomainStr, DomainType, DomainLen);
Py_INCREF(Py_None);
py_retval = Py_None;
return py_retval;
}
PyObject * _wrap__DMDomainValidateDomainString(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs);
PyObject *
_wrap__DMDomainDMDomainMatch(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs)
{
PyObject *py_retval;
BYTE retval;
BYTE *ControlStr;
BYTE *MatchStr;
BYTE ControlLen;
const char *keywords[] = {"ControlStr", "MatchStr", "ControlLen", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "ssc", (char **) keywords, &ControlStr, &MatchStr, &ControlLen)) {
return NULL;
}
retval = DMDomainMatch(ControlStr, MatchStr, ControlLen);
py_retval = Py_BuildValue((char *) "c", (int) retval);
return py_retval;
}
PyObject * _wrap__DMDomainDMDomainMatch(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs);
static PyMethodDef _DMDomain_functions[] = {
{(char *) "ValidateDomainString", (PyCFunction) _wrap__DMDomainValidateDomainString, METH_KEYWORDS|METH_VARARGS, NULL },
{(char *) "DMDomainMatch", (PyCFunction) _wrap__DMDomainDMDomainMatch, METH_KEYWORDS|METH_VARARGS, NULL },
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
#if defined(__GNUC__) && __GNUC__ >= 4
__attribute__ ((visibility("default")))
#endif
init_DMDomain(void)
{
PyObject *m;
m = Py_InitModule3((char *) "_DMDomain", _DMDomain_functions, NULL);
if (m == NULL) {
return;
}
}
--- _DMDomain.c 2012-07-02 01:22:25.000000000 +0200
+++ aaa.c 2012-07-02 01:22:19.000000000 +0200
@@ -65,9 +65,9 @@
_wrap__DMDomainValidateDomainString(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs)
{
PyObject *py_retval;
- char *DomainStr;
- char DomainType;
- char DomainLen;
+ BYTE *DomainStr;
+ BYTE DomainType;
+ BYTE DomainLen;
const char *keywords[] = {"DomainStr", "DomainType", "DomainLen", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "scc", (char **) keywords, &DomainStr, &DomainType, &DomainLen)) {
@@ -85,10 +85,10 @@
_wrap__DMDomainDMDomainMatch(PyObject * PYBINDGEN_UNUSED(dummy), PyObject *args, PyObject *kwargs)
{
PyObject *py_retval;
- char retval;
- char *ControlStr;
- char *MatchStr;
- char ControlLen;
+ BYTE retval;
+ BYTE *ControlStr;
+ BYTE *MatchStr;
+ BYTE ControlLen;
const char *keywords[] = {"ControlStr", "MatchStr", "ControlLen", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "ssc", (char **) keywords, &ControlStr, &MatchStr, &ControlLen)) {
File added
#! /usr/bin/env python
import sys
import pybindgen
from pybindgen import ReturnValue, Parameter, Module, Function, FileCodeSink
def my_module_gen(out_file):
mod = Module('_DMDomain')
mod.add_include('"DMDomain.h"')
mod.add_function('ValidateDomainString', None, [
Parameter.new('char*', 'DomainStr', transfer_ownership=False),
Parameter.new('char', 'DomainType'),
Parameter.new('char', 'DomainLen')])
mod.add_function('DMDomainMatch', 'char', [
Parameter.new('char*', 'ControlStr', transfer_ownership=False),
Parameter.new('char*', 'MatchStr', transfer_ownership=False),
Parameter.new('char', 'ControlLen')])
mod.generate(FileCodeSink(out_file) )
if __name__ == '__main__':
my_module_gen(sys.stdout)
/* Copyright (c) 2012, Franco (nextime) Lanza (nextime@nexlab.it). All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifdef STANDARD
/* STANDARD is defined, don't use any mysql functions */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
typedef long long longlong;
#endif /*__WIN__*/
#else
#include <my_global.h>
#include <my_sys.h>
#if defined(MYSQL_SERVER)
#include <m_string.h> /* To get strmov() */
#else
/* when compiled as standalone */
#include <string.h>
#define strmov(a,b) stpcpy(a,b)
#define bzero(a,b) memset(a,0,b)
#endif
#endif
#include <mysql.h>
#include <ctype.h>
#ifdef _WIN32
/* inet_aton needs winsock library */
#pragma comment(lib, "ws2_32")
#endif
#ifdef HAVE_DLOPEN
#include "DMDomain.h"
my_bool DMDOMAIN_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
longlong DMDOMAIN(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
void DMDOMAIN_deinit(UDF_INIT *initid);
typedef struct _DMDOMAINS
{
BYTE FirstStr[DOMAIN_MAXLEN];
unsigned long firstlen;
BYTE SecondStr[DOMAIN_MAXLEN];
unsigned long secondlen;
int Reversed;
int FirstIdx;
int SecondIdx;
} DOMAIN_STRUCT;
my_bool DMDOMAIN_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
DOMAIN_STRUCT DomainData;
if (args->arg_count != 2
|| args->arg_type[0] != STRING_RESULT
|| args->arg_type[1] != STRING_RESULT
|| (!args->args[1] && !args->args[0])
)
{
strcpy(message,"DMDOMAIN require 2 string arguments -> DMDOMAIN(matchdomain,controldomain)");
return 1;
}
initid->maybe_null=1;
initid->decimals=0;
initid->max_length=1;
if(args->args[1])
{
// FirstStr is the Control with wildcards
// SecondStr is the Match
DomainData.Reversed=0;
DomainData.FirstIdx=1;
DomainData.SecondIdx=0;
} else {
// SecondStr is the Control with wildcards
// FirstStr is the Match
DomainData.Reversed=1;
DomainData.FirstIdx=0;
DomainData.SecondIdx=1;
}
if( !(initid->ptr = (char *) malloc( sizeof(DomainData) ))) {
strcpy(message,"Couldn't allocate memory!");
return 1;
}
DomainData.firstlen=args->lengths[DomainData.FirstIdx];
if(DomainData.firstlen>DOMAIN_MAXLEN)
DomainData.firstlen=DOMAIN_MAXLEN;
else if(DomainData.firstlen<DOMAIN_MAXLEN)
DomainData.FirstStr[DomainData.firstlen]='\0';
memcpy((char*)DomainData.FirstStr,args->args[DomainData.FirstIdx],(size_t)DomainData.firstlen);
if(DomainData.Reversed) {
ValidateDomainString((BYTE *)DomainData.FirstStr,
(BYTE)DOMAIN_TYPE_MATCH, (BYTE)DomainData.firstlen);
} else {
ValidateDomainString((BYTE *)DomainData.FirstStr,
(BYTE)DOMAIN_TYPE_CONTROL, (BYTE)DomainData.firstlen);
}
//strcpy(message, (const char*)DomainData.FirstStr);
//return 1;
memcpy((char*)initid->ptr, (char*)&DomainData, sizeof(DomainData));
return 0;
}
void DMDOMAIN_deinit(UDF_INIT *initid __attribute__((unused)))
{
if (initid->ptr)
free(initid->ptr);
}
longlong DMDOMAIN(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
DOMAIN_STRUCT DomainData;
memcpy((char*)&DomainData, (char*)initid->ptr, sizeof(DomainData));
DomainData.secondlen=args->lengths[DomainData.SecondIdx];
if(DomainData.secondlen>DOMAIN_MAXLEN)
DomainData.secondlen=DOMAIN_MAXLEN;
else if(DomainData.secondlen<DOMAIN_MAXLEN)
DomainData.SecondStr[DomainData.secondlen]='\0';
memcpy((char*)DomainData.SecondStr,
args->args[DomainData.SecondIdx], (size_t)DomainData.secondlen);
if(DomainData.Reversed) {
ValidateDomainString((BYTE *)DomainData.SecondStr,
(BYTE)DOMAIN_TYPE_CONTROL, (BYTE)DomainData.secondlen);
if(DMDomainMatch((BYTE *)DomainData.SecondStr, (BYTE *)DomainData.FirstStr,
(BYTE)strlen((const char*)DomainData.SecondStr)))
return 1;
} else {
ValidateDomainString((BYTE *)DomainData.SecondStr,
(BYTE)DOMAIN_TYPE_MATCH, (BYTE)DomainData.secondlen);
if(DMDomainMatch((BYTE *)DomainData.FirstStr, (BYTE *)DomainData.SecondStr,
(BYTE)strlen((const char*)DomainData.FirstStr)))
return 1;
}
return 0;
}
#endif /* HAVE_DLOPEN */
import struct
import _DMDomain
import copy
DOMAIN_TYPE_MATCH="\x00"
DOMAIN_TYPE_CONTROL="\x01"
def ValidateDomainString(DomainStr, DomainType, DomainLen):
_DMDomain.ValidateDomainString(DomainStr, DomainType, struct.pack('<B', DomainLen))
stend=DomainStr.find("\x00")
if stend==-1:
stend=len(DomainStr)
if stend > 32:
stend=32
DomainStr=copy.deepcopy(DomainStr[0:stend])
return DomainStr
def DMDomainMatch(ControlStr, MatchStr, ControlLen):
return bool(struct.unpack('<B',
_DMDomain.DMDomainMatch(ControlStr, MatchStr, struct.pack('<B',ControlLen)))[0])
#!/bin/bash
##################################################################
# Copyright (c) 2012 Unixmedia S.r.l. <info@unixmedia.it>
# Copyright (c) 2012 Franco (nextime) Lanza <franco@unixmedia.it>
#
# Domotika System Domain unit tester [http://trac.unixmedia.it]
#
# This file is part of DMDomain.
#
# DMDomain is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################
ERED='\e[1;31m'
NO_COLOR='\e[0m'
EGREEN='\e[1;32m'
EYELLOW='\e[1;33m'
EBLUE='\e[1;34m'
EMAGENTA='\e[1;35m'
ECYAN='\e[1;36m'
EWHITE='\e[1;37m'
DEBUG="n"
echo
echo -e "$EWHITE\t\t DOMOTIKA DOMAIN TESTER \t\t$NO_COLOR\n"
if [ -f Makefile ] ; then
make clean
make debug
echo
fi
if [ \! -f ./dmdomain ] ; then
echo "dmdomain binary not found"
exit 1
fi
TCOLS=$(stty -a | tr -s ';' '\n' | grep "column" | sed s/'[^[:digit:]]'//g)
PBMIN=0 # progressbar min value
PBMAX=100 # progressbar max value
PBSYM="=" # symbol used for building the progressbar
PBPERCLEN=7 # length of % string, i.e. "[100%] " => 7 chars
# create the progressbar
function GetPBLine()
{
PBVAL=$1 # current progressbar value (function param)
RVAL=$2
PBUCOLS=$(($TCOLS-$PBPERCLEN-7)) # usable columns
PBNUM=$((($PBVAL*$PBUCOLS)/($PBMAX-$PBMIN)))
for((j=0; j<$PBNUM; j++)); do
PBLINE="$PBLINE$PBSYM"
done
PBPERC=$(printf "[%3d%%] " $PBVAL) # i.e. "[ 12%] "
echo -e "${EBLUE}$PBPERC$PBLINE> $2${NO_COLOR}\r"
echo -ne "\033[K$3 $4 $5 $6\r"
echo -ne "\033[1A\r"
}
c=0
o=0
e=0
p=0
RES=""
FILE=$1
if [ x"$1" = x"verbose" ] ; then
FILE=$2
fi
if [ x"$1" = x"debug" ] ; then
FILE=$2
DEBUG="y"
fi
if [ x"$FILE" = x"" ] ; then
FILE="tests/*.list"
else
if [ \! -f $FILE ] ; then
echo "File $FILE doesn't exists"
exit 0
fi
fi
echo -ne "$(GetPBLine $p $c 'Starting...')\r"
tot=`cat $FILE | grep -v "^#" | grep -v "^$" | wc -l`
for i in `cat $FILE | grep -v "^#" | grep -v "^$" `
do
c=$[ c+1 ]
uno=`echo $i | awk -F ':' '{print $1}'`
due=`echo $i | awk -F ':' '{print $2}'`
tre=`echo $i | awk -F ':' '{print $3}'`
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ./dmdomain' \'${uno}\' \'${due}\')\r"
totprova=$(./dmdomain "${uno}" "${due}")
prova=`echo -en "$totprova" | tail -n 1`
if [ "$DEBUG" = "y" ] ; then
echo -en "\n\n DEBUG: \n $totprova \n ------------- \n"
fi
if [ ${prova} != ${tre} ] ; then
RES="${RES}\n${ERED}ERROR: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $prova${EWHITE} (need: $tre)${NO_COLOR}| ./dmdomain '${uno}' '${due}'"
e=$[ e+1 ]
else
o=$[ o+1 ]
if [ "$1" = "verbose" ] || [ "$1" = "debug" ] ; then
RES="${RES}\n${EGREEN}OK: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $prova${EWHITE} (need: $tre)${NO_COLOR}| ./dmdomain '${uno}' '${due}'"
fi
fi
if [ "$DEBUG" = "y" ] ; then
echo -e "$RES"
RES=""
fi
p=$[ c*100/tot ]
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ./dmdomain' ${uno} ${due})\r"
done
echo -ne "$(GetPBLine 100 $c 'Done.')\r"
echo
echo -ne ${RES}
echo
echo "------------------------------------"
echo "FINAL REPORT:"
echo
pok=$[ o*100/tot ]
per=$[ 100-pok ]
echo -e " TESTS:$ECYAN $c$NO_COLOR - OK:$EGREEN $o ($pok%)$NO_COLOR ERRORS:$ERED $e ($per%)$NO_COLOR"
echo
echo "------------------------------------"
#!/bin/bash
##################################################################
# Copyright (c) 2012 Unixmedia S.r.l. <info@unixmedia.it>
# Copyright (c) 2012 Franco (nextime) Lanza <franco@unixmedia.it>
#
# Domotika System Domain unit tester [http://trac.unixmedia.it]
#
# This file is part of DMDomain.
#
# DMDomain is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################
ERED='\e[1;31m'
NO_COLOR='\e[0m'
EGREEN='\e[1;32m'
EYELLOW='\e[1;33m'
EBLUE='\e[1;34m'
EMAGENTA='\e[1;35m'
ECYAN='\e[1;36m'
EWHITE='\e[1;37m'
DEBUG="n"
echo
echo -e "$EWHITE\t\t DOMOTIKA DOMAIN TESTER \t\t$NO_COLOR\n"
TCOLS=$(stty -a | tr -s ';' '\n' | grep "column" | sed s/'[^[:digit:]]'//g)
PBMIN=0 # progressbar min value
PBMAX=100 # progressbar max value
PBSYM="=" # symbol used for building the progressbar
PBPERCLEN=7 # length of % string, i.e. "[100%] " => 7 chars
# create the progressbar
function GetPBLine()
{
PBVAL=$1 # current progressbar value (function param)
RVAL=$2
PBUCOLS=$(($TCOLS-$PBPERCLEN-7)) # usable columns
PBNUM=$((($PBVAL*$PBUCOLS)/($PBMAX-$PBMIN)))
for((j=0; j<$PBNUM; j++)); do
PBLINE="$PBLINE$PBSYM"
done
PBPERC=$(printf "[%3d%%] " $PBVAL) # i.e. "[ 12%] "
echo -e "${EBLUE}$PBPERC$PBLINE> $2${NO_COLOR}\r"
echo -ne "\033[K$3 $4 $5 $6\r"
echo -ne "\033[1A\r"
}
c=0
o=0
e=0
p=0
RES=""
FILE="tests/*.list"
echo -ne "$(GetPBLine $p $c 'Starting...')\r"
tot=`cat $FILE | grep -v "^#" | grep -v "^$" | wc -l`
for i in `cat $FILE | grep -v "^#" | grep -v "^$" `
do
c=$[ c+1 ]
uno=`echo $i | awk -F ':' '{print $1}'`
due=`echo $i | awk -F ':' '{print $2}'`
tre=`echo $i | awk -F ':' '{print $3}'`
#echo -ne "$(GetPBLine $p $c 'RUNNING TEST:' \'$uno\' \'$due\')\r "
totprova=$(mysql -u$1 -p$2 -e "SELECT IF((select DMDOMAIN('${due}', '${uno}')), TRUE, FALSE)" domotika | tail -n 1)
if [ "$totprova" = "0" ] ; then
provata="False"
else
provata="True"
fi
if [ ${provata} != ${tre} ] ; then
RES="${RES}\n${ERED}ERROR: ${EYELLOW}$uno ${ECYAN}$due${EMAGENTA} -> $provata${EWHITE} (need: $tre)${NO_COLOR}"
e=$[ e+1 ]
#echo
#echo
#echo
#echo $(mysql -u$1 -p$2 -e "SELECT IF((select DMDOMAIN('${due}', '${uno}')), TRUE, FALSE)" domotika )
else
o=$[ o+1 ]
fi
p=$[ c*100/tot ]
echo -ne "$(GetPBLine $p $c 'RUNNING TEST: ' \'$uno\' \'$due\')\r"
done
echo -ne "$(GetPBLine 100 $c 'Done.')\r"
echo
echo -ne ${RES}
echo
echo "------------------------------------"
echo "FINAL REPORT:"
echo
pok=$[ o*100/tot ]
per=$[ 100-pok ]
echo -e " TESTS:$ECYAN $c$NO_COLOR - OK:$EGREEN $o ($pok%)$NO_COLOR ERRORS:$ERED $e ($per%)$NO_COLOR"
echo
echo "------------------------------------"
test:tesa:False
test:testa:False
tes:test:False
test:test:True
test:test.a:False
test.a:test.a:True
test.a:test.ab:False
test.aaa:test.a:False
tes.aaa:test:False
tes:test:False
testa.aaa:test:False
testa:test:False
test.aaa.due:test.aaa:False
test.aaa:test.aaa.due:False
test.aaa:test:False
test..:test:True
test.:test:True
test.:test.:True
test:test.:True
uno.due.tre.quattro:uno.tre.due.quattro:False
uno.due.tre.quattro:uno.due.tre.quattro:True
uno.due.tre.quattro:uno.due.tre:False
uno.due.tre:uno.due.tre.quattro:False
uno.due.tre:uno.due.t:False
uno.due.tre:uno.due.tree:False
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:True
luce.taverna.salagiochi.centrale:luce.taverna.sala.centrale:False
[uno|due]:uno:True
[antani|sarca]:sarca:True
[sarca|antani]:sarca:True
[uno|due]:due:True
[uno|due]:tre:False
[uno]:uno:True
[uno|due|tre]:tre:True
[uno|due|tre]:uno:True
[uno|due|tre]:due:True
[uno|due|tre]:uno.due.tre:False
[uno|due|tre]:un:False
[uno|due|tre]:du:False
[uno|due|tre]:tr:False
[uno|due|tre]:aa:False
[uno|due]:un:False
[uno|due|]:uno:True
[uno|due|]:due:True
[uno].due:due:False
[uno].due:uno:False
[uno].due:uno.due:True
[uno].due:due.due:False
[uno.due]:uno:True
[uno.due]:due:False
[uno|due].tre:uno.tre:True
[uno|due].tre:due.tre:True
[uno|due].tre:un.tre:False
[uno|due].tre:unoo.tre:False
[uno|due].tre.quattro:uno.tre.quattro:True
[uno|due].tre.quattro:due.tre:False
[uno|due].tre.quattro:due.tre.quattro:True
[uno|due].due.[tre|ant].rim:uno.due.tre.rim:True
!:*:False
*:a]:True
*.!*:antani.sarca.pippo:True
!test.aaa.[*].![aa|sarca].[antani|sarca]:sarca.aaa.f.bb.anta:True
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:True
[*].[*].!anta.[sa|pt].![pt|aa].*:pro.o.en.sa.ff.htyf.mg:True
[*].[*].!anta.[sa|pt].![pt|aa].*:pro.o.en.a.ff.htyf.mg:False
prova.![sarca|sarc].pippo.a:prov.swefe.pippo.a:False
prov.![sarca|sarc].pippo.a:prov.swefe.pippo.a:True
luce.![sarca|antani]:luce.antani:False
luce.![sarca|antani]:luce.sarca:False
*.!padr.*:tapp.p1.camera.padr.ovest:False
*.padr.*:tapp.p1.camera.padre.ovest:False
*.!padr.*:tapp.p1.camera.padre.ovest:True
*.!padr.*:tapp.pt.ufficio:True
*.!padr.anta:app.pt.ufficio:False
*.!padr.anta:app.pt.ufficio.sar:False
*.!padr.anta:app.pt.padr:False
*.!padr.anta:app.pt.padr.anta:False
*.!padr.anta:app.pt.pad.anta:True
*.!padr.anta:app.pt.padrr.anta:True
*.!padr.anta:app.pt.pade.anta:True
*.!padr.anta:app.pt.pade.antr:False
*.!padr:tapp.p1.camera.padr.ovest:True
*.!padr:tapp.p1.camera.eee:True
*.![padr|pade]:tapp.p1.camera.eee:True
*.![padr|pade]:tapp.p1.camera.pade:False
*.![padr|pade]:tapp.p1.camera.pad:True
*.![padr|pade]:tapp.p1.camera.padr:False
*.![padr|pade]:tapp.p1.camera.padre:True
*.![padr|pade].*:tapp.p1.camera.padr.ovest:False
*.![padr|pade].*:tapp.p1.camera.padre.ovest:True
*.![padr|pade].*:tapp.p1.pade.padre.ovest:False
*.[uno|due].*:prova.uno.cinque:True
*.[uno|due].*:prova.due.cinque:True
*.[uno|due|tre].*:prova.due.cinque:True
*.[uno|due|tre].*:prova.uno.cinque:True
*.[uno|due|tre].*:prova.tre.cinque:True
*.[sarca|prova].*:prova.due.cinque:False
test.!a:test.a:False
luce.!antani:luce.antani:False
test.!aa:test.d:True
test.!:test:True
test.!:test.!:True
test.!a:test.d:True
test.!aa:test.d:True
test.!aa:test.aa:False
test.!aa:test.a:True
test.!ab:test.ac:True
test.!aaa:test.aab:True
test.!aaa:test.aa:True
test.!aa:test.aaa:True
test.!aa:test.!aaa:False
test.!:test.!aaa:True
test.!aa:test.aba:True
test.!aa:test.aab:True
test.!aa:test.ab.aaa:False
test.!aa:test.ab:True
test.!aa.due:test.aief.due:True
test.!aa.due:test.aa.due:False
test.!aa.due:test.a.due:True
!test:test:False
!test:anta:True
!test.anta:test.anta:False
!test.!anta:anta.test:True
!test.!anta:!anta.test:False
!test.!anta:sarca.biga:True
!test.!anta:!test.!anta:False
!123456789A123456789B123456789C1:123456789A123456789B123456789C1:False
!123456789A123456789B123456789C1:123456789A123456789B123456789C12:True
!123456789A123456789B123456789C1:123456789A123456789B123456789C1X:True
!123456789A123456789B123456789C1:123456789A123456789B123456789CX:True
uno.!due.tre.!quattro:uno.due.tre.qua:False
uno.!due.tre.!quattro:uno.due.tre.quattro:False
uno.!due.tre.!quattro:uno.due.tre.quattroo:False
uno.!due.tre.!quattro:uno.tre:False
!uno.!due.!tre.!quattro:quattro.tre.due.uno:True
![uno|due]:uno:False
![uno|due]:due:False
![uno|due]:tre:True
![uno]:uno:False
![uno].tre:un.tre:True
![uno].tre:unoo.tre:True
![uno|due].tre:uni.tre:True
![uno|due|tre]:tre:False
![uno|due|tre]:uno:False
![uno|due|tre]:due:False
![uno|due|tre]:uno.due.tre:False
![uno|due|tre]:un:True
![uno|due|tre]:du:True
![uno|due|tre]:tr:True
![uno|due|tre]:aa:True
![aaa|bbb|ccc].tre:ccc.tre:False
![aaa|bbb|ccc].tre:bbb.tre:False
![aaa|bbb|ccc].tre:aaa.tre:False
![uno|due]:un:True
![uno|due|]:uno:False
![uno|due|]:due:False
![uno].due:due:False
![uno].due:uno:False
![uno].due:uno.due:False
![uno].due:due.due:True
![uno.due]:uno:False
![uno.due]:due:True
![uno|due].tre:uno.tre:False
![uno|due].tre:due.tre:False
![uno|due].tre:un.tre:True
![uno|due].tre:unoo.tre:True
![uno|due].tre.quattro:uno.tre.quattro:False
![uno|due].tre.quattro:due.tre:False
![uno|due].tre.quattro:due.tre.quattro:False
![uno].![due|tre].![aaa|bbb|ccc|ddd]:aaa.bbb.due.tre:False
![uno].![due|tre].![aaa|bbb|ccc|ddd]:aaa.bbb.due:True
![uno].![due|tre].![aaa|bbb|ccc|due]:aaa.bbb.ccc:False
![uno].![due|tre].![aaa|bbb|ccc|ddd]:aaa.tre.due:False
![uno].![due|tre].![aaa|bbb|ccc|ddd]:aa.bb.du:True
![uno].![due|tre].![aaa|bbb|ccc|ddd]:aaaf.bbbe.due:True
*::False
*:anta:True
*:antani.sarca:True
*:anta.*:True
*:!:False
*:a]:True
.*::False
.*:a:False
*.prova:a:False
*.prova:a.anta.sarca.prova:True
*.prova:prova:False
*.prova:a.prova:True
*.prova:antani.prova:True
*.prova:tani.provaz:False
*.prova:tani.pro:False
antani*.prova:antani.prova:False
antani*.prova:antani*.prova:True
antani*.prova:antani:True
antani.*:antani.prova:True
antani.*.*.sarca:antani.prova.pippo.ciao:False
*.*:antani:True
*.*.antani:antani:False
*.*:antani.sarca:True
*.*:antani.sarca.pippo:True
*.!*:antani.sarca.pippo:True
*.prova:a.kprovdkk:False
*.prova:a.pro:False
*.prova:a.provd:False
*.a:aa.b.b.b.b.b.b.b.b.b.b.b.b.b.b.a:True
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.*:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b:True
*:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b:True
*.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b:False
*.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:b.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:True
*.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:False
*.aaa:ccc.aaaaaaaaaaaaaaaaaaaaaaaaaaaa:False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment