Beispiel #1
0
 void processCurrentAuthCandidate()
 {
   if (currentAuthCandidate!=authCandidates.end() && hueComm.findInProgress) {
     // try to authorize
     FOCUSLOG("Auth candidate: uuid=%s, baseURL=%s -> try creating user", currentAuthCandidate->first.c_str(), currentAuthCandidate->second.c_str());
     JsonObjectPtr request = JsonObject::newObj();
     request->add("username", JsonObject::newString(userName));
     request->add("devicetype", JsonObject::newString(deviceType));
     hueComm.apiAction(httpMethodPOST, currentAuthCandidate->second.c_str(), request, boost::bind(&BridgeFinder::handleCreateUserAnswer, this, _1, _2), true);
   }
   else {
     // done with all candidates (or find aborted in hueComm)
     if (authCandidates.size()>0 && MainLoop::now()<startedAuth+authTimeWindow && hueComm.findInProgress) {
       // we have still candidates and time to do a retry in a second, and find is not aborted
       retryLoginTicket = MainLoop::currentMainLoop().executeOnce(boost::bind(&BridgeFinder::attemptPairingWithCandidates, this), 1*Second);
       return;
     }
     else {
       // all candidates tried, nothing found in given time
       LOG(LOG_NOTICE, "Could not register with a hue bridge");
       hueComm.findInProgress = false;
       callback(ErrorPtr(new HueCommError(HueCommErrorNoRegistration, "No hue bridge found ready to register")));
       // done!
       keepAlive.reset(); // will delete object if nobody else keeps it
       return;
     }
   }
 }
Beispiel #2
0
 void processCurrentBridgeCandidate()
 {
   if (currentBridgeCandidate!=bridgeCandiates.end()) {
     // request description XML
     hueComm.bridgeAPIComm.httpRequest(
       (currentBridgeCandidate->second).c_str(),
       boost::bind(&BridgeFinder::handleServiceDescriptionAnswer, this, _1, _2),
       "GET"
     );
   }
   else {
     // done with all candidates
     if (refind) {
       // failed getting description, return error
       callback(ErrorPtr(new HueCommError(HueCommErrorDescription)));
       keepAlive.reset(); // will delete object if nobody else keeps it
       return; // done
     }
     else {
       // finding new bridges - attempt user login
       bridgeCandiates.clear();
       // now attempt to pair with one of the candidates
       startedAuth = MainLoop::now();
       attemptPairingWithCandidates();
     }
   }
 }
Beispiel #3
0
 const TCHAR *GetECLType(const std::_tstring & colID) const
 {
     clib::recursive_mutex::scoped_lock proc(m_mutex);
     StringStringMap::const_iterator found = m_schemaMap.find(colID);
     if (found != m_schemaMap.end()) 
     {
         return found->second.c_str();
     }
     return NULL;
 }
	const char * GetPath(const std::string & _label)
	{
		split_vector_type labels; 
		boost::algorithm::split(labels, _label, boost::algorithm::is_any_of(","), boost::algorithm::token_compress_on);
		for(split_vector_type::const_iterator itr = labels.begin(); itr != labels.end(); ++itr)
		{
			StringStringMap::const_iterator found = m_familynamePath.find(*itr);
			if (found != m_familynamePath.end())
				return found->second.c_str();

			found = m_stemPath.find(*itr);
			if (found != m_stemPath.end())
				return found->second.c_str();
		}

		return GetDefaultPath();
	}
Beispiel #5
0
 void bridgeRefindHandler(SsdpSearchPtr aSsdpSearch, ErrorPtr aError)
 {
   if (!Error::isOK(aError)) {
     // could not find bridge, return error
     callback(ErrorPtr(new HueCommError(HueCommErrorUuidNotFound)));
     keepAlive.reset(); // will delete object if nobody else keeps it
     return; // done
   }
   else {
     // found, now get description to get baseURL
     // - put it into queue as the only candidate
     bridgeCandiates.clear();
     bridgeCandiates[aSsdpSearch->uuid.c_str()] = aSsdpSearch->locationURL.c_str();
     // process the candidate
     currentBridgeCandidate = bridgeCandiates.begin();
     processCurrentBridgeCandidate();
   }
 }
