Ejemplo n.º 1
0
bool
HttpClient::perform()
{
    writeRequest();
    if (!_conn->fresh() && (_conn->stream().obtain().size == 0)) {
        _conn.reset(new HttpConnection(_conn->server()));
        writeRequest();
    }
    return (readStatus() && readHeaders() && readContent());
}
Ejemplo n.º 2
0
 bool EtherIPC::queueRequest(const RequestIPC& request) {
     if ( fActiveRequest.burden() == None ) {
         return writeRequest(request);
     } else {
         fRequestQueue.append(request);
         return true;
     }
 }
Ejemplo n.º 3
0
 void EtherIPC::done() {
     fActiveRequest = RequestIPC(None);
     if ( !fRequestQueue.isEmpty() ) {
         const RequestIPC request = fRequestQueue.first();
         fRequestQueue.removeFirst();
         writeRequest(request);
     } else {
         emit busyChanged(getBusy());
     }
 }
Ejemplo n.º 4
0
int
probeBrailleDisplay (
  BrailleDisplay *brl, unsigned int retryLimit,
  GioEndpoint *endpoint, int inputTimeout,
  BrailleRequestWriter *writeRequest,
  BraillePacketReader *readPacket, void *responsePacket, size_t responseSize,
  BrailleResponseHandler *handleResponse
) {
  unsigned int retryCount = 0;

  if (!endpoint) endpoint = brl->gioEndpoint;

  while (writeRequest(brl)) {
    drainBrailleOutput(brl, 0);

    while (gioAwaitInput(endpoint, inputTimeout)) {
      size_t size = readPacket(brl, responsePacket, responseSize);
      if (!size) break;

      {
        BrailleResponseResult result = handleResponse(brl, responsePacket, size);

        switch (result) {
          case BRL_RSP_DONE:
            return 1;

          case BRL_RSP_UNEXPECTED:
            logUnexpectedPacket(responsePacket, size);
          case BRL_RSP_CONTINUE:
            break;

          default:
            logMessage(LOG_WARNING, "unimplemented braille response result: %u", result);
          case BRL_RSP_FAIL:
            return 0;
        }
      }
    }

    if (errno != EAGAIN)
#ifdef ETIMEDOUT
      if (errno != ETIMEDOUT)
#endif /* ETIMEDOUT */
        break;

    if (retryCount == retryLimit) break;
    retryCount += 1;
  }

  return 0;
}
Ejemplo n.º 5
0
 void handleHandshake(const boost::system::error_code& ec)
 {
    try
    {
       if (!ec)
       {
          // finished handshake, commence with request
          writeRequest();
       }
       else
       {
          handleErrorCode(ec, ERROR_LOCATION);
       }
    }
    CATCH_UNEXPECTED_ASYNC_CLIENT_EXCEPTION
 }
