コード例 #1
0
void Endpoint_v1::TicketRequest::onRequestFinished()
{
	QByteArray respbytes = reply->readAll();
	reply->deleteLater();
	std::string response ( respbytes.begin(), respbytes.end() );

	JSONNode respnode = libJSON::parse ( response );
	JSONNode errnode = respnode.at ( "error" );
	if (errnode.as_string() != "") {
		emit failed(QString("server_failure"), QString(errnode.as_string().c_str()));
		return;
	}

	available = FHttpApi::Data_GetTicketDefault;

	JSONNode subnode = respnode.at ("ticket");
	ticket = new Ticket();
	ticket->ticket = subnode.as_string().c_str();
	ticket->name = _un;
	ticket->password = _p;

	subnode = respnode.at("default_character");
	defaultCharacter = subnode.as_string().c_str();

	subnode = respnode.at("characters");
	qslFromJsonArray(subnode, characters);

	subnode = respnode.at("bookmarks");
	qslFromJsonArray(subnode, bookmarks);

	emit succeeded();
}
コード例 #2
0
ファイル: dropbox.cpp プロジェクト: ybznek/miranda-ng
void CDropbox::RequestAccountInfo(void *p)
{
	CDropbox *self = (CDropbox*)p;

	MCONTACT hContact = self->GetDefaultContact();

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	GetCurrentAccountRequest request(token);
	NLHR_PTR response(request.Send(self->hNetlibConnection));
	HandleJsonResponseError(response);

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty())
		return;

	JSONNode referral_link = root.at("referral_link");
	if (!referral_link.empty())
		db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());

	JSONNode email = root.at("email");
	if (!email.empty())
		db_set_s(hContact, MODULE, "e-mail", email.as_string().c_str());

	JSONNode name = root.at("name");
	if (!name.empty()) {
		db_set_utf(hContact, MODULE, "FirstName", name.at("given_name").as_string().c_str());
		db_set_utf(hContact, MODULE, "LastName", name.at("surname").as_string().c_str());
	}

	JSONNode country = root.at("country");
	if (!country.empty()) {
		std::string isocode = country.as_string();

		if (isocode.empty())
			db_unset(hContact, MODULE, "Country");
		else {
			char *szCountry = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
			db_set_s(hContact, MODULE, "Country", szCountry);
		}
	}

	/*JSONNode quota_info = root.at("quota_info");
	if (!quota_info.empty()) {
		ULONG lTotalQuota = quota_info.at("quota").as_int();
		ULONG lNormalQuota = quota_info.at("normal").as_int();
		ULONG lSharedQuota = quota_info.at("shared").as_int();

		db_set_dw(hContact, MODULE, "SharedQuota", lSharedQuota);
		db_set_dw(hContact, MODULE, "NormalQuota", lNormalQuota);
		db_set_dw(hContact, MODULE, "TotalQuota", lTotalQuota);

		db_set_s(hContact, "CList", "StatusMsg", CMStringA(FORMAT, Translate("Free %ld of %ld MB"), (lTotalQuota - lNormalQuota) / (1024 * 1024), lTotalQuota / (1024 * 1024)));
	}*/
}
コード例 #3
0
ファイル: usb.cpp プロジェクト: nonolith/connect
bool USB_device::processMessage(ClientConn& client, string& cmd, JSONNode& n){
	if (cmd == "controlTransfer"){
		unsigned id = jsonIntProp(n, "id", 0);
		uint8_t bmRequestType = jsonIntProp(n, "bmRequestType", 0xC0);
		uint8_t bRequest = jsonIntProp(n, "bRequest");
		uint16_t wValue = jsonIntProp(n, "wValue", 0);
		uint16_t wIndex = jsonIntProp(n, "wIndex", 0);
	
		bool isIn = bmRequestType & 0x80;
		
		JSONNode reply(JSON_NODE);
		reply.push_back(JSONNode("_action", "return"));
		reply.push_back(JSONNode("id", id));
		
		int ret = -1000;
		
		if (isIn){
			uint16_t wLength = jsonIntProp(n, "wLength", 64);
			if (wLength > 64) wLength = 64;
			if (wLength < 0) wLength = 0;
		
			uint8_t data[wLength];
			ret = controlTransfer(bmRequestType, bRequest, wValue, wIndex, data, wLength);
			
			if (ret >= 0){
				JSONNode data_arr(JSON_ARRAY);
				for (int i=0; i<ret && i<wLength; i++){
					data_arr.push_back(JSONNode("", data[i]));
				}
				data_arr.set_name("data");
				reply.push_back(data_arr);
			}
		}else{
			string datastr;
			JSONNode data = n.at("data");
			if (data.type() == JSON_ARRAY){
				for(JSONNode::iterator i=data.begin(); i!=data.end(); i++){
					datastr.push_back(i->as_int());
				}
			}else{
				datastr = data.as_string();
			}
			ret = controlTransfer(bmRequestType, bRequest, wValue, wIndex, (uint8_t *)datastr.data(), datastr.size());
		}
		
		reply.push_back(JSONNode("status", ret));
	
		client.sendJSON(reply);
	}else if(cmd == "enterBootloader"){
		std::cout << "enterBootloader: ";
		int r = controlTransfer(0x40|0x80, 0xBB, 0, 0, NULL, 100);
		std::cout << "return " <<  r << std::endl;
	}else{
		return false;
	}
	return true;
}
コード例 #4
0
ファイル: dropbox.cpp プロジェクト: kmdtukl/miranda-ng
void CDropbox::RequestAccountInfo()
{
	MCONTACT hContact = CDropbox::GetDefaultContact();

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	GetAccountInfoRequest request(token);
	NLHR_PTR response(request.Send(hNetlibConnection));
	HandleHttpResponseError(response);

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty())
		return;

	JSONNode referral_link = root.at("referral_link");
	if (!referral_link.empty())
		db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());

	JSONNode display_name = root.at("display_name");
	if (!display_name.empty())
	{
		ptrT display_name(mir_utf8decodeT(display_name.as_string().c_str()));
		TCHAR *sep = _tcsrchr(display_name, _T(' '));
		if (sep)
		{
			db_set_ts(hContact, MODULE, "LastName", sep + 1);
			display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0';
			db_set_ts(hContact, MODULE, "FirstName", display_name);
		}
		else
		{
			db_set_ts(hContact, MODULE, "FirstName", display_name);
			db_unset(hContact, MODULE, "LastName");
		}
	}

	JSONNode country = root.at("country");
	if (!country.empty())
	{
		std::string isocode = country.as_string();

		if (isocode.empty())
			db_unset(hContact, MODULE, "Country");
		else
		{
			char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
			db_set_s(hContact, MODULE, "Country", country);
		}
	}

	JSONNode quota_info = root.at("quota_info");
	if (!quota_info.empty())
	{
		db_set_dw(hContact, MODULE, "SharedQuota", quota_info.at("shared").as_int());
		db_set_dw(hContact, MODULE, "NormalQuota", quota_info.at("normal").as_int());
		db_set_dw(hContact, MODULE, "TotalQuota", quota_info.at("quota").as_int());
	}
}
コード例 #5
0
ファイル: dropbox.cpp プロジェクト: gloria8023/miranda-ng
void CDropbox::RequestAccountInfo()
{
	MCONTACT hContact = CDropbox::GetDefaultContact();

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	GetAccountInfoRequest request(token);
	NLHR_PTR response(request.Send(hNetlibConnection));
	HandleHttpResponseError(response);

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty())
		return;

	JSONNode referral_link = root.at("referral_link");
	if (!referral_link.empty())
		db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str());

	JSONNode display_name = root.at("display_name");
	if (!display_name.empty())
	{
		CMString tszDisplayName(display_name.as_mstring());
		int pos = tszDisplayName.ReverseFind(' ');
		if (pos != -1)
		{
			db_set_ts(hContact, MODULE, "LastName", tszDisplayName.Mid(pos+1));
			db_set_ts(hContact, MODULE, "FirstName", tszDisplayName.Left(pos));
		}
		else
		{
			db_set_ts(hContact, MODULE, "FirstName", tszDisplayName);
			db_unset(hContact, MODULE, "LastName");
		}
	}

	JSONNode country = root.at("country");
	if (!country.empty())
	{
		std::string isocode = country.as_string();

		if (isocode.empty())
			db_unset(hContact, MODULE, "Country");
		else
		{
			char *szCountry = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0);
			db_set_s(hContact, MODULE, "Country", szCountry);
		}
	}

	JSONNode quota_info = root.at("quota_info");
	if (!quota_info.empty())
	{
		db_set_dw(hContact, MODULE, "SharedQuota", quota_info.at("shared").as_int());
		db_set_dw(hContact, MODULE, "NormalQuota", quota_info.at("normal").as_int());
		db_set_dw(hContact, MODULE, "TotalQuota", quota_info.at("quota").as_int());
	}
}
コード例 #6
0
ファイル: ast.cpp プロジェクト: appwilldev/HQL
HQLOperand::HQLOperand(const JSONNode &n, OPERAND_TYPE ot)
{
    // ot == ID -> auto
    switch(n.type()){
    case JSON_NULL:
        type = NIL;
        break;
    case JSON_STRING:
        {
            if(ot == ID){
                type = ID;
                data.str = new string(n.as_string());
            }else{
                type = STRING;
                data.str = new string(string("\"") + n.as_string() + "\"");
            }
            break;
        }
    case JSON_NUMBER:
        {
            type = NUM;
            data.num = n.as_float();
            break;
        }
    case JSON_BOOL:
        {
            type = BOOL;
            data.boolean = n.as_bool();
            break;
        }
    case JSON_ARRAY:
    case JSON_NODE:
        {
            //TODO
            break;
        }
    default:
        type = NIL;
    }
}
コード例 #7
0
void SimulationAnimationPatch::loadJSON(const JSONNode data) {
	string patchName = data.name();

	// Load options for raytracer application. (window, ray tracer, filter)
	JSONNode::const_iterator i = data.begin();

	while (i != data.end()) {
		std::string nodeName = i->name();

		if (nodeName == "frameDirectory") {
			JSONNode fileName = *i;
			m_file_frameManager = new ArnoldFileFrameManager(fileName.as_string());
		}

		i++;
	}
}
コード例 #8
0
ファイル: dropbox_utils.cpp プロジェクト: wyrover/miranda-ng
void CDropbox::HandleJsonResponseError(NETLIBHTTPREQUEST *response)
{
	if (response == NULL)
		throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));

	if (response->resultCode == HTTP_STATUS_OK)
		return;

	if (response->resultCode != HTTP_STATUS_CONFLICT) {
		if (response->dataLength)
			throw DropboxException(response->pData);
		throw DropboxException(HttpStatusToText((HTTP_STATUS)response->resultCode));
	}

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty())
		throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));

	JSONNode error = root.at("error_summary");
	if (error.empty())
		return;

	throw DropboxException(error.as_string().c_str());
}
コード例 #9
0
void TestSuite::TestInspectors(void){
    UnitTest::SetPrefix("TestInspectors.cpp - Inspectors");
    JSONNode test = JSONNode(JSON_NULL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT(""));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
	   assertEquals(test.as_bool(), false);
    #endif

    test = 15.5f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("15.5"));
  #endif
    assertEquals(test.as_int(), 15);
    assertEquals(test.as_float(), 15.5f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), true);
    #endif

    test = 0.0f;
    assertEquals(test.type(), JSON_NUMBER);
  #ifdef JSON_CASTABLE
    assertEquals(test.as_string(), JSON_TEXT("0"));
  #endif
    assertEquals(test.as_int(), 0);
    assertEquals(test.as_float(), 0.0f);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_bool(), false);
    #endif

    test = true;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("true"));
	   assertEquals(test.as_int(), 1);
	   assertEquals(test.as_float(), 1.0f);
    #endif
    assertEquals(test.as_bool(), true);

    test = false;
    assertEquals(test.type(), JSON_BOOL);
    #ifdef JSON_CASTABLE
	   assertEquals(test.as_string(), JSON_TEXT("false"));
	   assertEquals(test.as_int(), 0);
	   assertEquals(test.as_float(), 0.0f);
    #endif
    assertEquals(test.as_bool(), false);

    #ifdef JSON_CASTABLE
	   test.cast(JSON_NODE);
    #else
	   test = JSONNode(JSON_NODE);
    #endif
    assertEquals(test.type(), JSON_NODE);
    assertEquals(test.size(), 0);
    test.push_back(JSONNode(JSON_TEXT("hi"), JSON_TEXT("world")));
    test.push_back(JSONNode(JSON_TEXT("hello"), JSON_TEXT("mars")));
    test.push_back(JSONNode(JSON_TEXT("salut"), JSON_TEXT("france")));
    assertEquals(test.size(), 3);
    TestSuite::testParsingItself(test);

    #ifdef JSON_CASTABLE
	   JSONNode casted = test.as_array();
	   #ifdef JSON_UNIT_TEST
		  assertNotEquals(casted.internal, test.internal);
	   #endif
	   assertEquals(casted.type(), JSON_ARRAY);
	   assertEquals(test.type(), JSON_NODE);
	   assertEquals(test.size(), 3);
	   assertEquals(casted.size(), 3);
	   TestSuite::testParsingItself(casted);
    #endif

    UnitTest::SetPrefix("TestInspectors.cpp - Location");

    try {
	   #ifdef JSON_CASTABLE
		  assertEquals(casted.at(0), JSON_TEXT("world"));
		  assertEquals(casted.at(1), JSON_TEXT("mars"));
		  assertEquals(casted.at(2), JSON_TEXT("france"));
		  assertEquals(casted.at(0).name(), JSON_TEXT(""));
		  assertEquals(casted.at(1).name(), JSON_TEXT(""));
		  assertEquals(casted.at(2).name(), JSON_TEXT(""));
	   #endif
	   assertEquals(test.at(0), JSON_TEXT("world"));
	   assertEquals(test.at(1), JSON_TEXT("mars"));
	   assertEquals(test.at(2), JSON_TEXT("france"));
	   assertEquals(test.at(0).name(), JSON_TEXT("hi"));
	   assertEquals(test.at(1).name(), JSON_TEXT("hello"));
	   assertEquals(test.at(2).name(), JSON_TEXT("salut"));
    } catch (std::out_of_range){
	   FAIL("exception caught");
    }

    try {
	   assertEquals(test.at(JSON_TEXT("hi")), JSON_TEXT("world"));
	   assertEquals(test.at(JSON_TEXT("hello")), JSON_TEXT("mars"));
	   assertEquals(test.at(JSON_TEXT("salut")), JSON_TEXT("france"));
	   #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
		  assertEquals(test.at_nocase(JSON_TEXT("SALUT")), JSON_TEXT("france"));
		  assertEquals(test.at_nocase(JSON_TEXT("HELLO")), JSON_TEXT("mars"));
		  assertEquals(test.at_nocase(JSON_TEXT("HI")), JSON_TEXT("world"));
	   #endif
    } catch (std::out_of_range){
	   FAIL("exception caught");
    }

    assertException(test.at(JSON_TEXT("meh")), std::out_of_range);
    #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
	   assertException(test.at_nocase(JSON_TEXT("meh")), std::out_of_range);
    #endif

    assertEquals(test[JSON_TEXT("hi")], json_string(JSON_TEXT("world")));
    assertEquals(test[JSON_TEXT("hello")], json_string(JSON_TEXT("mars")));
    assertEquals(test[JSON_TEXT("salut")], json_string(JSON_TEXT("france")));
    assertEquals(test[0], JSON_TEXT("world"));
    assertEquals(test[1], JSON_TEXT("mars"));
    assertEquals(test[2], JSON_TEXT("france"));

    #ifdef JSON_ITERATORS
	  #ifdef JSON_CASTABLE
	   UnitTest::SetPrefix("TestInspectors.cpp - Iterators");
	   for(JSONNode::iterator it = casted.begin(), end = casted.end(); it != end; ++it){
		  assertEquals((*it).name(), JSON_TEXT(""));
	   }
	  #endif
    #endif

    #ifdef JSON_BINARY
	   UnitTest::SetPrefix("TestInspectors.cpp - Binary");
	   test.set_binary((const unsigned char *)"Hello World", 11);
	   assertEquals(test.type(), JSON_STRING);
	   assertEquals(test.as_string(), JSON_TEXT("SGVsbG8gV29ybGQ="));
	   assertEquals(test.as_binary(), "Hello World");
	   assertEquals(test.as_binary().size(), 11);

	   test = JSON_TEXT("Hello World");
	   assertEquals(test.type(), JSON_STRING);
	   assertEquals(test.as_string(), JSON_TEXT("Hello World"));
	   #ifdef JSON_SAFE
		  assertEquals(test.as_binary(), "");
	   #endif
    #endif

   #ifdef JSON_READ_PRIORITY
	  //This is a regression test for a bug in at()
	  json_string buffer(JSON_TEXT("{ \"myValue1\" : \"foo\", \"myValue2\" : \"bar\"}"));
	  JSONNode current = libjson::parse(buffer);
	  try {
		  JSONNode & value1 = current[JSON_TEXT("myValue1")];
		  assertEquals(value1.as_string(), JSON_TEXT("foo"));
		  JSONNode & value2 = current[JSON_TEXT("myValue2")];
		  assertEquals(value2.as_string(), JSON_TEXT("bar"));
	  } catch (...){
		  assertTrue(false);
	  }
  #endif
}
コード例 #10
0
ファイル: dropbox.cpp プロジェクト: ybznek/miranda-ng
UINT CDropbox::RequestAccessTokenAsync(void *owner, void *param)
{
	HWND hwndDlg = (HWND)param;
	CDropbox *instance = (CDropbox*)owner;

	EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
	SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process..."));

	if (instance->HasAccessToken())
		instance->DestroyAccessToken();

	char requestToken[128];
	GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, _countof(requestToken));

	GetAccessTokenRequest request(requestToken);
	NLHR_PTR response(request.Send(instance->hNetlibConnection));

	if (response == NULL || response->resultCode != HTTP_STATUS_OK) {
		Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText(HTTP_STATUS_ERROR));
		if (hwndDlg)
			SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
		/*else
			ShowNotification(TranslateT("server does not respond"), MB_ICONERROR);*/
		return 0;
	}

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty()) {
		Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
		if (hwndDlg)
			SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));
		/*else
			ShowNotification((TCHAR*)error_description, MB_ICONERROR);*/
		return 0;
	}

	JSONNode node = root.at("error_description");
	if (node != JSONNULL) {
		ptrT error_description(mir_a2t_cp(node.as_string().c_str(), CP_UTF8));
		Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, HttpStatusToText((HTTP_STATUS)response->resultCode));
		if (hwndDlg)
			SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
		/*else
			ShowNotification((TCHAR*)error_description, MB_ICONERROR);*/
		return 0;
	}

	node = root.at("access_token");
	db_set_s(NULL, MODULE, "TokenSecret", node.as_string().c_str());
	ProtoBroadcastAck(MODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_OFFLINE, (WPARAM)ID_STATUS_ONLINE);

	MCONTACT hContact = instance->GetDefaultContact();
	if (hContact) {
		if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE)
			db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
	}

	try {
		RequestAccountInfo(instance);
	}
	catch (DropboxException &ex) {
		Netlib_Logf(instance->hNetlibConnection, "%s: %s", MODULE, ex.what());
		return 0;
	}

	if (hwndDlg)
		SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
	/*else
		ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/

	SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");

	return 0;
}
コード例 #11
0
ファイル: ast.cpp プロジェクト: appwilldev/HQL
bool HQLOperand::predicate(const HQLOperand &o, const JSONNode &n)
{
    if(type != COOP){
        return false;
    }

    switch(data.coop){
    case COND_OPER::EQ:
        return CompareHQLOperandAndJSONNode<COND_OPER::EQ>(o, n);
        break;
    case COND_OPER::GT:
        return CompareHQLOperandAndJSONNode<COND_OPER::GT>(o, n);
        break;
    case COND_OPER::LT:
        return CompareHQLOperandAndJSONNode<COND_OPER::LT>(o, n);
        break;
    case COND_OPER::GE:
        return CompareHQLOperandAndJSONNode<COND_OPER::GE>(o, n);
        break;
    case COND_OPER::LE:
        return CompareHQLOperandAndJSONNode<COND_OPER::LE>(o, n);
        break;
    case COND_OPER::IN:
        {
            if(o.get_type()==NUM_ARRAY){
                if(n.type()==JSON_NUMBER){
                    string ns=num2str(n.as_int());
                    vector<string>::const_iterator it=o.as_str_array()->begin();
                    for(;it!=o.as_str_array()->end();it++){
                        if(ns==*it)return true;
                    }
                    return false;
                }
                return false;
            }else if(o.get_type()==STR_ARRAY){
                if(n.type()==JSON_STRING){
                    string ns=n.as_string();
                    vector<string>::const_iterator it=o.as_str_array()->begin();
                    for(;it!=o.as_str_array()->end();it++){
                        if(ns==*it)return true;
                    }
                    return false;
                }
                return false;
            }
            return false;
            break;
        }
    case COND_OPER::CONTAINS:
        {
            string val = o.as_str_array()->at(0);
            string sep = o.as_str_array()->at(1);
            string ns=n.as_string();
            string unit;
            string::size_type start = 0, end = 0;
            while(end!=string::npos){
                end = ns.find_first_of(sep, start);
                if(end==string::npos){
                    unit = ns.substr(start);
                }else{
                    unit = ns.substr(start, end-start);
                }
                start = end + 1;
                if(val == "\"" + unit + "\""){
                    return true;
                }
            }
            return false;
            break;
        }
    case COND_OPER::TIME_IN:
        {
            if(n.type()!=JSON_NUMBER) return false;
            if(o.get_type()!=NUM) return false;
            time_t now = time(NULL);
            return now-o.as_num() <= n.as_float();
            break;
        }
    default:
        return false;
    }
    return false;
}
コード例 #12
0
      PresetReaderJson::PresetReaderJson(std::string data) {
        LOGDEBUG("Preset Data:" << data);
        JSONNode node = libjson::parse(data);
        if(node.contains("profile-uuid")){
          db::HiveDb db=DatabaseService::getDatabase();//"sqlite3", org::esb::config::Config::get("db.url"));
          litesql::DataSource<db::Preset>s = litesql::select<db::Preset > (db, db::Preset::Uuid == node["profile-uuid"].as_string());
          if(s.count()==1){
            data=s.one().data;
          }else{
            throw org::esb::lang::Exception(__FILE__,__LINE__,"profile defined by profile-uuid not found");
          }
          node = libjson::parse(data);
        }
        if (node.contains("format") && node["format"].contains("id")) {
          _preset["id"] = node["format"]["id"].as_string();
          if(node.contains("name")){
            _preset["name"]=node["name"].as_string();
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no format attribute found");
        }
        std::string type;
        type = "video";
        if (node.contains(type)) {
          int c = node[type].size();
          for (int a = 0; a < c; a++) {
            JSONNode n = node[type].at(a);
            std::string name = n.name();
            std::string value = n.as_string();
            /*filter out some unwanted attributes*/
            if (name == "frame_size"){
              int width;
              int height;
              int result=sscanf(value.c_str(),"%dx%d", &width, &height);
              LOGDEBUG("width="<<width);
              LOGDEBUG("width="<<height);
              _codecs[type]["width"]=StringUtil::toString(width);
              _codecs[type]["height"]=StringUtil::toString(height);
              continue;
            }
            //LOGDEBUG("json type : "<<n.type());
            if (name == "id") {
              name = "codec_id";
            }
            if (name == "b" || name == "maxrate" || name == "bt" || name == "bufsize" || name == "minrate")
              value += "000";
            LOGDEBUG("Name=" << name << " val=" << value);

            _codecs[type][name] = value; //.insert(std::pair<std::string, std::string>(name,value));
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no video attribute found");
        }
        type = "audio";
        if (node.contains(type)) {
          int c = node[type].size();
          for (int a = 0; a < c; a++) {
            JSONNode n = node[type].at(a);
            LOGDEBUG("Name=" << n.name() << " val=" << n.as_string());
            if (n.name() == "id") {
              n.set_name("codec_id");
              //AVCodec * codec=avcodec_find_encoder_by_name(n.as_string().c_str());
              //n=JSONNode("codec_id",codec->id);
            }
            _codecs[type][n.name()] = n.as_string(); //.insert(std::pair<std::string, std::string>(n.name(),n.as_string()));
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no audio attribute found");
        }
      }
