void check_service_properties(const azure::storage::service_properties& a, const azure::storage::service_properties& b)
{
    CHECK_UTF8_EQUAL(a.logging().version(), b.logging().version());
    CHECK_EQUAL(a.logging().delete_enabled(), b.logging().delete_enabled());
    CHECK_EQUAL(a.logging().read_enabled(), b.logging().read_enabled());
    CHECK_EQUAL(a.logging().write_enabled(), b.logging().write_enabled());
    CHECK_EQUAL(a.logging().retention_policy_enabled(), b.logging().retention_policy_enabled());
    CHECK_EQUAL(a.logging().retention_days(), b.logging().retention_days());

    CHECK_UTF8_EQUAL(a.hour_metrics().version(), b.hour_metrics().version());
    CHECK_EQUAL(a.hour_metrics().enabled(), b.hour_metrics().enabled());
    if (a.hour_metrics().enabled())
    {
        CHECK_EQUAL(a.hour_metrics().include_apis(), b.hour_metrics().include_apis());
    }
    CHECK_EQUAL(a.hour_metrics().retention_policy_enabled(), b.hour_metrics().retention_policy_enabled());
    CHECK_EQUAL(a.hour_metrics().retention_days(), b.hour_metrics().retention_days());

    CHECK_UTF8_EQUAL(a.minute_metrics().version(), b.minute_metrics().version());
    CHECK_EQUAL(a.minute_metrics().enabled(), b.minute_metrics().enabled());
    if (a.minute_metrics().enabled())
    {
        CHECK_EQUAL(a.minute_metrics().include_apis(), b.minute_metrics().include_apis());
    }
    CHECK_EQUAL(a.minute_metrics().retention_policy_enabled(), b.minute_metrics().retention_policy_enabled());
    CHECK_EQUAL(a.minute_metrics().retention_days(), b.minute_metrics().retention_days());

    auto a_iter = a.cors().cbegin();
    auto b_iter = b.cors().cbegin();
    for (; a_iter != a.cors().cend() && b_iter != b.cors().cend(); ++a_iter, ++b_iter)
    {
        CHECK(std::equal(a_iter->allowed_headers().cbegin(), a_iter->allowed_headers().cend(), b_iter->allowed_headers().cbegin()));
        CHECK(std::equal(a_iter->allowed_methods().cbegin(), a_iter->allowed_methods().cend(), b_iter->allowed_methods().cbegin()));
        CHECK(std::equal(a_iter->allowed_origins().cbegin(), a_iter->allowed_origins().cend(), b_iter->allowed_origins().cbegin()));
        CHECK(std::equal(a_iter->exposed_headers().cbegin(), a_iter->exposed_headers().cend(), b_iter->exposed_headers().cbegin()));
        CHECK_EQUAL(a_iter->max_age().count(), b_iter->max_age().count());
    }

    CHECK(a_iter == a.cors().cend());
    CHECK(b_iter == b.cors().cend());

    // TODO: Is the following check valid?
    //CHECK_UTF8_EQUAL(a.default_service_version(), b.default_service_version());
}
Ejemplo n.º 2
0
 string_type build() const
 {
     string_type res = name() + string_traits_type::convert("=") + as_string( value() );
     if ( !comment().empty() )
         res += string_traits_type::convert("; comment=") + as_string( comment() );
     if ( !expires().empty() )
         res += string_traits_type::convert("; expires=") + as_string( expires() );
     if ( !max_age().empty() )
         res += string_traits_type::convert("; max-Age=") + as_string( max_age() );
     if ( !path().empty() )
         res += string_traits_type::convert("; path=") + as_string( path() );
     if ( !domain().empty() )
         res += string_traits_type::convert("; domain=") + as_string( domain() );
     if ( !version().empty() )
         res += string_traits_type::convert("; version=") + as_string( version() );
     if ( http_only() )
         res += string_traits_type::convert("; httponly");
     if ( secure() )
         res += string_traits_type::convert("; secure");
     return res;
 }
