bool AdBlockRule::networkMatch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &encodedUrl) const
{
    if (m_type == CssRule || !m_isEnabled || m_isInternalDisabled) {
        return false;
    }

    bool matched = stringMatch(domain, encodedUrl);

    if (matched) {
        // Check domain restrictions
        if (hasOption(DomainRestrictedOption) && !matchDomain(request.firstPartyUrl().host())) {
            return false;
        }

        // Check third-party restriction
        if (hasOption(ThirdPartyOption) && !matchThirdParty(request)) {
            return false;
        }

        // Check object restrictions
        if (hasOption(ObjectOption) && !matchObject(request)) {
            return false;
        }

        // Check subdocument restriction
        if (hasOption(SubdocumentOption) && !matchSubdocument(request)) {
            return false;
        }

        // Check xmlhttprequest restriction
        if (hasOption(XMLHttpRequestOption) && !matchXmlHttpRequest(request)) {
            return false;
        }

        // Check image restriction
        if (hasOption(ImageOption) && !matchImage(request)) {
            return false;
        }

        // Check script restriction
        if (hasOption(ScriptOption) && !matchScript(request)) {
            return false;
        }

        // Check stylesheet restriction
        if (hasOption(StyleSheetOption) && !matchStyleSheet(request)) {
            return false;
        }

        // Check object-subrequest restriction
        if (hasOption(ObjectSubrequestOption) && !matchObjectSubrequest(request)) {
            return false;
        }
    }

    return matched;
}
Exemple #2
0
void GetWfdiscInfo ( struct wfdiscList *wf, char *sta , char *chan ,
		     int ondate , int offdate , char * inst ) 
{
    strcpy ( inst , "-" ) ;

    if ( !wf )
	return ;

    while ( wf ) {
	if ( stringMatch ( sta , wf->element->sta , 5 ) &&
	     stringMatch ( chan, wf->element->chan, 3 ) &&
	     ondate  <= wf->element->jdate &&
	     offdate >= wf->element->jdate ) {
		strcpy ( inst , wf->element->instype ) ;
		return ;
	}

	wf = wf->next ;
    }
} /* end GetWfdiscInfo */
bool AdBlockRule::urlMatch(const QUrl &url) const
{
    if (!hasOption(DocumentOption) && !hasOption(ElementHideOption)) {
        return false;
    }


    const QString encodedUrl = url.toEncoded();
    const QString domain = url.host();

    return stringMatch(domain, encodedUrl);
}
Exemple #4
0
void GetChannelInfo(struct sitechanList *sc, char *Station, char *comp,
                    double *hang, double *vang)
{
    *hang = nullSitechan.hang ;
    *vang = nullSitechan.vang ;

    if(!sc) 
	return;

    while(sc){
	if( stringMatch (Station, sc->element->sta, 5 ) &&
	    stringMatch (comp , sc->element->chan , 3 ) ) {
	    *hang = sc->element->hang;
	    *vang = sc->element->vang;
	    return;
	}

	sc = sc->next;
    }

} /* end GetChannelInfo */
Exemple #5
0
static Result
stringSearch(
    const Byte* buf,
    size_t      len,
    const char* test,
    size_t      tlen,
    size_t*     offset,
    size_t      limit,
    int         flags
)
{
    // Search for the string up to limit characters beyond the offset.
    // len - tlen is the last position at which a match is possible.
    // Ranges are exclusive at the right.
    Result  rslt;
    size_t  start = *offset;
    size_t  last;
    size_t  end = start + limit;

    if (start >= len || tlen > len)
    {
        return Error;
    }

    last = len - tlen + 1;

    if (end >= last)
    {
        end = last;
    }

    for (; start < end; ++start)
    {
        // stringMatch will update this to the end of the match
        *offset = start;

        rslt = stringMatch(buf, len, test, tlen, offset, CompareEq, flags);

        if (rslt != Fail)
        {
            return rslt;
        }
    }

    return Error;
}
Exemple #6
0
static void directivePragma (int c)
{
	if (cppIsident1 (c))
	{
		readIdentifier (c, Cpp.directive.name);
		if (stringMatch (vStringValue (Cpp.directive.name), "weak"))
		{
			/* generate macro tag for weak name */
			do
			{
				c = getcAndCollect ();
			} while (c == SPACE);
			if (cppIsident1 (c))
			{
				readIdentifier (c, Cpp.directive.name);
				makeDefineTag (vStringValue (Cpp.directive.name), NULL, false);
			}
		}
	}
	Cpp.directive.state = DRCTV_NONE;
}
Exemple #7
0
void GetSiteInfo ( struct siteList *si , char *sta , int ondate ,
		   int offdate, float *lat , float *lon , float *elev )
{
    *lat = *lon = *elev = -999.0 ;

    if ( !si )
	return ;

    while ( si ) {
	if ( stringMatch ( sta , si->element->sta , 5 ) &&
	     ondate == si->element->ondate &&
	     offdate == si->element->offdate ) {
		*lat = si->element->lat ;
		*lon = si->element->lon ;
		*elev = si->element->elev ;
		return ;
	}

	si = si->next ;
    }

} /* end GetSiteInfo */
 CompletionType evaluate()
 {
     Register<Value> value;
     switch (method)
     {
     case ToString:
     case ValueOf:
         if (!getThis()->isObject())
         {
             throw getErrorInstance("TypeError");
         }
         value = static_cast<ObjectValue*>(getThis())->getValueProperty();
         if (!value->isString())
         {
             throw getErrorInstance("TypeError");
         }
         break;
     case CharAt:
         value = charAt();
         break;
     case CharCodeAt:
         value = charCodeAt();
         break;
     case Concat:
         value = concat(getThis());
         break;
     case IndexOf:
         value = indexOf(getThis());
         break;
     case LastIndexOf:
         value = lastIndexOf(getThis());
         break;
     case LocaleCompare:
         value = localeCompare(getThis());
         break;
     case Match:
         value = stringMatch();
         break;
     case Replace:
         value = stringReplace();
         break;
     case Search:
         value = stringSearch();
         break;
     case Slice:
         value = slice(getThis());
         break;
     case Split:
         value = stringSplit();
         break;
     case Substring:
         value = substring(getThis());
         break;
     case Substr:
         value = substr(getThis());
         break;
     case ToLowerCase:
     case ToLocaleLowerCase:
         value = toLowerCase(getThis());
         break;
     case ToUpperCase:
     case ToLocaleUpperCase:
         value = toUpperCase(getThis());
         break;
     }
     return CompletionType(CompletionType::Return, value, "");
 }
