Exemplo n.º 1
0
void
ProjectGiraffeTab1::updateItems()
{
#if kDebugUseDummyItems
	AppLog("Creating dummy items");
	User *dummyUser = new User();
	dummyUser->setUsername(L"Username");
	for (int i = 0; i < 10; i++) {
		Graffiti *graffiti = new Graffiti();
		graffiti->setUser(dummyUser);
		graffiti->setText(L"dummy string");
		_items->Add(graffiti);
	}

#else

#if kDebugUseHttpConnection

	double latitude = ProjectGiraffeMainForm::currentLatitude;
	double longitude = ProjectGiraffeMainForm::currentLongitude;
	HttpConnection *connection = HttpConnection::graffitiNearbyGetConnection(this,latitude,longitude);
	connection->begin();

#else
	// Kick off http request for items based on location.
	// Populate item source array
	HttpSession* pHttpSession = null;
	HttpTransaction* pHttpTransaction = null;
	String* pProxyAddr = null;
	String hostAddr = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";
	String uri = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";

	AppLog("Starting the HTTP Session");
	pHttpSession = new HttpSession();

	// HttpSession construction.
	pHttpSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, null);

	// Open a new HttpTransaction.
	pHttpTransaction = pHttpSession->OpenTransactionN();

	// Add a listener.
	pHttpTransaction->AddHttpTransactionListener(*this);

	// Get an HTTP request.
	HttpRequest* pHttpRequest = pHttpTransaction->GetRequest();

	// Set the HTTP method and URI:
	pHttpRequest->SetMethod(NET_HTTP_METHOD_GET);
	pHttpRequest->SetUri(uri);

	// Submit the request:
	pHttpTransaction->Submit();
#endif

#endif
}
Exemplo n.º 2
0
String IRailConnection::getTrip(String &from, String &to,TrainsResultsForm *pTrainsResultsForm) {
	this->pTrainsResultsForm = pTrainsResultsForm;
	result r = E_SUCCESS;
	String* pProxyAddr = null;
	String hostAddr = L"http://api.irail.be";
	String hostAddr2(L"http://api.irail.be/connections/?to=");
	hostAddr2.Append(to);
	hostAddr2.Append(L"&from=");
	hostAddr2.Append(from);
	HttpSession* pSession = null;
	HttpTransaction* pTransaction = null;

	pSession = new HttpSession();
	r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr ,hostAddr,null);
	if (IsFailed(r))
	{
		AppLog("Construct Session failed. (%s)\n", GetErrorMessage(r));
	}
	pTransaction = pSession->OpenTransactionN();
	if (null == pTransaction)
	{
		AppLog("Construct Session failed. \n");
	}
	r = pTransaction->AddHttpTransactionListener(*this);
	if (IsFailed(r))
	{
		AppLog("AddHttpTransactionListener Session failed.\n");
	}
	HttpRequest* pRequest = pTransaction->GetRequest();
	if(pRequest == null)
	{
		AppLog("GetRequest failed. \n");
	}

	r = pRequest->SetUri(hostAddr2);
	if(IsFailed(r))
	{
		AppLog("SetUri failed. (%s)\n", GetErrorMessage(r));
	}

	r = pRequest->SetMethod(NET_HTTP_METHOD_GET);
	if(IsFailed(r))
	{
		AppLog("SetMethod failed. (%s)\n", GetErrorMessage(r));
	}
	r = pTransaction->Submit();
	if(IsFailed(r))
	{
		AppLog("Submit failed. (%s)\n", GetErrorMessage(r));
	}
	return hostAddr;
}
Exemplo n.º 3
0
 bool IsCompleted( const HttpTransactionHandle& handle )
 {
     HttpTransaction* transaction = _GetCurlHandle( handle.GetHandleId() );
     if( transaction )
     {
         return transaction->IsCompleted();
     }
     else
     {
         // 存在しないハンドルなので、既に終了して削除されている可能性がある
         return true;
     }
 }