Beispiel #6
0
static int handle_request(void* /*cls*/, MHD_Connection* connection, const char* url, const char* method, const char*, const char*, unsigned int*, void** /*con_cls*/) {
  if (std::string(method) != "GET") {
    return report_error(connection, MHD_HTTP_NOT_IMPLEMENTED, "501 Not Implemented");
  }
  
  if (mp3d_debug_httpd) {
    MHD_get_connection_values(connection, MHD_HEADER_KIND, dump_key, NULL);
    MHD_get_connection_values(connection, MHD_COOKIE_KIND, dump_key, NULL);
    MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, dump_key, NULL);
    std::cout << "*** " << method << " request for '" << url << "'" << std::endl;
  }
  
  const char* q = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "mp3d_q");
  
  const std::string request_url(url);
  if (request_url == "/") {
    std::string page_data;
    make_main_page(page_data, q);
    return send_string_response(connection, MHD_HTTP_OK, page_data);
  } else if (boost::starts_with(request_url, "/static/")) {
    StringStringMap::const_iterator it = static_file_map.find(request_url);
    if (it == static_file_map.end()) {
      return report_error(connection, MHD_HTTP_NOT_FOUND, "404 Not Found");
    }
    return send_string_response(connection, MHD_HTTP_OK, it->second);
  } else if (boost::starts_with(request_url, "/play/")) {
    const size_t id = strtoul(request_url.substr(6).c_str(), 0, 10); // FIXME: error checking.
    play_queue.clear();
    play_queue.push_back(all_mp3s[id]); // FIXME: lookup by id (don't assume id == index).
    return see_other(connection, "/");
  } else if (boost::starts_with(request_url, "/add/")) {
    const size_t id = strtoul(request_url.substr(5).c_str(), 0, 10); // FIXME: error checking.
    play_queue.push_back(all_mp3s[id]); // FIXME: lookup by id (don't assume id == index).
    return see_other(connection, "/");
  } else if (boost::starts_with(request_url, "/remove/")) {
    const size_t id = strtoul(request_url.substr(8).c_str(), 0, 10); // FIXME: error checking.
    play_queue.remove(id); // FIXME: is this set-like behavior the behavior we want?
    return see_other(connection, "/");
  } else {
    return report_error(connection, MHD_HTTP_NOT_FOUND, "404 Not Found");
  }
}
	BEGIN_CUNKNOWN
	END_CUNKNOWN

	CFontResolver()
	{
		m_ftLibraryLoaded = false;
		FT_Error error = FT_Init_FreeType(&m_ftLibrary);
		if (!error)
			m_ftLibraryLoaded = true;

		split_vector_type searchFolders; 
		boost::algorithm::split(searchFolders, DEFAULT_FONTPATH, boost::algorithm::is_any_of(";"), boost::algorithm::token_compress_on);

		for(split_vector_type::const_iterator itr = searchFolders.begin(); itr != searchFolders.end(); ++itr) {
			findFilesByExt(*itr, ".ttf", m_stemPath);
			findFilesByExt(*itr, ".ttc", m_stemPath);
		}

		split_vector_type defaultFonts; 
		boost::algorithm::split(defaultFonts, DEFAULT_FONT, boost::algorithm::is_any_of(";"), boost::algorithm::token_compress_on);

		for(split_vector_type::const_iterator itr = defaultFonts.begin(); itr != defaultFonts.end(); ++itr) 
		{
			StringStringMap::const_iterator found = m_stemPath.find(*itr);
			if (found != m_stemPath.end())
			{
				m_defaultPath = found->second;
				break;
			}
		}

		if (m_defaultPath.empty())
		{
#if defined WIN32
			m_defaultPath = "c:/windows/fonts/verdana.ttf";
#else
			m_defaultPath = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
#endif
		}
	}
