std::vector<xml_node_t*> xml_node_t::get_nodes( const std::string&        path,
                           const std::string&        parm_name,
                           const std::string&        parm_value )
{
  std::vector<xml_node_t*> nodes;
  if ( path.empty() || path == name_str )
  {
    xml_parm_t* parm = get_parm( parm_name );
    if ( parm && parm -> value_str == parm_value )
    {
      nodes.push_back( this );
    }
  }
  else
  {
    std::string name_str;
    xml_node_t* node = split_path( name_str, path );
    if ( ! node ) return nodes;

    for ( size_t i = 0; i < children.size(); ++i )
    {
      if ( node -> children[ i ] )
      {
        std::vector<xml_node_t*> n = node -> children[ i ] -> get_nodes( name_str, parm_name, parm_value );
        nodes.insert( nodes.end(), n.begin(), n.end() );
      }
    }
  }

  return nodes;
}
xml_node_t* xml_node_t::search_tree( const std::string& node_name,
                                     const std::string& parm_name,
                                     const std::string& parm_value )
{
  if ( node_name.empty() || node_name == name_str )
  {
    xml_parm_t* parm = get_parm( parm_name );
    if ( parm && parm -> value_str == parm_value ) return this;
  }

  for ( size_t i = 0; i < children.size(); ++i )
  {
    if ( children[ i ] )
    {
      xml_node_t* node = children[ i ] -> search_tree( node_name, parm_name, parm_value );
      if ( node ) return node;
    }
  }

  return nullptr;
}
Esempio n. 3
0
File: main.c Progetto: chagge/papers
int
main(int argc, char *argv[])
{
    printf("---- SMACK/2 - benchmark program ----\n");

    {
        char dir[512];
        char *p = getcwd(dir, sizeof(dir));
	if (p == NULL)
		perror("getcwd");
	else
        	printf("directory = %s\n", p);
    }

#if WIN32
    {
        SetProcessAffinityMask(NULL, 1);
        SetPriorityClass(NULL,  REALTIME_PRIORITY_CLASS);
    }
#endif
#ifdef __linux__

    {
        cpu_set_t mask;
        int status;

        CPU_ZERO(&mask);
        CPU_SET(1, &mask);
        status = sched_setaffinity(0, sizeof(mask), &mask);
        if (status != 0)
        {
            perror("sched_setaffinity");
        }
    }

#endif

    /*
     * Print cpu info
     */
    {
        char vendor[16];
        char brand[64];
        struct CpuInfo info;
        
        pixie_cpu_vendor(vendor);
        pixie_cpu_brand(brand);
        pixie_cpu_info(&info);

        printf("CPU width = %u-bits\n", (unsigned)sizeof(void*)*8);
        printf("CPU vendor = \"%s\"\n", vendor);
        printf("CPU brand = \"%s\"\n", brand);
        printf("CPU codename = \"%s\" (0x%X" "x)\n", info.codename, info.codenumber);
        printf("CPU info = type(%u) family(%u) model(%u) stepping(%u)\n",
               info.type, info.family, info.model, info.stepping);
        
        printf("\n");
    }

    /*
     * First, do a unit-test. If the unit-test fails, then it's pointless
     * continueing with the benchmarks
     */
    if (smack_selftest() != 0) {
        printf("selftest failed\n");
        return 1;
    }
    
    /*
     * Print help if user is confused
     */
    if (0 && ( argc <= 1 
        || get_parm("--help", argc, argv) 
        || get_parm("-h", argc, argv)
        || get_parm("-?", argc, argv))) {
        printf("usage:\n"
               " smack2 --benchmark\n"
               " smack2 --haystack kingjames.txt --needle pharoah\n"
               " smack2 --haystack kingjames.txt --needles patterns.txt\n"
               );
        return 1;
    }
    if (get_parm("--haystack", argc, argv)) {
        if (!get_parm("--needles", argc, argv) 
            && !get_parm("--needle", argc, argv)) {
            printf("FAIL: need to specify patterns to search for\n");
            printf(" hint: use \"--needles <file>\" to read patterns from file\n");
            printf(" hint: use \"--needle <pattern\" to specify one or more patterns\n");
            return 1;
        }
    }
        
    
    /*
     * If doing simple benchmarks, do them first
     */
    if (get_parm("--benchmark", argc, argv) || argc <= 1) {
        printf("--- low-level benchmarks ---\n");
        bench_c_ptr();
        bench_c_idx(0);
        bench_asm_ptr();
        //bench_asm_ptr2();
        bench_asm_idx();
        printf("\n");
        smack_benchmark();
    }
    if (!get_parm("--haystack", argc, argv))
        return 0;
    
    /*
     * Look in file for patterns
     */
    {
        const char *filename = get_parm("--haystack", argc, argv);
        char *buf;
        size_t sizeof_buf;
        struct stat s;
        int x;
        struct SMACK *smack;
        int i;
        
        fprintf(stderr, "haystack file = %s\n", filename);
        
        /*
         * Find file size
         */
        x = stat(filename, &s);
        if (x != 0) {
            perror(filename);
            return 1;
        }
        sizeof_buf = s.st_size;
        
        /*
         * Allocate memory
         */
        buf = (char*)malloc(sizeof_buf);
        if (buf == 0) {
            fprintf(stderr, "Could not allocate %u bytes for buffer\n",
                    (unsigned)sizeof_buf);
            return 1;
        }
        
        /*
         * Read in the file
         */
        {
            FILE *fp;
            size_t bytes_read;
            fp = fopen(filename, "rb");
            if (fp == NULL) {
                perror(filename);
                return 1;
            }
            bytes_read = fread(buf, 1, sizeof_buf, fp);
            if (bytes_read == 0) {
                perror(filename);
                return 1;
            }
            if (bytes_read < sizeof_buf) {
                fprintf(stderr, "ERROR: could not read entire file\n");
                fprintf(stderr, "wanted %u bytes, read %u bytes\n",
                        (unsigned)sizeof_buf, 
                        (unsigned)bytes_read);
                sizeof_buf = bytes_read;
            }
            fclose(fp);
            
            fprintf(stderr, "file-size = %u\n", (unsigned)sizeof_buf);
        }
        
        /*
         * Build the smack object
         */
        smack = smack_create("haystack", SMACK_CASE_INSENSITIVE);
        if (smack == 0) {
            fprintf(stderr, "FAIL: couldn't create test object\n");
            return 1;
        }
        
        /*
         * Add patterns
         */
        for (i=1; i<argc; i++) {
            if (strcmp(argv[i], "--needle") == 0) {
                const char *pattern = argv[i+1];
                if (i+1 >= argc) {
                    fprintf(stderr, "FAIL: expected value to parm\n");
                    return 1;
                }
                smack_add_pattern(smack, pattern, strlen(pattern), 1, 0);
            }
            if (strcmp(argv[i], "--needles") == 0) {
                const char *patterns = argv[i+1];
                FILE *fp;
                char line[80];
                if (i+1 >= argc) {
                    fprintf(stderr, "FAIL: expected value to parm\n");
                    return 1;
                }
                fp = fopen(patterns, "rt");
                if (fp == NULL) {
                    perror(patterns);
                    return 1;
                }
                
                while (fgets(line, sizeof(line), fp)) {
                    /* strip whitespace */
                    while (line[0] && isspace(line[0]&0xFF))
                        memmove(line, line+1, strlen(line));
                    while (line[0] && isspace(line[strlen(line)-1]&0xFF))
                        line[strlen(line)-1] = '\0';
                    if (line[0] == '\0' || ispunct(line[0]&0xFF))
                        continue;
                    smack_add_pattern(smack, line, strlen(line), 1, 0);
                }
            }
        }
        if (smack_count_patterns(smack) == 0) {
            fprintf(stderr, "FAIL: no patterns found\n");
            return 1;
        } else {
            fprintf(stderr, "needles = %u patterns\n", smack_count_patterns(smack));
        }
        
        smack_compile(smack);
        
        /*
         * Do the benchmark
         */
        do_haystack(smack,
                    buf, sizeof_buf,
                    10);

    }
    
    
    
    return 0;
}
Esempio n. 4
0
File: msnms.c Progetto: OPSF/uClinux
void process_simple_msnms_server_response(struct Seaper *seap, struct NetFrame *frame, const unsigned char *px, unsigned length)
{
	unsigned offset=0;
	unsigned char cmd[16] = "";
	unsigned i;
	unsigned eol=0;

	/*Find out length of the command line */
	for (eol=0; eol<length && px[eol] != '\n'; eol++)
		;

	skip_whitespace(px, length, &offset);

	/* get command */
	i=0;
	while (offset < length && px[offset] != '\n' && !isspace(px[offset])) {
		if (i<sizeof(cmd)-1) {
			cmd[i++] = px[offset];
			cmd[i] = '\0';
		}
		offset++;
	}
	skip_whitespace(px, length, &offset);

	SAMPLE("MSN-MSGR", "command", REC_SZ, cmd, -1);

	switch (CMD(cmd)) {
    case 0x56455200: /* "VER" */
		while (offset < eol) {
			unsigned parm = offset;
			unsigned parm_length = get_parm(px, length, &offset);

			if (is_number(px+parm, parm_length))
				continue;

			if (equals(px+parm, parm_length, "CVR0"))
				continue;


			/* Syntax:
			 * VER <TrID> <protocol> <protocol> .... 
			 *
			 *	Indicates a list of protocols supported
			 *
			 *  Examples:
			 *		VER 0 MSNP8 CVR0
			 *		VER 0 MSNP8 MYPROTOCOL CVR0
			 */
			process_record(seap,
				"ID-IP",	REC_FRAMESRC,	frame, -1,
				"app",		REC_SZ,			"MSN-MSGR",		-1,
				"ver",		REC_PRINTABLE,	px+parm, parm_length,
				0);
		}				

		break;
    case 0x4e4c4e00: /* "NLN" */
		{
			unsigned state, state_length;
			unsigned handle, handle_length;
			unsigned friendly, friendly_length;

			state = offset;
			state_length = get_parm(px, length, &offset);

			handle = offset;
			handle_length = get_parm(px, length, &offset);

			friendly = offset;
			friendly_length = get_parm(px, length, &offset);

			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMEDST,	frame, -1,
				"friend",	REC_PRINTABLE,	px+handle, handle_length,
				"name",		REC_PRINTABLE,	px+friendly, friendly_length,
				"state",	REC_PRINTABLE,	px+state, state_length,
				0);
		}				
		break;
    case 0x514e4700: /* "QNG" */
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMEDST,	frame, -1,
				0);
		break;
    case 0x43565200: /* "CVR" */
		break;
    case 0x55535200: /* "USR" */
		break;
    case 0x4d534700: /* "MSG" */
    case 0x58465200: /* "XFR" */
	default:
		FRAMERR(frame, "msn-ms: unknown commanded from client: %.*s\n", length, px);
	}


	
}
Esempio n. 5
0
File: msnms.c Progetto: OPSF/uClinux
void process_simple_msnms_client_request(struct Seaper *seap, struct NetFrame *frame, const unsigned char *px, unsigned length)
{
	unsigned offset=0;
	unsigned char cmd[16] = "";
	unsigned i;
	unsigned eol=0;

	/*Find out length of the command line */
	for (eol=0; eol<length && px[eol] != '\n'; eol++)
		;

	skip_whitespace(px, length, &offset);

	/* get command */
	i=0;
	while (offset < length && px[offset] != '\n' && !isspace(px[offset])) {
		if (i<sizeof(cmd)-1) {
			cmd[i++] = px[offset];
			cmd[i] = '\0';
		}
		offset++;
	}
	skip_whitespace(px, length, &offset);

	SAMPLE("MSN-MSGR", "command", REC_SZ, cmd, -1);

	switch (CMD(cmd)) {
    case 0x56455200: /* "VER" */
		while (offset < eol) {
			unsigned parm = offset;
			unsigned parm_length = get_parm(px, length, &offset);

			if (is_number(px+parm, parm_length))
				continue;

			if (equals(px+parm, parm_length, "CVR0"))
				continue;


			/* Syntax:
			 * VER <TrID> <protocol> <protocol> .... 
			 *
			 *	Indicates a list of protocols supported
			 *
			 *  Examples:
			 *		VER 0 MSNP8 CVR0
			 *		VER 0 MSNP8 MYPROTOCOL CVR0
			 */
			process_record(seap,
				"ID-IP",	REC_FRAMESRC,	frame, -1,
				"app",		REC_SZ,			"MSN-MSGR",		-1,
				"ver",		REC_PRINTABLE,	px+parm, parm_length,
				0);
		}				

		break;
    case 0x4e4c4e00: /* "NLN" */
		break;
    case 0x514e4700: /* "QNG" */
		break;
    case 0x43565200: /* "CVR" */
/*
    *  The first parameter is hexadecimal number specifying your locale ID (e.g. "0x0409" For U.S. English).
    * The second parameter is your OS type (e.g. "win" for Windows).
    * The third parameter is your OS version (e.g. "4.10" for Windows 98).
    * The fourth parameter is the architecture of your computer (e.g. "i386" for Intel-comaptible PCs of type 386 or above).
    * The fifth parameter is your client name (e.g. "MSMSGR" for the official MSN Messenger client).
    * The sixth parameter is your client version (e.g. "6.0.0602").
    * The seventh parameter is always "MSMSGS" in the official client. Your guess about what this means is as good as mine.
    * The eighth parameter is your passport.
*/
		{
			unsigned trid, trid_length;
			unsigned localid, localid_length;
			unsigned ostype, ostype_length;
			unsigned osver, osver_length;
			unsigned arch, arch_length;
			unsigned clientname, clientname_length;
			unsigned clientver, clientver_length;
			unsigned msmsgs, msmsgs_length;
			unsigned passport, passport_length;

			trid = offset;
			trid_length = get_parm(px, length, &offset);
			
			localid=offset;
			localid_length = get_parm(px, length, &offset);
			
			ostype=offset;
			ostype_length = get_parm(px, length, &offset);
			
			osver=offset;
			osver_length = get_parm(px, length, &offset);
			
			arch=offset;
			arch_length = get_parm(px, length, &offset);
			
			clientname=offset;
			clientname_length = get_parm(px, length, &offset);
			
			clientver=offset;
			clientver_length = get_parm(px, length, &offset);
			
			msmsgs=offset;
			msmsgs_length = get_parm(px, length, &offset);
			
			passport=offset;
			passport_length = get_parm(px, length, &offset);
			
			process_record(seap,
				"ID-IP",	REC_FRAMESRC,	frame, -1,
				"Passport",	REC_PRINTABLE,	px+passport, passport_length,
				0);

			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"localid",	REC_PRINTABLE, px+localid, localid_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"ostype",	REC_PRINTABLE, px+ostype, ostype_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"osver",	REC_PRINTABLE	, px+osver, osver_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"arch",		REC_PRINTABLE	, px+arch, arch_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"clientname",	REC_PRINTABLE, px+clientname, clientname_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"clientver",REC_PRINTABLE, px+clientver, clientver_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"msmsgs",	REC_PRINTABLE, px+msmsgs, msmsgs_length,
				0);
			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"passport",	REC_PRINTABLE, px+passport, passport_length,
				0);

		}				
		break;
    case 0x55535200: /* "USR" */
	/*After receiving the response to CVR, you must send the USR command. It has a TrID.
    * The first parameter is the authentication system (always TWN).
    * The second parameter is always the letter I (standing for initiating authentication).
    * The third parameter is the account name that you want to log on with.
	*/
		{
			unsigned trid, trid_length;
			unsigned twn, twn_length;
			unsigned ii, ii_length;
			unsigned username, username_length;

			trid = offset;
			trid_length = get_parm(px, length, &offset);
			
			twn = offset;
			twn_length = get_parm(px, length, &offset);

			ii = offset;
			ii_length = get_parm(px, length, &offset);

			username = offset;
			username_length = get_parm(px, length, &offset);

			process_record(seap,
				"proto",	REC_SZ,			"MSN-MSGR", -1,
				"ip",		REC_FRAMESRC,	frame, -1,
				"username",	REC_PRINTABLE, px+username, username_length,
				0);
			process_record(seap,
				"ID-IP",	REC_FRAMESRC,	frame, -1,
				"MSN-username",	REC_PRINTABLE,	px+username, username_length,
				0);
		}				
		break;
    case 0x4d534700: /* "MSG" */
    case 0x58465200: /* "XFR" */
	default:
		FRAMERR(frame, "msn-ms: unknown commanded from client: %.*s\n", length, px);
	}


	
}