コード例 #1
0
ファイル: XMLHttpRequest.cpp プロジェクト: ollie314/webkit
ExceptionOr<void> XMLHttpRequest::send(const String& body)
{
    if (auto result = prepareToSend())
        return WTFMove(result.value());

    if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) {
        String contentType = m_requestHeaders.get(HTTPHeaderName::ContentType);
        if (contentType.isNull()) {
#if ENABLE(DASHBOARD_SUPPORT)
            if (usesDashboardBackwardCompatibilityMode())
                m_requestHeaders.set(HTTPHeaderName::ContentType, ASCIILiteral("application/x-www-form-urlencoded"));
            else
#endif
                m_requestHeaders.set(HTTPHeaderName::ContentType, HTTPHeaderValues::textPlainContentType());
        } else {
            replaceCharsetInMediaType(contentType, "UTF-8");
            m_requestHeaders.set(HTTPHeaderName::ContentType, contentType);
        }

        m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, EntitiesForUnencodables));
        if (m_upload)
            m_requestEntityBody->setAlwaysStream(true);
    }

    return createRequest();
}
コード例 #2
0
ファイル: XMLHttpRequest.cpp プロジェクト: ollie314/webkit
ExceptionOr<void> XMLHttpRequest::send(Document& document)
{
    if (auto result = prepareToSend())
        return WTFMove(result.value());

    if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) {
        if (!m_requestHeaders.contains(HTTPHeaderName::ContentType)) {
#if ENABLE(DASHBOARD_SUPPORT)
            if (usesDashboardBackwardCompatibilityMode())
                m_requestHeaders.set(HTTPHeaderName::ContentType, ASCIILiteral("application/x-www-form-urlencoded"));
            else
#endif
                // FIXME: this should include the charset used for encoding.
                m_requestHeaders.set(HTTPHeaderName::ContentType, document.isHTMLDocument() ? ASCIILiteral("text/html;charset=UTF-8") : ASCIILiteral("application/xml;charset=UTF-8"));
        }

        // FIXME: According to XMLHttpRequest Level 2, this should use the Document.innerHTML algorithm
        // from the HTML5 specification to serialize the document.
        m_requestEntityBody = FormData::create(UTF8Encoding().encode(createMarkup(document), EntitiesForUnencodables));
        if (m_upload)
            m_requestEntityBody->setAlwaysStream(true);
    }

    return createRequest();
}
コード例 #3
0
bool QQnxVirtualKeyboardPps::hideKeyboard()
{
    qVirtualKeyboardDebug() << Q_FUNC_INFO;

    if (!prepareToSend())
        return false;

    pps_encoder_add_string(m_encoder, "msg", "hide");

    return writeCurrentPPSEncoder();
}
コード例 #4
0
bool QQnxVirtualKeyboardPps::queryPPSInfo()
{
    if (!prepareToSend())
        return false;

    // Request info, requires id to regenerate res message.
    pps_encoder_add_string(m_encoder, "msg", "info");
    pps_encoder_add_string(m_encoder, "id", "libWebView");

    return writeCurrentPPSEncoder();
}
コード例 #5
0
ファイル: XMLHttpRequest.cpp プロジェクト: ollie314/webkit
ExceptionOr<void> XMLHttpRequest::sendBytesData(const void* data, size_t length)
{
    if (auto result = prepareToSend())
        return WTFMove(result.value());

    if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) {
        m_requestEntityBody = FormData::create(data, length);
        if (m_upload)
            m_requestEntityBody->setAlwaysStream(true);
    }

    return createRequest();
}
コード例 #6
0
void CFitnessProtocol::setMode(ModeEnum_t mode)
{
    /**
     *
     *#### CMD_SetMode ####
	datalen = 2;
	byte[0] = CMD_SetMode;
	byte[1] = ModeEnum_t;
     */
    setCtrlBufferLength(2);
    ctrlBuffer(0) = CMD_SetMode;
    ctrlBuffer(1) = mode;
    prepareToSend();
}
コード例 #7
0
ファイル: XMLHttpRequest.cpp プロジェクト: ollie314/webkit
ExceptionOr<void> XMLHttpRequest::send(DOMFormData& body)
{
    if (auto result = prepareToSend())
        return WTFMove(result.value());

    if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) {
        m_requestEntityBody = FormData::createMultiPart(body, body.encoding(), document());
        m_requestEntityBody->generateFiles(document());
        if (!m_requestHeaders.contains(HTTPHeaderName::ContentType))
            m_requestHeaders.set(HTTPHeaderName::ContentType, makeString("multipart/form-data; boundary=", m_requestEntityBody->boundary().data()));
    }

    return createRequest();
}
コード例 #8
0
void CFitnessProtocol::setPosRange(int32_t minPos,int32_t maxPos)
{
    /**
     *
     *#### CMD_SetPosRange ####
    datalen = 9;
    byte[0] = CMD_SetPosRange;
    byte[1-4] = minPos;
    byte[5-8] = maxPos;
     */
    setCtrlBufferLength(9);
    ctrlBuffer(0) = CMD_SetPosRange;
    memcpy(&ctrlBuffer(1),&minPos,4);
    memcpy(&ctrlBuffer(5),&maxPos,4);
    prepareToSend();
}
コード例 #9
0
void QQnxVirtualKeyboardPps::applyKeyboardOptions()
{
    if (!prepareToSend())
        return;

    // Send the options message.
    pps_encoder_add_string(m_encoder, "msg", "options");
    pps_encoder_start_object(m_encoder, "dat");

    pps_encoder_add_string(m_encoder, "enter", enterKeyTypeStr());
    pps_encoder_add_string(m_encoder, "type", keyboardModeStr());

    pps_encoder_end_object(m_encoder);

    writeCurrentPPSEncoder();
}
コード例 #10
0
void CFitnessProtocol::setModePara_DZ(int16_t torsion,int32_t position)
{
    /**
     *
     *#### setModePara_DZ ####
	datalen = 8;
	byte[0] = CMD_SetModePara;
	byte[1] = Mode_DZ;
	byte[2-3] = torsion;
	byte[4-7] = position;
     */
    setCtrlBufferLength(8);
    ctrlBuffer(0) = CMD_SetModePara;
    ctrlBuffer(1) = Mode_DZ;
    memcpy(&ctrlBuffer(2),&torsion,2);
    memcpy(&ctrlBuffer(4),&position,4);
    prepareToSend();
}
コード例 #11
0
void CFitnessProtocol::setModePara_DD(int16_t torsion,int16_t speed)
{
    /**
     *
     *#### setModePara_DD ####
	datalen = 6;
	byte[0] = CMD_SetModePara;
	byte[1] = Mode_DD;
	byte[2-3] = torsion;
	byte[4-5] = speed;
     */
    setCtrlBufferLength(6);
    ctrlBuffer(0) = CMD_SetModePara;
    ctrlBuffer(1) = Mode_DD;
    memcpy(&ctrlBuffer(2),&torsion,2);
    memcpy(&ctrlBuffer(4),&speed,2);
    prepareToSend();
}
コード例 #12
0
bool QQnxVirtualKeyboardPps::showKeyboard()
{
    qVirtualKeyboardDebug() << Q_FUNC_INFO;

    if (!prepareToSend())
        return false;

    // NOTE:  This must be done everytime the keyboard is shown even if there is no change because
    // hiding the keyboard wipes the setting.
    applyKeyboardOptions();

    if (isVisible())
        return true;

    pps_encoder_reset(m_encoder);

    // Send the show message.
    pps_encoder_add_string(m_encoder, "msg", "show");

    return writeCurrentPPSEncoder();
}
コード例 #13
0
ファイル: XMLHttpRequest.cpp プロジェクト: ollie314/webkit
ExceptionOr<void> XMLHttpRequest::send(Blob& body)
{
    if (auto result = prepareToSend())
        return WTFMove(result.value());

    if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) {
        if (!m_requestHeaders.contains(HTTPHeaderName::ContentType)) {
            const String& blobType = body.type();
            if (!blobType.isEmpty() && isValidContentType(blobType))
                m_requestHeaders.set(HTTPHeaderName::ContentType, blobType);
            else {
                // From FileAPI spec, whenever media type cannot be determined, empty string must be returned.
                m_requestHeaders.set(HTTPHeaderName::ContentType, emptyString());
            }
        }

        m_requestEntityBody = FormData::create();
        m_requestEntityBody->appendBlob(body.url());
    }

    return createRequest();
}
コード例 #14
0
ファイル: webserver.c プロジェクト: viczzh/CS-118-Project-2
int main(int argc, char *argv[])
{
    signal(SIGALRM, timeOutHandler); // bind the timeOutHandler with the timer object.
   // int sockfd, newsockfd, cwnd_length, portno, pid;
	int newsockfd, cwnd_length, portno, pid;
    //float ploss, pcorr;
    char* tail;
    char* hi = "Received your message";

   // socklen_t clilen;
   //struct sockaddr_in serv_addr, cli_addr;


    if (argc < 5 && argc!=2) {
        fprintf(stderr,"ERROR, proper use: ./sender <port number> <cwnd> <p_loss> <p_corrupt>\n");
        exit(1);
    }
    if (argc==2){
	test=true;
    }

  if(test==false){
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    if (sockfd < 0)
        error("ERROR opening socket");

    bzero((char *) &serv_addr, sizeof(serv_addr));

    portno = atoi(argv[1]);
    cwnd_length = atoi(argv[2]);

    ploss = strtof(argv[3], &tail);
    pcorr = strtof(argv[4], &tail);

    printf( "Probability of Loss: %f\n",ploss);
    printf( "Probability of Corruption: %f\n\n", pcorr);

	

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(portno);

    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) //ANDREW CHANGE #2: casted &serv_addr to (struct sockaddr *) instead of (struct sockaddr_in*)
        error("ERROR on binding");

    clilen = sizeof(cli_addr);
  }

    FILE* requestFile; // FIXME: Read the document about allocate a new file in ram


   char* testInput;

   if (test==false){		//if not a test, read socket input into buffer
	while (1) {
		int n;
        	char buffer[256];

       	 	bzero(buffer, 256);
       		 n = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr*) &cli_addr, (socklen_t *) &clilen); //ANDREW CHANGE #3: casted &cli_addr to (struct sockaddr *)
        	if (n < 0)
            		error("ERROR reading from socket");
       		 else {
            		// fprintf(stdout, buffer);
           		 requestFile = findFile(buffer);
           		 break;
           		 // break out the initial round of request
            		// FIXME: if the file is not found, send something to client
       		 }
   	 } /* end of while */
   }
   else{		//if a test, read "test" into buffer
	 testInput = argv[1];
   	 printf( "\n\n\nmain()\n----------\nRequested Filename: %s\n\n\n",testInput);
	 requestFile = findFile(testInput);
   }

    /* init window */

    //FIRST BURST OF COMMANDS
	makeWindow(requestFile);		//allocate and construct window
	//if(test==true){
	if(1){
	  printWindow();
	}

    //FIXME: Not sure if anything missing
	
	
    int commandLength;	//single pointer to a single integer that saves the length of lastCommand()
    int* lastCommand = prepareToSend(&commandLength);
	printf( "Preparing to send\n{ ");
	 int p=0;
	for (p=0; p < commandLength; p++){
		if (p == commandLength - 1)
			printf( "%d }\n",lastCommand[p]);
		else
			printf( "%d, ",lastCommand[p]);
	}
	sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); // first send
        // TODO: free the lastCommand;

        free(lastCommand);
	commandLength=0;
	printWindow();
		
    alarm(1); // start timming cycle.
	
    while(1){
      //if timeout, resend
	if(resend == true){
		printf( "About to resend\n");
		lastCommand = prepareToSend(&commandLength);
		if(commandLength>0){
			printf( "Preparing to resend:\n{ ");
			printf( "%d }\n",lastCommand[0]);
			sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); 
		}
		free(lastCommand);
		resend=false;
	}
      // receving acks from recever:
      int n;
      char buffer[256]; // buffer for acks
      bzero(buffer, 256);
	
      n = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr*)&cli_addr, (socklen_t *) &clilen);
      if (n < 0)
          error("ERROR reading from socket");
      else {
        int ack = 0;

        // check if done
        if(strncmp("done", buffer, 4) == 0) {
          printf("Receiver signaled final fully sent! Terminating...\n");
          exit(0);
        }
        // TODO: parse the acks from buffer:
	ack = atoi(buffer);
        updateOnAcked(ack);

	 printWindow();
	if (isFinished()){
		printf( "Send complete! \n\n");
		break;
	}
	 
        lastCommand = prepareToSend(&commandLength);
	if(commandLength>0){
		printf( "Preparing to send:\n{ ");
		 int p=0;
		for (p=0; p < commandLength; p++){
			if (p == commandLength - 1)
				printf( "%d }\n",lastCommand[p]);
			else
				printf( "%d, ",lastCommand[p]);
		}
		sendPacket(lastCommand, commandLength, sockfd, (struct sockaddr*)&cli_addr, clilen); // first send
        	// TODO: free the lastCommand;
        	
   	}
	 else
		printf( "Nothing to Send \n\n");
	 printWindow();
	free(lastCommand);
	 commandLength=0;
        //TODO: free the lastCommand
        // free(lastCommand);
      }
    }
    return 0; /* we never get here */
}