コード例 #13
0
ファイル: ast_slfk.cpp プロジェクト: appwilldev/HQL
const map<uint64_t, set<string> > SLFKCondNode::match(const Model &m, ModelGetter *getter)
{
    map<uint64_t, set<string> > ret;
    if(m.attr<bool>("deleted")) return ret;
    //uint64_t fn = m.fullname();
    uint64_t gn = m.attr<uint64_t>(*operands[1].as_str());
    string type = m.type();

    string attr = *operands[3].as_str();
    JSONNode v = m.attr<JSONNode>(attr);
    if(v.type()==JSON_NODE && v.size()<=0){
        return ret;
    }

    if(!TypeConfig::is_subtype(type, *operands[0].as_str())){
        // this will not happens
        return ret;
    }

    if(TypeConfig::type_id(*operands[0].as_str())==0){
        gn = FULLNAME_SET_CAT(gn);
    }

    if(this->has_semantic_each()){
        switch(operands[4].as_coop_type()){
        case COND_OPER::EQ:
            {
                HQLOperand o = HQLOperand(v);
                SLFKCondNode n = SLFKCondNode(type,
                                              *operands[1].as_str(),
                                              etype,
                                              attr,
                                              operands[4],
                                              o);
                ret[gn].insert(n.cache_key());
                break;
            }
        case COND_OPER::CONTAINS:
            {
                string sep = operands[5].as_str_array()->at(1);
                string val = v.as_string();
                string unit;
                string::size_type start = 0, end = 0;
                while(end!=string::npos){
                    end = val.find_first_of(sep, start);
                    if(end==string::npos){
                        unit = val.substr(start);
                    }else{
                        unit = val.substr(start, end-start);
                    }
                    start = end + 1;
                    if(unit.size()<1) continue;
                    vector<string> *arg = new vector<string>;//({unit, sep});
                    arg->push_back("\"" + unit + "\"");
                    arg->push_back(sep);
                    HQLOperand o = HQLOperand(arg, HQLOperand::CONTAINS_ARG);

                    SLFKCondNode n = SLFKCondNode(type,
                                                  *operands[1].as_str(),
                                                  etype,
                                                  attr,
                                                  operands[4],
                                                  o);
                    ret[gn].insert(n.cache_key());
                }
                break;
            }
        default:
            {
                //this will not happens
                return ret;
            }
        }
    }else{
        if(operands[4].predicate(operands[5], v)){
            ret[gn].insert(this->cache_key());
        }
    }

    return ret;
}