Ejemplo n.º 6
0
void EHttpBasicAuthLogicHandler::doHandshake(EIoFilter::NextFilter* nextFilter) {
	logger->debug(__FILE__, __LINE__, " doHandshake()");

	if (step > 0) {
		throw EProxyAuthException(__FILE__, __LINE__, "Authentication request already sent");
	}

	// Send request
	sp<EHttpProxyRequest> req = dynamic_pointer_cast<EHttpProxyRequest>(request);
	EMap<EString*, EList<EString*>*>* headers = req->getHeaders();

	EString uk(EHttpProxyConstants_USER_PROPERTY);
	EString* username = req->getProperties()->get(&uk);
	EString pw(EHttpProxyConstants_PWD_PROPERTY);
	EString* password = req->getProperties()->get(&pw);

    EString value("Basic " + createAuthorization(username->c_str(), password->c_str()));
    EAbstractAuthLogicHandler::addValueToHeader(headers, "Proxy-Authorization",
                                     value.c_str(), true);
	addKeepAliveHeaders(headers);

	writeRequest(nextFilter, req);
	step++;
}
Ejemplo n.º 7
0
static int
setFirmness (BrailleDisplay *brl, BrailleFirmness setting) {
  brl->data->firmnessSetting = setting * 0XFF / BRL_FIRMNESS_MAXIMUM;
  return writeRequest(brl);
}
Ejemplo n.º 8
0
static int
handleAcknowledgement (BrailleDisplay *brl, int ok) {
  brl->data->acknowledgementHandler(brl, ok);
  brl->data->acknowledgementHandler = NULL;
  return writeRequest(brl);
}
void EHttpDigestAuthLogicHandler::doHandshake(EIoFilter::NextFilter* nextFilter) {
	logger->debug(__FILE__, __LINE__, " doHandshake()");

	if (step > 0 && directives == null) {
		throw EProxyAuthException(__FILE__, __LINE__, "Authentication challenge not received");
	}

	sp<EHttpProxyRequest> req = dynamic_pointer_cast<EHttpProxyRequest>(request);
	EMap<EString*, EList<EString*>*>* headers = req->getHeaders();

	if (step > 0) {
		logger->debug(__FILE__, __LINE__, "  sending DIGEST challenge response");

		// Build a challenge response
		EHashMap<EString*, EString*> map;
		EString k(EHttpProxyConstants_USER_PROPERTY);
		map.put(new EString("username"), new EString(req->getProperties()->get(&k)));
		EStringUtilities::copyDirective(directives, map, "realm");
		EStringUtilities::copyDirective(directives, map, "uri");
		EStringUtilities::copyDirective(directives, map, "opaque");
		EStringUtilities::copyDirective(directives, map, "nonce");
		EString algorithm = EStringUtilities::copyDirective(directives, map, "algorithm");

		// Check for a supported algorithm
		if (!algorithm.equalsIgnoreCase("md5") && !algorithm.equalsIgnoreCase("md5-sess")) {
			throw EProxyAuthException(__FILE__, __LINE__, "Unknown algorithm required by server");
		}

		// Check for a supported qop
        k = "qop";
		EString* qop = directives->get(&k);
		if (qop != null) {
			EStringTokenizer st(qop->c_str(), ",");
			EString token;// = null;

			while (st.hasMoreTokens()) {
				EString tk = st.nextToken();
				if (token.equalsIgnoreCase("auth")) {
					break;
				}

				/* @see:
				int pos = Arrays.binarySearch(DigestUtilities.SUPPORTED_QOPS, tk);
				if (pos > -1) {
					token = tk;
				}
				*/
				if (tk.equalsIgnoreCase("auth") || tk.equalsIgnoreCase("auth-int")) {
					token = tk;
				}
			}

			if (!token.isEmpty()) {
				map.put(new EString("qop"), new EString(token));

				byte nonce[8] = {0};
				rnd.nextBytes(nonce, 8);

				try {
					EString* cnonce = new EString(EBase64::encodeBase64(nonce, 8)/*, proxyIoSession.getCharsetName()*/);
					map.put(new EString("cnonce"), cnonce);
				} catch (EUnsupportedEncodingException& e) {
					throw EProxyAuthException(__FILE__, __LINE__, "Unable to encode cnonce", &e);
				}
			} else {
				throw EProxyAuthException(__FILE__, __LINE__, "No supported qop option available");
			}
		}

		map.put(new EString("nc"), new EString("00000001"));
		map.put(new EString("uri"), new EString(req->getHttpURI()));

		// Compute the response
		try {
            sp<EIoSession> session = proxyIoSession->getSession();
			EString k(EHttpProxyConstants_PWD_PROPERTY);
			map.put(new EString("response"), new EString(DigestUtilities::computeResponseValue(session, map, req
					->getHttpVerb(), req->getProperties()->get(&k)->c_str(), response->getBody())));

		} catch (EException& e) {
			throw EProxyAuthException(__FILE__, __LINE__, "Digest response computing failed", &e);
		}

		// Prepare the challenge response header and add it to the
		// request we will send
		EString sb("Digest ");// = new StringBuilder("Digest ");
		boolean addSeparator = false;

		sp<EIterator<EMapEntry<EString*, EString*>*> > iter = map.entrySet()->iterator();
		while (iter->hasNext()) {
			EMapEntry<EString*, EString*>* entry = iter->next();
			EString* key = entry->getKey();

			if (addSeparator) {
				sb.append(", ");
			} else {
				addSeparator = true;
			}

			boolean quotedValue = !key->equals("qop") && !key->equals("nc");
			sb.append(key);

			if (quotedValue) {
				sb.append("=\"").append(entry->getValue()).append('\"');
			} else {
				sb.append('=').append(entry->getValue());
			}
		}

		addValueToHeader(headers, "Proxy-Authorization", sb.toString().c_str(), true);
	}

	addKeepAliveHeaders(headers);
	//req->setHeaders(headers); ?

	writeRequest(nextFilter, req);
	step++;
}
Ejemplo n.º 10
0
static int
getPacket (BrailleDisplay *brl, Packet *packet) {
  while (1) {
    int count = readPacket(brl, packet);

    if (count > 0) {
      switch (packet->header.type) {
        {
          int ok;

        case PKT_NAK:
          logNegativeAcknowledgement(packet);

          if (!brl->data->acknowledgementHandler) {
            logMessage(LOG_WARNING, "Unexpected NAK.");
            continue;
          }

          switch (packet->header.arg1) {
            case PKT_ERR_TIMEOUT: {
              int originalLimit = brl->data->outputPayloadLimit;

              if (brl->data->outputPayloadLimit > brl->data->model->cellCount)
                brl->data->outputPayloadLimit = brl->data->model->cellCount;

              if (brl->data->outputPayloadLimit > 1)
                brl->data->outputPayloadLimit--;

              if (brl->data->outputPayloadLimit != originalLimit)
                logMessage(LOG_WARNING, "Maximum payload length reduced from %d to %d.",
                           originalLimit, brl->data->outputPayloadLimit);
              break;
            }
          }

        handleNegativeAcknowledgement:
          ok = 0;
          goto handleAcknowledgement;

        case PKT_ACK:
          if (!brl->data->acknowledgementHandler) {
            logMessage(LOG_WARNING, "Unexpected ACK.");
            continue;
          }

          ok = 1;
        handleAcknowledgement:
          brl->data->acknowledgementHandler(brl, ok);
          brl->data->acknowledgementHandler = NULL;
          if (writeRequest(brl)) continue;

          count = -1;
          break;
        }
      }
    } else if ((count == 0) && brl->data->acknowledgementHandler &&
               afterTimePeriod(&brl->data->acknowledgementPeriod, NULL)) {
      if (++brl->data->acknowledgementsMissing < 5) {
        logMessage(LOG_WARNING, "Missing ACK; assuming NAK.");
        goto handleNegativeAcknowledgement;
      }

      logMessage(LOG_WARNING, "Too many missing ACKs.");
      count = -1;
    }

    return count;
  }
}