Exemple #1
0
IpAddress
syncResolve(const std::string& host, boost::asio::io_service& ioService,
            const ndn::dns::AddressSelector& addressSelector)
{
  Resolver resolver(SuccessCallback(), ErrorCallback(), addressSelector, ioService);

  BoostResolver::query query(host, Resolver::NULL_PORT);

  BoostResolver::iterator remoteEndpoint = resolver.syncResolve(query);

  BoostResolver::iterator end;
  for (; remoteEndpoint != end; ++remoteEndpoint)
    {
      if (addressSelector(EndPoint(*remoteEndpoint).address()))
        {
          return EndPoint(*remoteEndpoint).address();
        }
    }
  BOOST_THROW_EXCEPTION(Error("No endpoint matching the specified address selector found"));
}
Exemple #2
0
IpAddress
syncResolve(const std::string& host, boost::asio::io_service& ioService,
            const ndn::dns::AddressSelector& addressSelector)
{
  Resolver resolver(SuccessCallback(), ErrorCallback(), addressSelector, ioService);

  BoostResolver::query query(host, Resolver::NULL_PORT
#if not defined(__FreeBSD__)
                                 , BoostResolver::query::all_matching
#endif
                                 );

  BoostResolver::iterator remoteEndpoint = resolver.syncResolve(query);

  BoostResolver::iterator end;
  for (; remoteEndpoint != end; ++remoteEndpoint)
    {
      if (addressSelector(EndPoint(*remoteEndpoint).address()))
        {
          return EndPoint(*remoteEndpoint).address();
        }
    }
  throw Error("No endpoint matching the specified address selector found");
}
OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
                                                   OCClientResponse *clientResponse) {
    OIC_LOG_V(DEBUG, TAG, "INSIDE ProvisionEnrolleeResponse");

    // If user stopped the process then return from this function;
    if (IsSetupStopped()) {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
        return OC_STACK_DELETE_TRANSACTION;
    }

    ProvisioningInfo *provInfo;

    if (!ValidateEnrolleResponse(clientResponse)) {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        return OC_STACK_DELETE_TRANSACTION;
    }

    char *tnn;
    char *cd;

    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);

    while (input) {

        int64_t ps;
        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) {

            if (ps == 1) {
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "PS is NOT proper");
                goto Error;

            }
        }

        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
            if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) {
                OIC_LOG_V(DEBUG, TAG, "SSID is proper");
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "SSID is NOT proper");
                goto Error;
            }
        }

        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
            if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) {
                OIC_LOG_V(DEBUG, TAG, "Password is proper");
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "Password is NOT proper");
                goto Error;
            }
        }

        LogProvisioningResponse(input->values);

        input = input->next;

    }

    SuccessCallback(clientResponse);

    return OC_STACK_KEEP_TRANSACTION;

    Error:
    {

        ErrorCallback(DEVICE_NOT_PROVISIONED);

        return OC_STACK_DELETE_TRANSACTION;
    }

}