Ejemplo n.º 3
0
void CategoryInfo::DoExecute() {


  auto categories = model_->categories();
  vector<string> names = categories->category_names();
  /*
  cache_ << "*category_info: " << label_ << "\n";
  for(string name : names) {
    cache_ << "Category: " << name << "\n";
    cache_ << "min_age: " << categories->min_age(name) << "\n";
    cache_ << "max_age: " << categories->max_age(name) << "\n";

    vector<unsigned> years = categories->years(name);
    cache_ << "years: ";
    for (unsigned year : years)
      cache_ << year << " ";
    cache_ << "\n\n";
  }
  */
  cache_ << "*" << label_ << " " << "("<< type_ << ")"<<"\n";
  for(string name : names) {
    cache_ << name << " " << REPORT_R_LIST<<"\n";
    cache_ << "min_age: " << categories->min_age(name) << "\n";
    cache_ << "max_age: " << categories->max_age(name) << "\n";

    vector<unsigned> years = categories->years(name);
    cache_ << "years: ";
    for (unsigned year : years)
      cache_ << year << " ";
    cache_ << "\n";
    cache_ << REPORT_R_LIST_END << "\n";
  }


  ready_for_writing_ = true;
}
Ejemplo n.º 4
0
static int load2(struct sts_id *id, FILE *fp)
{
	char buffer[1024];
	char *p;
	long pos;
	struct stat stat_buf;
	size_t s;

	if (!fgets(buffer, sizeof(buffer), fp) ||
	    strcmp(buffer, "1\n"))
		return -1;

	if (id->id)
	{
		free(id->id);
		id->id=0;
	}

	id->tempfail=0;
	while (fgets(buffer, sizeof(buffer), fp))
	{
		if (strcmp(buffer, "\n") == 0)
			break;

		if (strcmp(buffer, "tempfail") == 0)
		{
			id->tempfail=1;
		}

		if (strcmp(strtok(buffer, ": "), "id"))
			continue;

		if ((p=strtok(NULL, ": \r\n")) == 0)
			p="";

		if ((id->id=courier_strdup(p)) == 0)
			break;
	}

	if (!id->id)
		return -1;

	while (strcmp(buffer, "\n"))
	{
		if (fgets(buffer, sizeof(buffer), fp) == 0)
			return -1;
	}

	if ((pos=ftell(fp)) < 0 || fstat(fileno(fp), &stat_buf) < 0)
		return -1;

	s=stat_buf.st_size-pos;

	if ((id->policy=courier_malloc(s+1)) == NULL ||
	    fread(id->policy, s, 1, fp) != 1)
		return -1;

	id->policy[s]=0;
	id->timestamp=stat_buf.st_mtime;
	id->expiration=id->timestamp+max_age(id);

	return 0;
}
Ejemplo n.º 5
0
static void reset_timestamp(struct sts_id *id)
{
	id->timestamp=time(NULL);
	id->expiration=id->timestamp+max_age(id);
}
Ejemplo n.º 6
0
sn_coap_hdr_s* M2MResource::handle_get_request(nsdl_s *nsdl,
                                               sn_coap_hdr_s *received_coap_header,
                                               M2MObservationHandler *observation_handler)
{
    tr_debug("M2MResource::handle_get_request()");
    sn_coap_msg_code_e msg_code = COAP_MSG_CODE_RESPONSE_CONTENT;
    sn_coap_hdr_s * coap_response = NULL;
    if(_has_multiple_instances) {
        coap_response = sn_nsdl_build_response(nsdl,
                                               received_coap_header,
                                               msg_code);
        if(received_coap_header) {
            // process the GET if we have registered a callback for it
            if ((operation() & SN_GRS_GET_ALLOWED) != 0) {
                if(coap_response) {
                    uint16_t coap_content_type = 0;
                    bool content_type_present = false;
                    if(received_coap_header->content_type_ptr){
                        content_type_present = true;
                        coap_response->content_type_ptr = alloc_copy(received_coap_header->content_type_ptr,
                                                                     received_coap_header->content_type_len);
                        if(coap_response->content_type_ptr) {
                            coap_response->content_type_len = received_coap_header->content_type_len;
                            for(uint8_t i = 0; i < coap_response->content_type_len; i++) {
                                coap_content_type = (coap_content_type << 8) +
                                        (coap_response->content_type_ptr[i] & 0xFF);
                            }
                        }
                    }

                    if(!content_type_present &&
                       M2MBase::coap_content_type() == COAP_CONTENT_OMA_TLV_TYPE) {
                        coap_content_type = COAP_CONTENT_OMA_TLV_TYPE;
                    }

                    tr_debug("M2MResource::handle_get_request() - Request Content-Type %d", coap_content_type);
                    if (!coap_response->content_type_ptr) {
                        coap_response->content_type_ptr =
                                m2m::String::convert_integer_to_array(coap_content_type,
                                    coap_response->content_type_len);
                        if (coap_response->content_type_ptr) {
                            set_coap_content_type(coap_content_type);
                        }
                    }
                    uint8_t *data = NULL;
                    uint32_t data_length = 0;
                    // fill in the CoAP response payload
                    if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type) {
                        M2MTLVSerializer *serializer = new M2MTLVSerializer();
                        if(serializer) {
                            data = serializer->serialize(this, data_length);
                            delete serializer;
                        }
                    } else {
                        msg_code = COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT; // Content format not supported
                    }

                    coap_response->payload_len = data_length;
                    coap_response->payload_ptr = data;

                    coap_response->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
                    memset(coap_response->options_list_ptr, 0, sizeof(sn_coap_options_list_s));

                    coap_response->options_list_ptr->max_age_ptr =
                            m2m::String::convert_integer_to_array(max_age(),
                                coap_response->options_list_ptr->max_age_len);

                    if(received_coap_header->token_ptr) {
                        tr_debug("M2MResource::handle_get_request - Sets Observation Token to resource");
                        set_observation_token(received_coap_header->token_ptr,
                                              received_coap_header->token_len);
                    }

                    if(received_coap_header->options_list_ptr) {
                        if(received_coap_header->options_list_ptr->observe) {
                            if (is_observable()) {
                                uint32_t number = 0;
                                uint8_t observe_option = 0;
                                if(received_coap_header->options_list_ptr->observe_ptr) {
                                    observe_option = *received_coap_header->options_list_ptr->observe_ptr;
                                }
                                if(START_OBSERVATION == observe_option) {
                                    tr_debug("M2MResource::handle_get_request - Starts Observation");
                                    // If the observe length is 0 means register for observation.
                                    if(received_coap_header->options_list_ptr->observe_len != 0) {
                                        for(int i=0;i < received_coap_header->options_list_ptr->observe_len; i++) {
                                            number = (*(received_coap_header->options_list_ptr->observe_ptr + i) & 0xff) <<
                                                     8*(received_coap_header->options_list_ptr->observe_len- 1 - i);
                                            }
                                    }
                                    // If the observe value is 0 means register for observation.
                                    if(number == 0) {
                                        tr_debug("M2MResource::handle_get_request - Put Resource under Observation");
                                        M2MResourceInstanceList::const_iterator it;
                                        it = _resource_instance_list.begin();
                                        for (; it!=_resource_instance_list.end(); it++ ) {
                                            tr_debug("M2MResource::handle_get_request - set_resource_observer");
                                            (*it)->set_resource_observer(this);
                                            (*it)->add_observation_level(M2MBase::R_Attribute);
                                        }
                                        set_under_observation(true,observation_handler);
                                        M2MBase::add_observation_level(M2MBase::R_Attribute);
                                        coap_response->options_list_ptr->observe_ptr =
                                                m2m::String::convert_integer_to_array(observation_number(),
                                                      coap_response->options_list_ptr->observe_len);
                                    }
                                } else if (STOP_OBSERVATION == observe_option) {
                                    tr_debug("M2MResource::handle_get_request - Stops Observation");
                                    set_under_observation(false,NULL);
                                    M2MBase::remove_observation_level(M2MBase::R_Attribute);
                                    M2MResourceInstanceList::const_iterator it;
                                    it = _resource_instance_list.begin();
                                    for (; it!=_resource_instance_list.end(); it++ ) {
                                        (*it)->set_resource_observer(NULL);
                                    }
                                }
                                msg_code = COAP_MSG_CODE_RESPONSE_CONTENT;
                            }
                            else {
                                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
                            }
                        }
                    }
                }
            } else {
                tr_error("M2MResource::handle_get_request - Return COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
                // Operation is not allowed.
                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
            }
        }
        if(coap_response) {
            coap_response->msg_code = msg_code;
        }
    } else {
        coap_response = M2MResourceInstance::handle_get_request(nsdl,
                            received_coap_header,
                            observation_handler);
    }
    return coap_response;
}
Ejemplo n.º 7
0
/**
 * Validate our Maturation Rate process
 *
 * - Check for the required parameters
 * - Assign variables from our parameters
 * - Verify the categories are real
 * - If proportions or selectivities only has 1 element specified
 *   add more elements until they match number of categories
 * - Verify vector lengths are all the same
 * - Verify categories From->To have matching age ranges
 * - Check all proportions are between 0.0 and 1.0
 */