Beispiel #8
0
void fillAndPrint(StringStringMap& coll)
{
  //fill insert elements in random order
  coll["Deutschland"] = "Germany";
  coll["deutsch"] = "German";
  coll["Haken"] = "snag";
  coll["arbeiten"] = "work";
  coll["Hund"] = "dog";
  coll["gehen"] = "go";
  coll["Unternehmen"] = "enterprise";
  coll["unternehmen"] = "undertake";
  coll["gehen"] = "walk";
  coll["Bestatter"] = "undertaker";
  //print elements

  StringStringMap::iterator pos;
  cout.setf(ios::left, ios::adjustfield);
  for (pos=coll.begin(); pos!=coll.end(); ++pos) {
    cout << setw(15) << pos->first.c_str() << " "
	 << pos->second << endl;
  }
  cout << endl;
}
Beispiel #9
0
void
herschel::xml::displayStringStringMap(Port<Octet>& port,
                                     zstring outerTagName,
                                     zstring tagName,
                                     zstring firstPairTagName,
                                     zstring secPairTagName,
                                     const StringStringMap& strMap)
{
  if (!strMap.empty())
    displayOpenTag(port, outerTagName);

  for (StringStringMap::const_iterator it = strMap.begin();
       it != strMap.end();
       it++)
  {
    displayOpenTag(port, tagName);
    displayTag(port, firstPairTagName, it->first);
    displayTag(port, secPairTagName, it->second);
    displayCloseTag(port, tagName);
  }

  if (!strMap.empty())
    displayCloseTag(port, outerTagName);
}
Beispiel #10
0
 void bridgeDiscoveryHandler(SsdpSearchPtr aSsdpSearch, ErrorPtr aError)
 {
   if (Error::isOK(aError)) {
     // check device for possibility of being a hue bridge
     if (aSsdpSearch->server.find("IpBridge")!=string::npos) {
       LOG(LOG_INFO, "hue bridge candidate device found at %s, server=%s, uuid=%s", aSsdpSearch->locationURL.c_str(), aSsdpSearch->server.c_str(), aSsdpSearch->uuid.c_str());
       // put into map
       bridgeCandiates[aSsdpSearch->uuid.c_str()] = aSsdpSearch->locationURL.c_str();
     }
   }
   else {
     FOCUSLOG("discovery ended, error = %s (usually: timeout)", aError->description().c_str());
     aSsdpSearch->stopSearch();
     // now process the results
     currentBridgeCandidate = bridgeCandiates.begin();
     processCurrentBridgeCandidate();
   }
 }
Beispiel #11
0
 void findNewBridge(const char *aUserName, const char *aDeviceType, MLMicroSeconds aAuthTimeWindow, HueComm::HueBridgeFindCB aFindHandler)
 {
   refind = false;
   callback = aFindHandler;
   userName = nonNullCStr(aUserName);
   deviceType = nonNullCStr(aDeviceType);
   authTimeWindow = aAuthTimeWindow;
   if (hueComm.fixedBaseURL.empty()) {
     // actually search for a bridge
     keepAlive = BridgeFinderPtr(this);
     bridgeDetector->startSearch(boost::bind(&BridgeFinder::bridgeDiscoveryHandler, this, _1, _2), NULL);
   }
   else {
     // we have a pre-known base URL for the hue API, use this without any find operation
     keepAlive = BridgeFinderPtr(this);
     // - just put it in as the only auth candidate
     authCandidates.clear();
     authCandidates[PSEUDO_UUID_FOR_FIXED_API] = hueComm.fixedBaseURL;
     startedAuth = MainLoop::now();
     attemptPairingWithCandidates();
   }
 };
Beispiel #12
0
 void Update(const ns6__ECLResult * c)
 {
     clib::recursive_mutex::scoped_lock proc(m_mutex);
     SAFE_ASSIGN2CSTRING(m_name, c->Name);
     SAFE_ASSIGN(m_sequence, c->Sequence);
     SAFE_ASSIGN2CSTRING(m_value, c->Value);
     SAFE_ASSIGN2CSTRING(m_link, c->Link);
     SAFE_ASSIGN(IsSupplied, c->IsSupplied);
     SAFE_ASSIGN(m_total, c->Total);
     SAFE_ASSIGN2CSTRING(m_fileName, c->FileName);
     if (c->ECLSchemas)
     {
         m_schemaMap.clear();
         for(std::size_t i = 0; i < c->ECLSchemas->ECLSchemaItem.size(); ++i)
         {
             if (c->ECLSchemas->ECLSchemaItem[i]->ColumnName && c->ECLSchemas->ECLSchemaItem[i]->ColumnType) 
             {
                 m_schemaMap[*c->ECLSchemas->ECLSchemaItem[i]->ColumnName] = *c->ECLSchemas->ECLSchemaItem[i]->ColumnType;
             }
         }
     }
 }
Beispiel #13
0
			void Clear()
			{
				nvs.clear();
			}
Beispiel #14
0
 void attemptPairingWithCandidates()
 {
   currentAuthCandidate = authCandidates.begin();
   processCurrentAuthCandidate();
 }
int CGraphItem::GetProperties(StringStringMap & results) const
{
    results = m_propStringString;
    return results.size();
}