예제 #1
0
파일: Exception.cpp 프로젝트: ryall/pikpik
// =============================================================================
xbool Xen::CException::HandleError(xstring sMessage, xstring sCondition, xstring sFunction, xstring sFile, xint iLine)
{
	xstring sExceptionMessage;

#if !XRETAIL
	sExceptionMessage = XFORMAT
	(
		"Failed Condition: %s" XENDL "Function: %s" XENDL "Line: %d" XENDL XENDL "%s" XENDL XENDL "Would you like to debug?", 
		sCondition.c_str(), sFunction.c_str(), iLine, sMessage.c_str()
	);
#else
	sExceptionMessage = sMessage;
#endif

XLOG(sExceptionMessage.c_str());

#if XWINDOWS
	#if !XRETAIL
		xint iDialogResult = MessageBox(NULL, sExceptionMessage.c_str(), "Application Error", MB_YESNO | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND | MB_DEFBUTTON1);

		if (iDialogResult == IDYES)
			return true;
	#endif
#endif
	
	throw CException(sExceptionMessage);
	return false;
}
예제 #2
0
void CCacheEntry::populate(const char* resource_url)
{
    // Can we use what we have?
    if (m_assertion && m_assertion->getNotOnOrAfter())
    {
        // This is awful, but the XMLDateTime class is truly horrible.
        time_t now=time(NULL);
#ifdef WIN32
        struct tm* ptime=gmtime(&now);
#else
	struct tm res;
	struct tm* ptime=gmtime_r(&now,&res);
#endif
	char timebuf[32];
	strftime(timebuf,32,"%Y-%m-%dT%H:%M:%SZ",ptime);
	auto_ptr<XMLCh> timeptr(XMLString::transcode(timebuf));
	XMLDateTime curDateTime(timeptr.get());
	int result=XMLDateTime::compareOrder(&curDateTime,m_assertion->getNotOnOrAfter());
	if (XMLDateTime::LESS_THAN)
	    return;

	delete m_response;
	delete[] m_serialized;
	m_assertion=NULL;
        m_response=NULL;
	m_serialized=NULL;
    }

    if (!m_binding)
        return;

    auto_ptr<XMLCh> resource(XMLString::transcode(resource_url));    
    static const XMLCh* policies[] = { shibboleth::Constants::POLICY_CLUBSHIB };
    static const saml::QName* respondWiths[] = { &g_respondWith };

    // Build a SAML Request and send it to the AA.
    SAMLSubject* subject=new SAMLSubject(m_handle.c_str(),m_originSite.c_str());
    SAMLAttributeQuery* q=new SAMLAttributeQuery(subject,resource.get());
    SAMLRequest* req=new SAMLRequest(q,respondWiths);
    SAMLBinding* pBinding=CCache::g_Cache->getBinding(m_binding->getBinding());
    m_response=pBinding->send(*m_binding,*req);
    delete req;

    // Store off the assertion for quick access. Memory mgmt is based on the response pointer.
    Iterator<SAMLAssertion*> i=m_response->getAssertions();
    if (i.hasNext())
        m_assertion=i.next();

    auto_ptr<char> h(XMLString::transcode(m_handle.c_str()));
    auto_ptr<char> d(XMLString::transcode(m_originSite.c_str()));
    std::fprintf(stderr,"CCacheEntry::populate() fetched and stored SAML response for %s@%s\n",
		 h.get(),d.get());
}
예제 #3
0
파일: text.cpp 프로젝트: GamingAtheist/ogui
int_vec calculate_text_breaks(const xstring& text)
{
  int_vec breaks;
  auto it = text.begin();
  bool last = false;
  for (int i = 0; it != text.end(); ++it, ++i)
  {
    if (*it == ' ')
    {
      if (last) breaks.push_back(i);
      last = false;
    }
    else last = true;
  }
  return breaks;
}
예제 #4
0
std::deque<xstring> split(const xstring& s, const xstring& delimitersRE)
{
	std::deque<xstring> rv;

	const xstring fixed = std::regex_replace(s, std::wregex(L"\r"), L"");

	std::wregex rePattern(delimitersRE);
	std::wsregex_token_iterator iter(fixed.begin(), fixed.end(), rePattern, -1);
	std::wsregex_token_iterator end;
	for (; iter != end; ++iter)
	{
		const xstring& item = *iter;
		if (!item.empty())
			rv.push_back(item);
	}
	return rv;
}
예제 #5
0
파일: text.cpp 프로젝트: GamingAtheist/ogui
void break_text_lines(font_ptr font, xstring text, int total_width, str_vec& lines)
{
  lines.clear();
  int_vec breaks = calculate_text_breaks(text);
  unsigned break_pos = 0;
  xstring cand = "";
  while (text.length() > 0 && break_pos<breaks.size())
  {
    xstring sub = text.substr(0, breaks[break_pos]);
    Rect bounds = font->get_bounds(sub);
    if (bounds.get_width() > total_width)
    {
      if (cand.empty()) return; // Not enough space for single word
      lines.push_back(cand);
      text = text.substr(breaks[break_pos - 1]);
      text.trim();
      breaks = calculate_text_breaks(text);
      break_pos = 0;
    }
    else
    {
      cand = text.substr(0, breaks[break_pos]);
      break_pos++;
    }
  }
  if (text.length() > 0) lines.push_back(text.trim());
}
예제 #6
0
/* Returns a specified field of the given tag. */
bool ID3V1_TAG::GetField(ID3V1_TAG_COMP type, xstring& result, int charset) const
{
  result.reset();
  char buffer[32];

  switch( type )
  { default:
      return false;

    case ID3V1_TITLE:
      safecopy(buffer, title, sizeof title);
      break;

    case ID3V1_ARTIST:
      safecopy(buffer, artist, sizeof artist);
      break;

    case ID3V1_ALBUM:
      safecopy(buffer, album, sizeof album);
      break;

    case ID3V1_YEAR:
      safecopy(buffer, year, sizeof year);
      break;

    // Since all non-filled fields must be padded with zeroed bytes
    // its a good assumption that all ID3v1 readers will stop reading
    // the field when they encounter a zeroed byte. If the second last
    // byte of a comment field is zeroed and the last one isn't we
    // have an extra byte to fill with information. As the comments
    // field is to short to write anything useful in the ID3v1.1 standard
    // declares that this field should be 28 characters, that the next
    // byte always should be zero and that the last byte before the
    // genre byte should contain which track on the CD this music
    // comes from.
    case ID3V1_COMMENT:
      if( empty || !track )
        safecopy(buffer, comment, 30);
      else
        safecopy(buffer, comment, sizeof comment);
      break;

    case ID3V1_TRACK:
      if( empty || !track )
        return false;
      result.sprintf("%02d", track);
      return true;

    case ID3V1_GENRE:
      if( genre <= GENRE_LARGEST )
        result = genres[genre];
        // We don't need to convert these 7 bit ASCII texts.
      else if ( genre != 0xFF )
        result.sprintf("#%u", genre);
      else
        return false;
      return true;
  }

  if (!*buffer)
    return false;
  ch_convert(charset, buffer, CH_CP_NONE, buffer, sizeof buffer, 0);
  result = buffer;
  return true;
}