Exemple #9
0
int main(int argc, char *argv[])
{
    
    //setHttpAuth("admin:admin");
    //setHttpData("{\"ins_api\":{\"version\":\"1.2\",\"type\":\"cli_show\",\"chunk\":\"0\",\"sid\":\"1\",\"input\":\"show version\",\"output_format\":\"json\"}}");
    //appendHttpHeader("Content-Type: application/json");
    //printf("%s\n",httpFunction("http://192.168.113.50/ins"));
    OV_Version = OV200;
    char *oneViewAddress;
    //main2();
    //sleep(40);

    // Check for Debug Mode
    if (getenv("OV_DEBUG")) {
        debug = 1; // debug mode enabled
    } else {
        debug = 0; // debug mode disabled
    }

    
    // Peform an initial check to see what parameters have been passed
    char path[100];
    if (argc >1) {
        oneViewAddress = argv[1];
        if (is_valid_ip(oneViewAddress)) {
            // Create a string based upon the path to the sessionID
            identifySystem(oneViewAddress);
            sprintf(path, "/.%s_ov",oneViewAddress);
        } else {
            printMessage(YELLOW, "DEBUG", "Invalid IP Address");
            return 1;
        }
    }
    if(argc < 3)
    {
        printMessage(YELLOW, "DEBUG", "No parameters passed");
        fprintf(stderr, "usage: %s ADDRESS COMMAND <parameters>\n", argv[0]);
        // Somewhat over the top logo
        fprintf(stderr, " \
                _   _ ____     ___           __     ___\n\
                | | | |  _ \\   / _ \\ _ __   __\\ \\   / (_) _____      __\n\
                | |_| | |_) | | | | | '_ \\ / _ \\ \\ / /| |/ _ \\ \\ /\\ / /\n\
                |  _  |  __/  | |_| | | | |  __/\\ V / | |  __/\\ V  V /\n\
                |_| |_|_|      \\___/|_| |_|\\___| \\_/  |_|\\___| \\_/\\_/  \n\n");
        //Print the relevant helps
        ovCreatePrintHelp();
        ovShowPrintHelp();
        ovCopyPrintHelp();
        ovMessageBusHelp();
        return 1;
    }
 
    char url[URL_SIZE];
    char *httpData;
    json_t *root = NULL;
    json_error_t error;

    // Determine the action to be executed

    if (stringMatch(argv[2], "LOGIN")) {
        // Login to HP OneView
        SetHttpMethod(DCHTTPPOST);
        ovLogin(argv, path);
        return 0;
    } else if (stringMatch(argv[2], "SHOW")) {
        // Show/Query information from HP OneView
        char *sessionID = readSessionIDforHost(path);
        if (!sessionID) {
            printf("[ERROR] No session ID\n");
            return 1;
        }
        ovShow(sessionID, argc, argv);
        return 0; // return sucess

    } else if (stringMatch(argv[2], "CREATE")) {
        char *sessionID = readSessionIDforHost(path);
        if (!sessionID) {
            printf("[ERROR] No session ID\n");
            return 1;
        }
        ovCreate(sessionID, argv);
        return 0; // Return success
    } else if (strstr(argv[2], "COPY")) {
    
        char *sessionID = readSessionIDforHost(path);
        if (!sessionID) {
            printf("[ERROR] No session ID\n");
            return 1;
        }
        ovCopy(sessionID, argv);
        return 0; //return success
    } else if (strstr(argv[2], "CLONE")) {
        char *sessionID = readSessionIDforHost(path);
        if (!sessionID) {
            printf("[ERROR] No session ID");
            return 1;
        }
        
        // DEBUG OVID output
        //printf("[DEBUG] OVID:\t  %s\n",sessionID);
        if (strstr(argv[3], "SERVER-PROFILES")) {
            snprintf(url, URL_SIZE, URL_FORMAT, argv[1], "server-profiles");
            
            // Call to HP OneView API
            httpData = getRequestWithUrlAndHeader(url, sessionID);
            
            if(!httpData)
                return 1;
            
            //printf("[DEBUG] JSON: %s\n", httpData);
            root = json_loads(httpData, 0, &error);
            
        // Find Server Profile first
            //int fieldCount = argc -5; //argv[0] is the path to the program
            json_t *memberArray = json_object_get(root, "members");
            if (json_array_size(memberArray) != 0) {
                size_t index;
                json_t *serverProfile = NULL;
                //char *json_text;
                json_array_foreach(memberArray, index, serverProfile) {
                    const char *uri = json_string_value(json_object_get(serverProfile, "uri"));
                    char *cloneuri = argv[4];
                    printf ("%s / %s /n", cloneuri, url);
                        if (uri != NULL) {
                            if (stringMatch(cloneuri, (char *)uri)) {
                                //json_text = json_dumps(serverProfile, JSON_INDENT(4)); //4 is close to a tab
                                //printf("%s\n", json_text);
                                //
                                json_object_del(serverProfile, "uri");
                                json_object_del(serverProfile, "serialNumber");
                                json_object_del(serverProfile, "uuid");
                                json_object_del(serverProfile, "taskUri");
                                json_object_del(serverProfile, "status");
                                json_object_del(serverProfile, "inProgress");
                                json_object_del(serverProfile, "modified");
                                json_object_del(serverProfile, "eTag");
                                json_object_del(serverProfile, "created");
                                json_object_del(serverProfile, "serverHardwareUri");
                                json_object_del(serverProfile, "enclosureBay");
                                json_object_del(serverProfile, "enclosureUri");

                                //json_object_del(serverProfile, "connections");
                                json_t *connections, *connectionsArray= json_object_get(serverProfile, "connections");
                                json_array_foreach(connectionsArray, index, connections) {
                                    json_object_del(connections, "mac");
                                    json_object_del(connections, "wwnn");
                                    json_object_del(connections, "wwpn");
                                }
                                
                                int profileCount = atoi(argv[5]);
                                if (profileCount != 0){
                                    char name[100];
                                    //strcat(name, json_string_value(json_object_get(serverProfile, "name")));
                                    //strcat(name, )
                                    //const char *profileName = json_string_value(json_object_get(serverProfile, "name"));
                                    char profileName[100];
                                    strcpy(profileName, json_string_value(json_object_get(serverProfile, "name")));
                                    for (int i =0; i <profileCount; i++) {
                                        sprintf(name, "%s_%d",profileName, i);
                                        printf("%s\n", name);
                                        json_string_set( json_object_get(serverProfile, "name"), name);
                                        httpData = postRequestWithUrlAndDataAndHeader(url, json_dumps(serverProfile, JSON_ENSURE_ASCII), sessionID);
                                        
                                        if(!httpData)
                                            return 1;
                                    }
                                }
                                
                                //printf("%s\n", json_string_value(json_object_get(serverProfile, "name")));
                                //json_dumps(root, JSON_ENSURE_ASCII)
                                /*
                                httpData = postRequestWithUrlAndDataAndHeader(url, json_dumps(serverProfile, JSON_ENSURE_ASCII), sessionID);
                                
                                if(!httpData)
                                    return 1;
                                //free(json_text);
                                json_text = json_dumps(serverProfile, JSON_INDENT(4)); //4 is close to a tab
                                printf("%s\n", json_text);
                                free(json_text);
*/
                            }
                            
                        }