void TransitionCategory::DoValidate() {
  LOG_TRACE();
  from_category_names_ = model_->categories()->ExpandLabels(from_category_names_, parameters_.Get(PARAM_FROM));
  to_category_names_ = model_->categories()->ExpandLabels(to_category_names_, parameters_.Get(PARAM_TO));

  if (selectivity_names_.size() == 1)
    selectivity_names_.assign(from_category_names_.size(), selectivity_names_[0]);

  // Validate Categories
  auto categories = model_->categories();
  for (const string& label : from_category_names_) {
    if (!categories->IsValid(label))
      LOG_ERROR_P(PARAM_FROM) << ": category " << label << " does not exist. Have you defined it?";
  }
  for(const string& label : to_category_names_) {
    if (!categories->IsValid(label))
      LOG_ERROR_P(PARAM_TO) << ": category " << label << " does not exist. Have you defined it?";
  }

  // Validate the from and to vectors are the same size
  if (from_category_names_.size() != to_category_names_.size()) {
    LOG_ERROR_P(PARAM_TO)
        << ": Number of 'to' categories provided does not match the number of 'from' categories provided."
        << " Expected " << from_category_names_.size() << " but got " << to_category_names_.size();
  }

  // Allow a one to many relationship between proportions and number of categories.
  if (proportions_.size() == 1)
    proportions_.resize(to_category_names_.size(),proportions_[0]);

  // Validate the to category and proportions vectors are the same size
  if (to_category_names_.size() != proportions_.size()) {
    LOG_ERROR_P(PARAM_PROPORTIONS)
        << ": Number of proportions provided does not match the number of 'to' categories provided."
        << " Expected " << to_category_names_.size() << " but got " << proportions_.size();
  }

  // Validate the number of selectivities matches the number of proportions
  if (proportions_.size() != selectivity_names_.size() && proportions_.size() != 1) {
    LOG_ERROR_P(PARAM_SELECTIVITIES)
        << ": Number of selectivities provided does not match the number of proportions provided."
        << " Expected " << proportions_.size() << " but got " << selectivity_names_.size();
  }

  // Validate that each from and to category have the same age range.
  for (unsigned i = 0; i < from_category_names_.size(); ++i) {
    if (categories->min_age(from_category_names_[i]) != categories->min_age(to_category_names_[i])) {
      LOG_ERROR_P(PARAM_FROM) << ": Category " << from_category_names_[i] << " does not"
          << " have the same age range as the 'to' category " << to_category_names_[i];
    }

    if (categories->max_age(from_category_names_[i]) != categories->max_age(to_category_names_[i])) {
      LOG_ERROR_P(PARAM_FROM) << ": Category " << from_category_names_[i] << " does not"
          << " have the same age range as the 'to' category " << to_category_names_[i];
    }
  }

  // Validate the proportions are between 0.0 and 1.0
  for (Double proportion : proportions_) {
    if (proportion < 0.0 || proportion > 1.0)
      LOG_ERROR_P(PARAM_PROPORTIONS) << ": proportion " << AS_DOUBLE(proportion) << " must be between 0.0 and 1.0 (inclusive)";
  }

  for (unsigned i = 0; i < from_category_names_.size(); ++i)
    proportions_by_category_[from_category_names_[i]] = proportions_[i];
}