Exemplo n.º 4
0
void
Network::IsReachable(const String& hostAddr) {
	String* pProxyAddr = null;
	//String hostAddr = L"http://localhost:port";
	AppLogDebug("Trying to reach...%S", hostAddr.GetPointer());
	__pHttpSession = new HttpSession();
	__pHttpSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, null);
	HttpTransaction* pHttpTransaction = __pHttpSession->OpenTransactionN();
	pHttpTransaction->AddHttpTransactionListener(*this);
	HttpRequest* pHttpRequest = pHttpTransaction->GetRequest();
	pHttpRequest->SetMethod(NET_HTTP_METHOD_GET);
	pHttpRequest->SetUri(hostAddr);
	pHttpTransaction->Submit();
}
Exemplo n.º 5
0
void VKURequestData::OnTransactionCertVerificationRequiredN(HttpSession& httpSession, HttpTransaction& httpTransaction, Tizen::Base::String* pCert) {
    AppLog("OnTransactionCertVerificationRequiredN");

    httpTransaction.Resume();

    delete pCert;
}
Exemplo n.º 6
0
void VKURequestData::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen) {
    AppLog("OnTransactionReadyToRead");

    HttpResponse* pHttpResponse = httpTransaction.GetResponse();

    if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK) {
        HttpHeader* pHttpHeader = pHttpResponse->GetHeader();
        if (pHttpHeader != null) {
            //String* tempHeaderString = pHttpHeader->GetRawHeaderN();
            ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();

            String text(L"Read Body Length: ");
            text.Append(availableBodyLen);

            AppLog("len: %ls", text.GetPointer());

            data.CopyFrom(*pBuffer);

            //delete tempHeaderString;
            delete pBuffer;
        }
    }

    return;

}
Exemplo n.º 7
0
result Chatting::RequestHttpPost(void) {
	result r = E_SUCCESS;
	HttpSession* pSession = null;
	HttpTransaction* pTransaction = null;
	HttpRequest* pRequest = null;
	HttpMultipartEntity* pMultipartEntity = null;
	String hostAddr(HTTP_CLIENT_HOST_ADDRESS);

	// Creates an HTTP session.
	pSession = new HttpSession();
	r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);

	pTransaction = pSession->OpenTransactionN();
	r = pTransaction->AddHttpTransactionListener(*this);
	//  r = pTransaction->SetHttpProgressListener(*this);

	pRequest = pTransaction->GetRequest();
	pRequest->SetMethod(NET_HTTP_METHOD_POST);
	r = pRequest->SetUri(HTTP_CLIENT_REQUEST_URI);

	pMultipartEntity = new HttpMultipartEntity();
	r = pMultipartEntity->Construct();

	String me = __pEditField->GetText();

	Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"UTF-8");

	pMultipartEntity->AddStringPart(L"message", me, L"text/plain", L"UTF-8",
			*pEnc);
	r = pMultipartEntity->AddStringPart(L"friendIdRegId", resultRegId);

	r = pRequest->SetEntity(*pMultipartEntity);
	r = pTransaction->Submit();

	return r;
}
Exemplo n.º 8
0
void
UserProfileForm::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool rs)
{

	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	if(pHttpResponse == null)
		return;
	HttpHeader* pHttpHeader = pHttpResponse->GetHeader();
	if(pHttpHeader != null)
	{
		String* tempHeaderString = pHttpHeader->GetRawHeaderN();
		AppLog("HeaderString=%ls\n",tempHeaderString->GetPointer());
	}

	AppLog("OnTransactionHeaderCompleted\n");
}
Exemplo n.º 9
0
void HttpThread::OnTransactionCompleted(HttpSession & /*httpSession*/,
                                          HttpTransaction & httpTransaction)
{
  HttpResponse * pResponse = httpTransaction.GetResponse();
  if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK
      || pResponse->GetHttpStatusCode() == HTTP_STATUS_PARTIAL_CONTENT)
  {
    m_callback.OnFinish(200, m_begRange, m_endRange);
  }
  else
  {
    LOG(LWARNING, ("Download has finished with status code:", pResponse->GetHttpStatusCode(),
                   " and text:", FromTizenString(pResponse->GetStatusText() )));
    m_callback.OnFinish(-100, m_begRange, m_endRange);
  }
}
Exemplo n.º 10
0
void
Network::OnTransactionCompleted (HttpSession &httpSession, HttpTransaction &httpTransaction) {
	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	NetHttpStatusCode statusCode = pHttpResponse->GetStatusCode();
	int status = 1; // Default is DATA NETWORK

	// FIXME: Bada has no standard/apparent way of knowing the current network type
	// We have to get the network type from the system info
	// ...and if Wifi is enabled we override the setting to Wifi

	String key(L"NetworkType");
	String networkType;

	result r = SystemInfo::GetValue(key, networkType);

	if(r == E_SUCCESS && networkType != L"NoService" && networkType != L"Emergency") {
		AppLogDebug("Data Enabled, Network Type %S, Status Code: %d", networkType.GetPointer(), statusCode);
		status = 1;
	}

	Wifi::WifiManager manager;
	if(manager.IsActivated() && manager.IsConnected()) {
		AppLogDebug("Wifi Enabled");
		status = 2;
	}

	String res;

	res.Format(256, L"navigator.network.updateReachability({code:%d,http_code:%d});", status, statusCode);
	AppLogDebug("%S", res.GetPointer());
	pWeb->EvaluateJavascriptN(res);

	res.Format(128, L"Cordova.callbacks['%S'].success({code:%d,http_code:%d});", callbackId.GetPointer(), status, statusCode);
	AppLogDebug("%S", res.GetPointer());
	pWeb->EvaluateJavascriptN(res);
}
Exemplo n.º 11
0
void
UserProfileForm::OnTransactionCertVerificationRequiredN(HttpSession& httpSession, HttpTransaction& httpTransaction, Osp::Base::String* pCert)
{
	httpTransaction.Resume();
	AppLog("OnTransactionCertVerificationRequiredN\n");
}
Exemplo n.º 12
0
void
UserProfileForm::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen)
{

	AppLogDebug("OnTransactionReadyToRead,..availableBodyLen=%d",availableBodyLen);
	count++;

	HttpResponse* pHttpResponse = httpTransaction.GetResponse();

	if(pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
	{
		__pBuffer = pHttpResponse->ReadBodyN();
	}
	if(__pProfileName==NULL)
	{
		ParseJsonData();
		Label *pLabel = new Label();
		String labelText(L"Welcome ");
		labelText.Append(*__pProfileName);
		AppLog("labelText is =%ls",labelText.GetPointer());
		pLabel->Construct(Rectangle(05, 50, 500, 100), labelText);
		AddControl(*pLabel);
		Draw();
		Show();

		__pSession->CloseTransaction(httpTransaction);
		delete __pSession;
		__pSession = null;
	}

	//Get Profile Picture

	String imageurl;
	imageurl.Append(L"https://graph.facebook.com/me");
	imageurl.Append(L"/picture?");
	imageurl.Append(L"access_token=");
	imageurl.Append(__accessToken);
	SendRequestGet(imageurl);

	__pProfileImage = new Image();
	__pProfileImage->Construct();

	Bitmap *pBitmap;
	pBitmap=__pProfileImage->DecodeN(*__pBuffer,IMG_FORMAT_JPG,BITMAP_PIXEL_FORMAT_ARGB8888,150,150);
	Label *pImageLabel = new Label();
	pImageLabel->Construct(Rectangle(150,150, 150, 150),"");
	pImageLabel->SetBackgroundBitmap(*pBitmap);
	AddControl(*pImageLabel);

	Button* pGetFriends = new Button();
	pGetFriends->Construct(Rectangle(30,330, 350, 70), L"Get Friends");
	pGetFriends->SetActionId(ID_BUTTON_FRIENDS_CLICKED);
	pGetFriends->AddActionEventListener(*this);
	AddControl(*pGetFriends);

	Button* pLogout = new Button();
	pLogout->Construct(Rectangle(30,430, 350, 70), L"Logout");
	pLogout->SetActionId(ID_BUTTON_LOGOUT_CLICKED);
	pLogout->AddActionEventListener(*this);
	AddControl(*pLogout);
	Draw();
	Show();

}
Exemplo n.º 13
0
void IRailConnection::OnTransactionReadyToRead(HttpSession& httpSession,
		HttpTransaction& httpTransaction, int availableBodyLen) {
	//LEZEN werkt !
	ArrayListT<Connection> connections;
	connections.Construct(10);
	HttpResponse* resp = httpTransaction.GetResponse();
	ByteBuffer* buf = (resp->ReadBodyN());
	xmlDocPtr doc =
			xmlParseMemory((char*) (buf->GetPointer()), buf->GetLimit());
	if (doc != null) {
		xmlNodePtr connection = null;
		xmlNodePtr pRoot = xmlDocGetRootElement(doc);
		for (connection = pRoot->children; connection; connection
				= connection->next) {
			xmlNodePtr child = null;
			Connection con;
			for (child = connection->children; child; child = child->next) {
				if (child->type == XML_ELEMENT_NODE) {

					String nodeName;
					Osp::Base::Utility::StringUtil::Utf8ToString(
							(char*) child->name, nodeName);
					if (nodeName.CompareTo("departure") == 0) {
						xmlNodePtr child1 = null;
						for (child1 = child->children; child1; child1
								= child1->next) {
							if (child1->type == XML_ELEMENT_NODE) {
								String nodeName1;
								Osp::Base::Utility::StringUtil::Utf8ToString(
										(char*) child1->name, nodeName1);
								if (nodeName1.CompareTo("time") == 0) {
									xmlAttrPtr isoTime = child1->properties;
									if (isoTime != null && isoTime->type
											== XML_ATTRIBUTE_NODE) {
										String time;
										Osp::Base::Utility::StringUtil::Utf8ToString(
												(char*) isoTime->children->content,
												time);
										con.setFromTime(time);
									}
								} else if (nodeName1.CompareTo("station") == 0) {
									String station;
									Osp::Base::Utility::StringUtil::Utf8ToString(
											(char*) child1->children->content,
											station);
									con.setFromStation(station);
								}
							}
						}
					} else if (nodeName.CompareTo("arrival") == 0) {
						xmlNodePtr child1 = null;
						for (child1 = child->children; child1; child1
								= child1->next) {
							if (child1->type == XML_ELEMENT_NODE) {
								String nodeName1;
								Osp::Base::Utility::StringUtil::Utf8ToString(
										(char*) child1->name, nodeName1);
								if (nodeName1.CompareTo("time") == 0) {
									xmlAttrPtr isoTime = child1->properties;
									if (isoTime != null && isoTime->type
											== XML_ATTRIBUTE_NODE) {
										String time;
										Osp::Base::Utility::StringUtil::Utf8ToString(
												(char*) isoTime->children->content,
												time);
										con.setToTime(time);
									}
								} else if (nodeName1.CompareTo("station") == 0) {
									String station;
									Osp::Base::Utility::StringUtil::Utf8ToString(
											(char*) child1->children->content,
											station);
									con.setToStation(station);
								}
							}
						}
					} else if (nodeName.CompareTo("duration") == 0) {
						String duration_;
						Osp::Base::Utility::StringUtil::Utf8ToString(
								(char*) child->children->content, duration_);
						int duration;
						Integer::Parse(duration_, duration);
						con.setDuration(duration);
					}
				}
			}
			if(con != null) {
				connections.Add(con);
			}
		}
		xmlFreeDoc(doc);
		this->pTrainsResultsForm->setConnections(connections);
	} else {
		AppLog("parsing internet file failed");
	}
}
Exemplo n.º 14
0
void
ProjectGiraffeTab1::OnTransactionReadyToRead (HttpSession &httpSession, HttpTransaction &httpTransaction, int availableBodyLen)
{
	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	HttpHeader* pHttpHeader = null;
	AppLog("Checking HTTP Status Code");
	if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
	{
		//		MessageBox msgBox;
		//		msgBox.Construct(L"HTTP STATUS", L"HTTP Request OK", MSGBOX_STYLE_NONE, 3000);
		//		int modalresult = 0;
		//		msgBox.ShowAndWait(modalresult);

		ByteBuffer* pBody = null;
		String statusText = pHttpResponse->GetStatusText();
		String version = pHttpResponse->GetVersion();

		pHttpHeader = pHttpResponse->GetHeader();
		pBody = pHttpResponse->ReadBodyN();
		//delete pBody;

		//Parses from ByteBuffer
		IJsonValue* pValue = JsonParser::ParseN(*pBody);

		AppLog("Received HTTP response.");

		AppLog("Before traverse %d", _tableView->GetItemCount());
		_pJsonKeyList->RemoveAll(true);
		_pValueList->RemoveAll(true);
		_items->RemoveAll(true);
		// Populate the panel
		TraverseFunction(pValue);

		AppLog("After traverse");

		//clean up allocated jsonValues
		if (pValue->GetType() == JSON_TYPE_OBJECT)
		{
			// Converts the pValue to JsonObject
			JsonObject* pObject = static_cast< JsonObject* >(pValue);
			pObject->RemoveAll(true);
		}
		else if (pValue->GetType() == JSON_TYPE_ARRAY)
		{
			// Converts the pValue to JsonArray
			JsonArray* pArray = static_cast< JsonArray* >(pValue);
			pArray->RemoveAll(true);
		}

		delete pBody;
		delete pValue;
		_tableView->ScrollToItem(0);



	}else{
		AppLog("HTTP Status not OK");
	}
	//Remove load icon here.
	//_loadingPopupThread->Quit();
	//_loadingPopupThread->Join();
}
Exemplo n.º 15
0
void HttpThread::OnTransactionHeaderCompleted(HttpSession & httpSession,
                                              HttpTransaction & httpTransaction,
                                              int headerLen, bool bAuthRequired)
{
  result r = E_SUCCESS;
  HttpResponse * pResponse = httpTransaction.GetResponse();
  if ((r = GetLastResult()) != E_SUCCESS)
  {
    LOG(LWARNING, ("httpTransaction.GetResponse error", r));
    httpSession.CancelTransaction(httpTransaction);
    httpSession.CloseTransaction(httpTransaction);
    m_callback.OnFinish(-1, m_begRange, m_endRange);
    return;
  }

  int const httpStatusCode = pResponse->GetHttpStatusCode();
  // When we didn't ask for chunks, code should be 200
  // When we asked for a chunk, code should be 206
  bool const isChunk = !(m_begRange == 0 && m_endRange < 0);
  if ((isChunk && httpStatusCode != 206) || (!isChunk && httpStatusCode != 200))
  {
    LOG(LWARNING, ("Http request to", m_url, " aborted with HTTP code", httpStatusCode));
    httpSession.CancelTransaction(httpTransaction);
    r = httpSession.CloseTransaction(httpTransaction);
    m_callback.OnFinish(-4, m_begRange, m_endRange);
    LOG(LDEBUG, ("CloseTransaction result", r));
    return;
  }
  else if (m_expectedSize > 0)
  {
    bool bGoodSize = false;
    // try to get content length from Content-Range header first
    HttpHeader * pHeader = pResponse->GetHeader();
    LOG(LDEBUG, ("Header:", FromTizenString(*pHeader->GetRawHeaderN())));
    IEnumerator * pValues = pHeader->GetFieldValuesN("Content-Range");
    if (GetLastResult() == E_SUCCESS)
    {
      bGoodSize = true;
      pValues->MoveNext(); // strange, but works
      String const * pString = dynamic_cast<String const *>(pValues->GetCurrent());

      if (pString->GetLength())
      {
        int lastInd;
        pString->LastIndexOf ('/', pString->GetLength()-1, lastInd);
        int64_t value = -1;
        String tail;
        pString->SubString(lastInd + 1, tail);
        LOG(LDEBUG, ("tail value:",FromTizenString(tail)));
        LongLong::Parse(tail, value);
        if (value != m_expectedSize)
        {
          LOG(LWARNING, ("Http request to", m_url,
                         "aborted - invalid Content-Range:", value, " expected:", m_expectedSize ));
          httpSession.CancelTransaction(httpTransaction);
          r = httpSession.CloseTransaction(httpTransaction);
          m_callback.OnFinish(-2, m_begRange, m_endRange);
          LOG(LDEBUG, ("CloseTransaction result", r));
        }
      }
    }
    else
    {
      pValues = pHeader->GetFieldValuesN("Content-Length");
      if (GetLastResult() == E_SUCCESS)
      {
        bGoodSize = true;
        pValues->MoveNext();  // strange, but works
        String const * pString = dynamic_cast<String const *>(pValues->GetCurrent());
        if (pString)
        {
          int64_t value = -1;
          LongLong::Parse(*pString, value);
          if (value != m_expectedSize)
          {
            LOG(LWARNING, ("Http request to", m_url,
                           "aborted - invalid Content-Length:", value, " expected:", m_expectedSize));
            httpSession.CancelTransaction(httpTransaction);
            r = httpSession.CloseTransaction(httpTransaction);
            m_callback.OnFinish(-2, m_begRange, m_endRange);
            LOG(LDEBUG, ("CloseTransaction result", r));
          }
        }
      }
    }

    if (!bGoodSize)
    {
      LOG(LWARNING, ("Http request to", m_url,
                     "aborted, server didn't send any valid file size"));
      httpSession.CancelTransaction(httpTransaction);
      r = httpSession.CloseTransaction(httpTransaction);
      m_callback.OnFinish(-2, m_begRange, m_endRange);
      LOG(LDEBUG, ("CloseTransaction result", r));
    }
  }
}