Пример #1
0
int
main(int argc, char *argv[])
{
    int i;
    uint16_t wc;
    int len;
    uint8_t *cp;

#if 0
    i = 0xa9;
    cp = &tab[i][0];
    utf8enc(i, cp);
    printf("\n");
    i = 0x2260;
    cp = &tab[i][0];
    utf8enc(i, cp);
    printf("\n");
#endif

    exit(0);

    for (i = 0 ; i < 65536 ; i++) {
        cp = &tab[i][0];
        utf8enc(i, cp);
        wc = utf8dec(&tab[i][0], &len);
        if (wc != i) {
//            printf("0x%x (0x%x): %x\n", i, wc, len);
            printf("ERROR: %x != %x (%d)\n", wc, i, len);
            exit(1);
        }
    }

    exit(0);
}
Пример #2
0
bool GJContext::SignIn(LPCTSTR username,LPCTSTR password,CLoginFrame *loginFrame)
{
	StopRecv();
	this->m_pLoginFrame=loginFrame;
	bool bOk=true;
	JID *nSelf=new JID();
	if(!nSelf)
	{
		bOk=false;
	}else if(!nSelf->setServer(m_Server)||!nSelf->setUsername(utf8enc(username)))
	{
		bOk=false;
	}else { 
		if(m_pClient) 
			m_pClient->disconnect();  
		m_pClient=new Client(*nSelf,encryptPassword(utf8enc(password)),m_Port);  
		m_pVCardMgr=new VCardManager(m_pClient);
		if(!m_pClient)
			bOk=false;
		else
		{
			m_pClient->registerConnectionListener(this);
			m_pClient->registerIqHandler(this,0);
			m_pClient->registerMessageHandler(this);
			m_pClient->rosterManager()->registerRosterListener(this,false);
			bOk= m_pClient->connect(false);

		}
	}
	if(!bOk&&nSelf) 
		delete nSelf;
	else 
	{
		if(m_pSelf)
			delete m_pSelf;
		m_pSelf=nSelf; 
		StartRecv();
	}

	return bOk;
}
Пример #3
0
IRIRef *IRIRef::normalize() THROWS(BadAllocException, TraceableException) {
  if (this->normalized && !this->urified) {
    return this;
  }

  uint8_t *normed = NULL;
  DPtr<uint8_t> *normal = NULL;

  if (this->utf8str->standable()) {
    this->utf8str = this->utf8str->stand();
    normal = this->utf8str;
    normal->hold();
  } else {
    NEW(normal, MPtr<uint8_t>, this->utf8str->size());
  }
  normed = normal->dptr();

  // Percent encoding; decode if IUnreserved
  uint8_t bits = UINT8_C(0);
  uint8_t *begin = this->utf8str->dptr();
  uint8_t *end = begin + this->utf8str->size();
  uint8_t *marki = begin;
  uint8_t *markj = begin;
  uint8_t *markk = normed;
  for (; marki != end; marki = markj) {
    for (markj = marki; markj != end && *markj != to_ascii('%'); ++markj) {
      // loop does the work
    }
    size_t sz = markj - marki;
    memmove(markk, marki, sz * sizeof(uint8_t));
    markk += sz;
    if (markj == end) {
      break;
    }

    uint8_t enc[4] = { UINT8_C(0xFF), UINT8_C(0xFF),
                       UINT8_C(0xFF), UINT8_C(0xFF) };
    enc[0] = (((uint8_t) IRI_HEX_VALUE(markj[1])) << 4)
             | (uint8_t) IRI_HEX_VALUE(markj[2]);
    if (enc[0] <= UINT8_C(0x7F)) {
      if (IRIRef::isIUnreserved(enc[0])) {
        *markk = enc[0];
        ++markk;
      } else {
        markk[0] = markj[0];
        markk[1] = to_upper(markj[1]);
        markk[2] = to_upper(markj[2]);
        markk += 3;
      }
      markj += 3;
      continue;
    }

    uint8_t *markl = markj + 3;
    int i = 1;
    uint8_t bits;
    for (bits = enc[0] << 1; markl != end && *markl == to_ascii('%') &&
                             bits > UINT8_C(0x7F) && i < 4; bits <<= 1) {
      enc[i] = (((uint8_t) IRI_HEX_VALUE(markl[1])) << 4)
               | (uint8_t) IRI_HEX_VALUE(markl[2]);
      markl += 3;
      ++i;
    }
    try {
      const uint8_t *endenc;
      uint32_t codepoint = utf8char(enc, &endenc);
      if (IRIRef::isIUnreserved(codepoint)) {
        i = endenc - enc; // should already be equal, but just in case
        memmove(markk, enc, i * sizeof(uint8_t));
        markk += i;
        markj = markl;
        this->urified = false;
      } else {
        for (; markj != markl; markj += 3) {
          markk[0] = markj[0];
          markk[1] = to_upper(markj[1]);
          markk[2] = to_upper(markj[2]);
          markk += 3;
        }
      }
    } catch (InvalidEncodingException &e) {
      markk[0] = markj[0];
      markk[1] = to_upper(markj[1]);
      markk[2] = to_upper(markj[2]);
      markk += 3;
      markj += 3;
    }
  }
  if (markk != end) {
    DPtr<uint8_t> *temp = normal->sub(0, markk - normed);
    normal->drop();
    normal = temp;
  }

  if (this->normalized) {
    this->utf8str->drop();
    this->utf8str = normal;
    return this;
  }

  // Character normalization; NFC
  DPtr<uint32_t> *codepoints = utf8dec(normal);
  normal->drop();
  DPtr<uint32_t> *codepoints2 = nfc_opt(codepoints);
  codepoints->drop();
  normal = utf8enc(codepoints2);
  codepoints2->drop();
  this->utf8str->drop();
  this->utf8str = normal;

  // Path normalization
  this->resolve(NULL);

  // Case normalization; scheme and host
  DPtr<uint8_t> *part = this->getPart(SCHEME);
  if (part != NULL) {
    begin = part->dptr();
    end = begin + part->size();
    for (; begin != end; ++begin) {
      *begin = to_lower(*begin);
    }
    part->drop();
  }
  part = this->getPart(HOST);
  if (part != NULL) {
    begin = part->dptr();
    end = begin + part->size();
    for (; begin != end; ++begin) {
      *begin = to_lower(*begin);
    }
    part->drop();
  }

  this->normalized = true;
  return this;
}