Beispiel #1
0
void schema_validator::validate_key(const config & cfg,
				  const std::string & name,
				  const std::string & value,
				  int start_line,
				  const std::string &file){
	if (!stack_.empty() && stack_.top() && config_read_){
		// checking existing keys
		const class_key * key =stack_.top()->find_key(name);
		if (key){
			std::map<std::string,boost::regex>::iterator itt =
					types_.find(key->get_type());
			if (itt != types_.end()){
				boost::smatch sub;
				bool res = boost::regex_match(value,sub,itt->second);
				if (!res ) {
					cache_.top()[&cfg].push_back(
							message_info(WRONG_VALUE,file,start_line,0,
										 stack_.top()->get_name(),
										 name,value));
				}
			}
		}
		else{
			cache_.top()[&cfg].push_back(
					message_info(EXTRA_KEY,file,start_line,0,
								 stack_.top()->get_name(),name));
		}

	}
}
Beispiel #2
0
void schema_validator::validate(const config & cfg, const std::string & name,
								int start_line,
								const std::string &file){
	//close previous errors and print them to output.
	message_map::iterator cache_it = cache_.top().begin();
	for (;cache_it != cache_.top().end();++cache_it){
		for (message_list::iterator i = cache_it->second.begin();
		i != cache_it->second.end(); ++i){
			print(*i);
		}
	}
	cache_.pop();
	// clear cache
	cache_it = cache_.top().find(&cfg);
	if (cache_it != cache_.top().end()){
		cache_it->second.clear();
	}
	// Please note that validating unknown tag keys the result will be false
	// Checking all elements counters.
	if (!stack_.empty() && stack_.top() && config_read_){
		class_tag::all_const_tag_iterators p = stack_.top()->tags();
		for (class_tag::const_tag_iterator tag = p.first;
			 tag != p.second ; ++tag){
			int cnt = counter_.top()[tag->first].cnt;
			if (tag->second.get_min() > cnt){
				cache_.top()[&cfg].push_back(
						message_info(MISSING_TAG,file,start_line,
									 tag->second.get_min(),tag->first,"",
									 name));
				continue;
			}
			if (tag->second.get_max() < cnt){
				cache_.top()[&cfg].push_back(
						message_info(EXTRA_TAG,file,start_line,
									 tag->second.get_max(),tag->first,"",
									 name));
			}
		}
		// Checking if all mandatory keys are present
		class_tag::all_const_key_iterators k = stack_.top()->keys();
		for (class_tag::const_key_iterator key = k.first;
			 key != k.second ; ++key){
			if (key->second.is_mandatory()){
				if (cfg.get(key->first) == nullptr){
					cache_.top()[&cfg].push_back(
							message_info(MISSING_KEY,file,start_line,0,
										 name,key->first ));
				}
			}
		}
	}
}
Beispiel #3
0
void data_arrived(SOCKET sock, char buffer[BUF_SIZE]){
    if (strcmp(buffer, "new") == 0){
        nb_client = nb_client + 1;
        new_console(0);
        if (nb_client){
            new_console(0);
            }
         }
    if (strcmp(buffer, "del") == 0){
        nb_client = nb_client - 1;
        new_console(0);
         }
    if (strstr(buffer, "#1")){
            nb_rcv_packets = nb_rcv_packets +1;
            remove_packet_account(sock, buffer);
         }
    if (nb_client == -1){
        nb_client = 0;
        new_console(0);
        }
    if (!nb_client){
        message_info("Waiting for first client");
        }


    return ;

}
Beispiel #4
0
void info(const std::string &text) {
    message_info(text.c_str());
}