CATableViewCell* ExchangeViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CCLog("row = %d , section = %d", row, section); CADipSize _size = cellSize; CATableViewCell* p_Cell = p_TableView->dequeueReusableCellWithIdentifier("2155"); if (p_Cell == NULL ) { p_Cell = CATableViewCell::create("2155"); p_Cell->setAllowsSelected(false); CAView* itemImage = CAView::createWithFrame(CADipRect(0, 0, _size.width, _size.height)); itemImage->setColor(ccc4(244, 243, 243, 255)); itemImage->setTag(99); p_Cell->addSubview(itemImage); CADipSize itemSize = itemImage->getBounds().size; CALabel* itemText = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/3, itemSize.width,40)); itemText->setTag(100); itemText->setFontSize(_px(35)); itemText->setTextAlignment(CATextAlignmentCenter); itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText); CALabel* itemText2 = CALabel::createWithCenter(CADipRect(itemSize.width/2, itemSize.height/5*4, itemSize.width,40)); itemText2->setTag(101); itemText2->setFontSize(_px(25)); itemText2->setTextAlignment(CATextAlignmentCenter); itemText2->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText2); CAScale9ImageView* iv = CAScale9ImageView::createWithCenter(CADipRect(itemSize.width-50,itemSize.height/2,50,50)); iv->setImage(CAImage::create("source_material/cell_btn_right.png")); iv->setTag(101); p_Cell->addSubview(iv); CAImageView* icon = CAImageView::createWithCenter(CADipRect(50,itemSize.height/2,64,64)); icon->setTag(101); icon->setScale(0.6f); icon->setImage(CAImage::create("source_material/btn_right_blue.png")); p_Cell->addSubview(icon); } CALabel * label = (CALabel*)p_Cell->getSubviewByTag(100); label->setText( unicode_to_utf8(exChangeMenuTag[row]) ); label->setColor(CAColor_black); CALabel* label2 = (CALabel*)p_Cell->getSubviewByTag(101); label2->setText(unicode_to_utf8(exChangeMenuTag2[row])); label2->setColor(CAColor_gray); return p_Cell; }
bool stupid_get_current_work_directory(std::string & dirname) { #ifdef _MSC_VER wchar_t temp[512] = { 0 }; if (nullptr == _wgetcwd(temp, sizeof(temp) / sizeof(temp[0]))) { dirname.clear(); return(false); } else { dirname = unicode_to_utf8(std::wstring(temp)) + g_directory_separator; stupid_directory_format(dirname); return(true); } #else char temp[512] = { 0 }; if (nullptr == getcwd(temp, sizeof(temp) / sizeof(temp[0]))) { dirname.clear(); return(false); } else { dirname = ansi_to_utf8(std::string(temp)) + g_directory_separator; stupid_directory_format(dirname); return(true); } #endif // _MSC_VER }
CATableViewCell* MenuViewController::tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row) { DSize _size = cellSize; CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); cell->setBackgroundView(NULL); CALabel* test = CALabel::createWithCenter(DRect(_size.width/2+30, _size.height/2, _size.width, _size.height)); test->setTextAlignment(CATextAlignmentLeft); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(_px(32)); test->setColor(CAColor_white); test->setTag(100); cell->addSubview(test); CAImageView* arrow = CAImageView::createWithCenter(DRect(_size.width-64,_size.height/2,64,64)); arrow->setTag(101); cell->addSubview(arrow); } CALabel* test = (CALabel*)cell->getSubviewByTag(100); test->setText(unicode_to_utf8(menuList[row]));// menuList[row]); CAImageView* arrow = (CAImageView*)cell->getSubviewByTag(101); arrow->setImage(CAImage::create("source_material/cell_btn_right.png")); return cell; }
string ustring::toUTF8() { WCHAR* unicodedata = toUnicode(); string retval = unicode_to_utf8(unicodedata, m_vData.size()*2); Game_SAFE_DELETE_ARRAY(unicodedata); return retval; }
CATableViewCell* FSNewsAboutController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CADipSize _size = cellSize; FSNewsAboutTableCell* cell = dynamic_cast<FSNewsAboutTableCell*>(table->dequeueReusableCellWithIdentifier("NewsAboutCell")); if (cell == NULL) { cell = FSNewsAboutTableCell::create("NewsAboutCell", CADipRect(0, 0, _size.width, _size.height)); cell->initWithCell(); } CALabel* cellText = (CALabel*)cell->getSubviewByTag(100); // CASwitch* cellBtn = (CASwitch*)cell->getSubviewByTag(103); // cellBtn->setVisible(false); // switch (section) { // case 0: // cellText->setText(unicode_to_utf8(aboutMenuTag[row])); // break; // case 1: // cellText->setText(unicode_to_utf8(aboutMenuTag[row + 2])); // if (row==2||row==3||row==4) { // cellBtn->setVisible(true); // }; // break; // case 2: // cellText->setText(unicode_to_utf8(aboutMenuTag[row + 8])); // break; // } cellText->setText(unicode_to_utf8(aboutMenuTag[row])); return cell; }
status_t volume_name(struct exfat_entry* entry, char* _name) { if (entry == NULL || _name == NULL) return B_BAD_VALUE; if (entry->type == EXFAT_ENTRY_TYPE_NOT_IN_USE) { const char* untitled = "Untitled"; size_t length = strlen(untitled); strncpy(_name, untitled, length); if (strlen(_name) < length) return B_NAME_TOO_LONG; } else if (entry->type == EXFAT_ENTRY_TYPE_LABEL) { // UCS-2 can encode codepoints in the range U+0000 to U+FFFF // UTF-8 needs at most 3 bytes to encode values in this range size_t utf8NameLength = entry->label.length * 3; memset(_name, 0, utf8NameLength + 1); // zero out the character array unicode_to_utf8((const uchar*)entry->label.name, entry->label.length * 2, (uint8*)_name, &utf8NameLength); if (strlen(_name) < utf8NameLength) return B_NAME_TOO_LONG; } else return B_NAME_NOT_FOUND; return B_OK; }
bool clFileAssociationsWin::Command( int id, int subId, Win* win, void* data ) { if ( id == CMD_OK ) { EndModal( CMD_OK ); return true; } if ( id == CMD_MINUS ) { const clNCFileAssociation* p = m_ListWin.GetCurrentData(); if ( !p ) { return true; } if ( NCMessageBox( ( NCDialogParent* )Parent(), _LT( "Delete item" ), carray_cat<char>( _LT( "Delete '" ), unicode_to_utf8( p->GetMask().data() ).data() , "' ?" ).data(), false, bListOkCancel ) == CMD_OK ) { m_ListWin.Del(); m_Saved = false; } return true; } if ( id == CMD_EDIT || ( id == CMD_ITEM_CLICK && win == &m_ListWin ) ) { const clNCFileAssociation* ValueToEdit = m_ListWin.GetCurrentData(); if ( !ValueToEdit ) { return true; } clEditFileAssociationsWin Dialog( ( NCDialogParent* )Parent(), ValueToEdit ); Dialog.SetEnterCmd( 0 ); if ( Dialog.DoModal( ) == CMD_OK ) { m_ListWin.Rename( Dialog.GetResult( ) ); m_Saved = false; } return true; } if ( id == CMD_PLUS ) { clEditFileAssociationsWin Dialog( ( NCDialogParent* )Parent(), NULL ); Dialog.SetEnterCmd( 0 ); if ( Dialog.DoModal( ) == CMD_OK ) { m_ListWin.Ins( Dialog.GetResult( ) ); m_Saved = false; } return true; } return NCDialog::Command( id, subId, win, data ); }
void VSearcher::Set( unicode_t* uStr, bool sens, charset_struct* charset ) //throw { sBigList.clear(); sList.clear(); bytes.clear(); _cs = charset; mode = 0; int maxSymLen = 0; bool one = true; int i; for ( ; *uStr; uStr++ ) { SBigNode node; if ( !node.Set( *uStr, sens, charset ) ) { unicode_t x[2] = { *uStr, 0}; throw_msg( "symbol '%s' not exist in charset '%s'", unicode_to_utf8( x ).data(), charset->name ); } int n = node.MaxLen(); if ( maxSymLen < n ) { maxSymLen = n; } if ( node.b[0] ) { one = false; } sBigList.append( node ); } sBigList.append( SBigNode() ); mode = 1; if ( one ) { for ( i = 0; i < sBigList.count(); i++ ) { for ( char* s = sBigList[i].a; *s; s++ ) { bytes.append( *s ); } } mode = 3; } else if ( maxSymLen == 1 ) { for ( i = 0; i < sBigList.count(); i++ ) { sList.append( SNode( sBigList[i].a[0], sBigList[i].b[0] ) ); } mode = 2; } }
/* * tioputc: */ int tioputc(int c) { char utf8[6]; int bytes; bytes = unicode_to_utf8(c, utf8); fwrite(utf8, 1, bytes, stdout); return 0; }
status_t DirectoryIterator::_GetNext(uchar* name, size_t* _nameLength, ino_t* _id, EntryVisitor* visitor) { size_t nameMax = *_nameLength; size_t nameIndex = 0; status_t status; int32 chunkCount = 1; while ((status = _NextEntry()) == B_OK) { TRACE("DirectoryIterator::_GetNext() %" B_PRIu32 "/%p, type 0x%x, " "offset %" B_PRId64 "\n", fInode->Cluster(), fCurrent, fCurrent->type, fOffset); if (fCurrent->type == EXFAT_ENTRY_TYPE_FILE) { chunkCount = fCurrent->file.chunkCount; if (_id != NULL) { *_id = fInode->GetVolume()->GetIno(fCluster, fOffset - 1, fInode->ID()); } if (visitor != NULL) visitor->VisitFile(fCurrent); TRACE("DirectoryIterator::_GetNext() File chunkCount %" B_PRId32 "\n", chunkCount); } else if (fCurrent->type == EXFAT_ENTRY_TYPE_FILEINFO) { chunkCount--; TRACE("DirectoryIterator::_GetNext() Filename length %d\n", fCurrent->file_info.name_length); *_nameLength = fCurrent->file_info.name_length * 2; if (visitor != NULL) visitor->VisitFileInfo(fCurrent); } else if (fCurrent->type == EXFAT_ENTRY_TYPE_FILENAME) { TRACE("DirectoryIterator::_GetNext() Filename\n"); memcpy((uint8*)name + nameIndex, fCurrent->file_name.name, sizeof(fCurrent->file_name.name)); nameIndex += sizeof(fCurrent->file_name.name); name[nameIndex] = '\0'; chunkCount--; if (visitor != NULL) visitor->VisitFilename(fCurrent); } if (chunkCount == 0 || nameIndex >= nameMax) break; } if (status == B_OK) { //*_nameLength = nameIndex; #ifdef TRACE_EXFAT char utfName[EXFAT_FILENAME_MAX_LENGTH]; size_t utfLen = EXFAT_FILENAME_MAX_LENGTH; unicode_to_utf8(name, nameIndex, (uint8*)utfName, &utfLen); TRACE("DirectoryIterator::_GetNext() Found %s %ld\n", utfName, *_nameLength); #endif } return status; }
void PathList::GetStrings(std::vector<std::string>& list) const { for (size_t i = 0; i < m_list.size(); i++) { if (m_list[i].conf.ptr() && m_list[i].name.data()) { m_list[i].conf->Set("name", unicode_to_utf8(m_list[i].name.data()).data()); list.push_back(std::string(m_list[i].conf->GetConfig().data())); } } }
bool LabelVisitor::VisitLabel(struct exfat_entry* entry) { TRACE("LabelVisitor::VisitLabel()\n"); char utfName[30]; size_t utfLength = 30; unicode_to_utf8((const uchar*)entry->name_label.name, entry->name_label.length * 2, (uint8*)utfName, &utfLength); fVolume->SetName(utfName); return true; }
bool GetSmbLogon( NCDialogParent* parent, FSSmbParam& params, bool enterServer ) { SmbLogonDialog dlg( parent, params, enterServer ); if ( dlg.DoModal() == CMD_OK ) { if ( enterServer ) { Copy( params.server, unicode_to_utf8( dlg.serverEdit.GetText().data() ).data() , sizeof( params.server ) ); } Copy( params.domain, unicode_to_utf8( dlg.domainEdit.GetText().data() ).data() , sizeof( params.domain ) ); Copy( params.user, unicode_to_utf8( dlg.userEdit.GetText().data() ).data() , sizeof( params.user ) ); Copy( params.pass, unicode_to_utf8( dlg.passwordEdit.GetText().data() ).data() , sizeof( params.pass ) ); params.isSet = true; return true; } return false; }
CATableViewCell* huafeiPreViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CCLog("row = %d , section = %d", row, section); CADipSize _size = cellSize; CATableViewCell* p_Cell = p_TableView->dequeueReusableCellWithIdentifier("2155"); if (p_Cell == NULL) { p_Cell = CATableViewCell::create("2155"); p_Cell->setAllowsSelected(false); CALabel* itemText = CALabel::createWithCenter(CADipRect(_size.width/2, _size.height/2, _size.width-200,80)); itemText->setTag(100); itemText->setFontSize(_px(30)); itemText->setTextAlignment(CATextAlignmentCenter); itemText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText); CALabel* itemText2 = CALabel::createWithCenter(CADipRect(_size.width - 80, _size.height/2, _size.width-200,80)); itemText2->setTag(101); itemText2->setFontSize(_px(25)); itemText2->setTextAlignment(CATextAlignmentCenter); itemText2->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); p_Cell->addSubview(itemText2); } CALabel * label = (CALabel*)p_Cell->getSubviewByTag(100); label->setText(unicode_to_utf8(huafeiMenu[row])); label->setColor(CAColor_black); CALabel * label1 = (CALabel*)p_Cell->getSubviewByTag(101); label1->setText(unicode_to_utf8(huafeiMenu[row+4])); label1->setColor(CAColor_red); return p_Cell; }
void unicode_test(void) { char pc[256] = {0}; wchar_t pw[256] = {0}; char cc[] = "1中a华人民cc共和xxxx国"; wchar_t wc[] = L"1中a华人民cc共和xxxx国"; unicode_to_gb18030(wc, 0, pc, sizeof(pc)); assert(0 == strcmp(pc, cc)); unicode_from_gb18030(pc, 0, pw, sizeof(pw)); assert(0 == wcscmp(pw, wc)); memset(pc, 0, sizeof(pc)); memset(pw, 0, sizeof(pw)); unicode_to_utf8(wc, 0, pc, sizeof(pc)); unicode_from_utf8(pc, 0, pw, sizeof(pw)); assert(0 == wcscmp(pw, wc)); }
bool DoEditConfigDialog(NCDialogParent *parent) { EditOptDialog dlg(parent); if (dlg.DoModal() == CMD_OK) { wcmConfig.editSavePos = dlg.saveFilePosButton.IsSet(); wcmConfig.editAutoIdent = dlg.autoIdentButton.IsSet(); wcmConfig.editShl = dlg.shlButton.IsSet(); int tabSize = atoi(unicode_to_utf8(dlg.tabEdit.GetText().ptr()).ptr()); if (tabSize>0 && tabSize<=64) wcmConfig.editTabSize = tabSize; return true; } return false; }
/* ** Truncate word to chars from text[i1..i2] */ void ocrword_truncate(OCRWORD *word,int i1,int i2) { int i,n; int *u; double w0,scale; static char *funcname="ocrword_truncate"; n=word->n; if (i1<0) i1=0; if (i2>n-1) i2=n-1; if (i2<i1) { word->n=0; word->w0=0.; word->w=0; return; } w0=word->w0; /* Fix text */ willus_mem_alloc_warn((void **)&u,n*sizeof(int),funcname,10); utf8_to_unicode(u,word->text,n); unicode_to_utf8(word->text,&u[i1],i2-i1+1); willus_mem_free((double **)&u,funcname); /* Fix length */ word->n=i2-i1+1; if (word->cpos==NULL) return; /* Fix width */ word->w0 = word->cpos[i2]-(i1==0?0.:word->cpos[i1-1]); scale = word->w/w0; word->w = (int)(scale*word->w0+.5); /* Fix left position and subsequent positions */ if (i1>0) { double x0; x0=word->cpos[i1-1]; word->x0 += x0; word->c += (int)(x0*scale+.5); for (i=i1;i<=i2;i++) word->cpos[i-i1]=word->cpos[i]-x0; } }
bool GetSftpLogon( NCDialogParent* parent, FSSftpParam& params ) { SftpLogonDialog dlg( parent, params ); if ( dlg.DoModal() == CMD_OK ) { params.server = dlg.serverEdit.GetText().data(); params.user = dlg.userEdit.GetText().data(); // params.pass = dlg.passwordEdit.GetText().ptr(); params.port = atoi( unicode_to_utf8( dlg.portEdit.GetText().data() ).data() ); params.isSet = true; params.charset = dlg.charset; return true; } return false; }
status_t DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id, EntryVisitor* visitor) { if (fCluster == EXFAT_CLUSTER_END) return B_ENTRY_NOT_FOUND; if (fOffset == -2) { if (*_nameLength < 3) return B_BUFFER_OVERFLOW; *_nameLength = 2; strlcpy(name, "..", *_nameLength + 1); if (fInode->ID() == 1) *_id = fInode->ID(); else *_id = fInode->Parent(); fOffset = -1; TRACE("DirectoryIterator::GetNext() found ..\n"); return B_OK; } else if (fOffset == -1) { if (*_nameLength < 2) return B_BUFFER_OVERFLOW; *_nameLength = 1; strlcpy(name, ".", *_nameLength + 1); *_id = fInode->ID(); fOffset = 0; TRACE("DirectoryIterator::GetNext() found .\n"); return B_OK; } uchar unicodeName[EXFAT_FILENAME_MAX_LENGTH + 1]; size_t nameLength = EXFAT_FILENAME_MAX_LENGTH; status_t status = _GetNext(unicodeName, &nameLength, _id, visitor); if (status == B_OK && name != NULL) { status = unicode_to_utf8(unicodeName, nameLength, (uint8 *)name, _nameLength); TRACE("DirectoryIterator::GetNext() %" B_PRIu32 " %s, %" B_PRIdINO "\n", fInode->Cluster(), name, *_id); } return status; }
status_t DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id) { if (strcmp(name, ".") == 0) { *_id = fInode->ID(); return B_OK; } else if (strcmp(name, "..") == 0) { if (fInode->ID() == 1) *_id = fInode->ID(); else *_id = fInode->Parent(); return B_OK; } Rewind(); fOffset = 0; uchar currentName[EXFAT_FILENAME_MAX_LENGTH + 1]; size_t currentLength = EXFAT_FILENAME_MAX_LENGTH; while (_GetNext((uchar*)currentName, ¤tLength, _id) == B_OK) { char utfName[EXFAT_FILENAME_MAX_LENGTH]; size_t utfLength = EXFAT_FILENAME_MAX_LENGTH; unicode_to_utf8(currentName, currentLength, (uint8*)utfName, &utfLength); if (nameLength == utfLength && strncmp(utfName, name, nameLength) == 0) { TRACE("DirectoryIterator::Lookup() found ID %" B_PRIdINO "\n", *_id); return B_OK; } currentLength = EXFAT_FILENAME_MAX_LENGTH; } TRACE("DirectoryIterator::Lookup() not found %s\n", name); return B_ENTRY_NOT_FOUND; }
bool RootWindow::init() { if (!CAWindow::init()) { return false; } CAApplication::getApplication()->setNotificationView(CAView::createWithFrame(this->getBounds(), CAColor_green)); CAVector<CAViewController*> controllerVec; m_home = new MainViewController(); if (m_home) { m_home->setTabBarItem(CATabBarItem::create(unicode_to_utf8(mainBar[0]), CAImage::create("main/bar_0.png"),CAImage::create("main/bar_pre_0.png"))); m_home->init(); m_home->autorelease(); controllerVec.pushBack(m_home); } m_session = new SessionsViewController(); if (m_session) { m_session->init(); m_session->autorelease(); m_session->setTabBarItem(CATabBarItem::create(unicode_to_utf8(mainBar[1]), CAImage::create("main/bar_1.png"),CAImage::create("main/bar_pre_1.png"))); controllerVec.pushBack(m_session); } m_my = new MyStatusViewController(); if (m_my) { m_my->setTabBarItem(CATabBarItem::create(unicode_to_utf8(mainBar[2]), CAImage::create("main/bar_2.png"),CAImage::create("main/bar_pre_2.png"))); m_my->init(); m_my->autorelease(); controllerVec.pushBack(m_my); } CATabBarController* tabBarController = new CATabBarController(); tabBarController->initWithViewControllers(controllerVec); tabBarController->setTabBarSelectedBackgroundColor(CAColor_clear); tabBarController->setTabBarTitleColorForSelected(CAColor_white); tabBarController->setTabBarBackgroundImage(CAImage::create("common/sky_bg.png")); /* CANavigationBarItem* temp_nav = CANavigationBarItem::create(""); temp_nav->setNagigationBarHidden(true); tabBarController->setScrollEnabled(false); tabBarController->setNavigationBarItem(temp_nav); tabBarController->setTabBarTitleColorForSelected(CAColor_white); tabBarController->autorelease(); */ m_pRootNavigationController = new CANavigationController(); m_pRootNavigationController->initWithRootViewController(tabBarController); m_pRootNavigationController->setNavigationBarBackgroundImage(CAImage::create("common/sky_bg.png")); m_pRootNavigationController->setNavigationBarHidden(true, false); m_pRootNavigationController->setScrollEnabled(false); FUser user = FUserManager::sharedFUserManager()->onLineUser(); if (user.loginname.length() == 0) { LoginViewController* _viewController = new LoginViewController(); _viewController->init(); this->setRootViewController(_viewController); _viewController->release(); } else { FDataManager::getInstance()->setUserId(user.uid); this->setRootViewController(m_pRootNavigationController); } CAApplication::getApplication()->setNotificationView(NULL); return true; }
int dec_string(Decoder* d, ERL_NIF_TERM* value) { int has_escape = 0; int num_escapes = 0; int st; int ulen; int ui; int hi; int lo; char* chrbuf; int chrpos; if(d->p[d->i] != '\"') { return 0; } d->i++; st = d->i; while(d->i < d->len) { if(d->u[d->i] < 0x20) { return 0; } else if(d->p[d->i] == '\"') { d->i++; goto parse; } else if(d->p[d->i] == '\\') { if(d->i+1 >= d->len) { return 0; } has_escape = 1; num_escapes += 1; d->i++; switch(d->p[d->i]) { case '\"': case '\\': case '/': case 'b': case 'f': case 'n': case 'r': case 't': d->i++; break; case 'u': hi = 0; lo = 0; d->i++; if(d->i + 4 >= d->len) { return 0; } hi = int_from_hex(&(d->u[d->i])); if(hi < 0) { return 0; } d->i += 4; if(hi >= 0xD800 && hi < 0xDC00) { if(d->i + 6 >= d->len) { return 0; } if(d->p[d->i++] != '\\') { return 0; } else if(d->p[d->i++] != 'u') { return 0; } lo = int_from_hex(&(d->u[d->i])); if(lo < 0) { return 0; } hi = unicode_from_pair(hi, lo); if(hi < 0) { return 0; } } hi = utf8_len(hi); if(hi < 0) { return 0; } if(lo == 0) { num_escapes += 5 - hi; } else { num_escapes += 11 - hi; } break; default: return 0; } } else if(d->u[d->i] < 0x80) { d->i++; } else { ulen = utf8_validate(&(d->u[d->i]), d->len - d->i); if(ulen < 0) { return 0; } d->i += ulen; } } // The goto above ensures that we only // hit this when a string is not terminated // correctly. return 0; parse: if(!has_escape) { *value = enif_make_sub_binary(d->env, d->arg, st, (d->i - st - 1)); return 1; } hi = 0; lo = 0; ulen = (d->i - 1) - st - num_escapes; chrbuf = (char*) enif_make_new_binary(d->env, ulen, value); chrpos = 0; ui = st; while(ui < d->i - 1) { if(d->p[ui] != '\\') { chrbuf[chrpos++] = d->p[ui++]; continue; } ui++; switch(d->p[ui]) { case '\"': case '\\': case '/': chrbuf[chrpos++] = d->p[ui]; ui++; break; case 'b': chrbuf[chrpos++] = '\b'; ui++; break; case 'f': chrbuf[chrpos++] = '\f'; ui++; break; case 'n': chrbuf[chrpos++] = '\n'; ui++; break; case 'r': chrbuf[chrpos++] = '\r'; ui++; break; case 't': chrbuf[chrpos++] = '\t'; ui++; break; case 'u': ui++; hi = int_from_hex(&(d->u[ui])); if(hi < 0) { return 0; } if(hi >= 0xD800 && hi < 0xDC00) { lo = int_from_hex(&(d->u[ui+6])); if(lo < 0) { return 0; } hi = unicode_from_pair(hi, lo); ui += 10; } else { ui += 4; } hi = unicode_to_utf8(hi, (unsigned char*) chrbuf+chrpos); if(hi < 0) { return 0; } chrpos += hi; break; default: return 0; } } return 1; }
status_t InitNode(iso9660_volume* volume, iso9660_inode* node, char* buffer, size_t* _bytesRead, bool relocated) { uint8 recordLength = *(uint8*)buffer++; size_t nameLength; TRACE(("InitNode - ENTER, bufstart is %p, record length is %d bytes\n", buffer, recordLength)); if (_bytesRead != NULL) *_bytesRead = recordLength; if (recordLength == 0) return B_ENTRY_NOT_FOUND; char* end = buffer + recordLength; if (!relocated) { node->cache = NULL; node->name = NULL; node->attr.slName = NULL; memset(node->attr.stat, 0, sizeof(node->attr.stat)); } else free(node->attr.slName); node->extAttrRecLen = *(uint8*)buffer++; TRACE(("InitNode - ext attr length is %d\n", (int)node->extAttrRecLen)); node->startLBN[LSB_DATA] = *(uint32*)buffer; buffer += 4; node->startLBN[MSB_DATA] = *(uint32*)buffer; buffer += 4; TRACE(("InitNode - data start LBN is %d\n", (int)node->startLBN[FS_DATA_FORMAT])); node->dataLen[LSB_DATA] = *(uint32*)buffer; buffer += 4; node->dataLen[MSB_DATA] = *(uint32*)buffer; buffer += 4; TRACE(("InitNode - data length is %d\n", (int)node->dataLen[FS_DATA_FORMAT])); init_node_date(&node->recordDate, buffer); buffer += 7; node->flags = *(uint8*)buffer; buffer++; TRACE(("InitNode - flags are %d\n", node->flags)); node->fileUnitSize = *(uint8*)buffer; buffer++; TRACE(("InitNode - fileUnitSize is %d\n", node->fileUnitSize)); node->interleaveGapSize = *(uint8*)buffer; buffer++; TRACE(("InitNode - interleave gap size = %d\n", node->interleaveGapSize)); node->volSeqNum = *(uint32*)buffer; buffer += 4; TRACE(("InitNode - volume seq num is %d\n", (int)node->volSeqNum)); nameLength = *(uint8*)buffer; buffer++; // for relocated directories we take the name from the placeholder entry if (!relocated) { node->name_length = nameLength; TRACE(("InitNode - file id length is %u\n", node->name_length)); } // Set defaults, in case there is no RockRidge stuff. node->attr.stat[FS_DATA_FORMAT].st_mode |= (node->flags & ISO_IS_DIR) != 0 ? S_IFDIR | S_IXUSR | S_IRUSR | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH : S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; if (node->name_length == 0) { TRACE(("InitNode - File ID String is 0 length\n")); return B_ENTRY_NOT_FOUND; } if (!relocated) { // JOLIET extension: // on joliet discs, buffer[0] can be 0 for Unicoded filenames, // so I've added a check here to test explicitely for // directories (which have length 1) // Take care of "." and "..", the first two dirents are // these in iso. if (node->name_length == 1 && buffer[0] == 0) { node->name = strdup("."); node->name_length = 1; } else if (node->name_length == 1 && buffer[0] == 1) { node->name = strdup(".."); node->name_length = 2; } else if (volume->joliet_level > 0) { // JOLIET extension: convert Unicode16 string to UTF8 // Assume that the unicode->utf8 conversion produces 4 byte // utf8 characters, and allocate that much space node->name = (char*)malloc(node->name_length * 2 + 1); if (node->name == NULL) return B_NO_MEMORY; int32 sourceLength = node->name_length; int32 destLength = node->name_length * 2; status_t status = unicode_to_utf8(buffer, &sourceLength, node->name, &destLength); if (status < B_OK) { dprintf("iso9660: error converting unicode->utf8\n"); return status; } node->name[destLength] = '\0'; node->name_length = destLength; sanitize_iso_name(node, false); } else { node->name = (char*)malloc(node->name_length + 1); if (node->name == NULL) return B_NO_MEMORY; // convert all characters to lower case for (uint32 i = 0; i < node->name_length; i++) node->name[i] = tolower(buffer[i]); node->name[node->name_length] = '\0'; sanitize_iso_name(node, true); } if (node->name == NULL) { TRACE(("InitNode - unable to allocate memory!\n")); return B_NO_MEMORY; } } buffer += nameLength; if (nameLength % 2 == 0) buffer++; TRACE(("DirRec ID String is: %s\n", node->name)); return parse_rock_ridge(volume, node, buffer, end, relocated); }
bool Directory::read() { if (!is_open()) { return(false); } #ifdef _MSC_VER while (!m_eof) { const std::wstring file_name(m_file.cFileName); const DWORD file_type = m_file.dwFileAttributes; m_eof = !FindNextFileW(m_dir, &m_file); if (L"." == file_name || L".." == file_name) { continue; } if (FILE_ATTRIBUTE_DIRECTORY == (FILE_ATTRIBUTE_DIRECTORY & file_type)) { m_current_sub_path_short_name = unicode_to_utf8(file_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name + g_directory_separator; m_current_sub_path_is_directory = true; } else { m_current_sub_path_short_name = unicode_to_utf8(file_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name; m_current_sub_path_is_directory = false; } return(true); } #else while (nullptr != m_file) { /* * do not do like this: * struct dirent * file = m_file; * m_file = readdir(m_dir); * operate_function(file); * the behavior is undefined, the result is not expected */ const std::string d_name(m_file->d_name); #if 0 const size_t d_type = m_file->d_type; #endif // 0 m_file = readdir(m_dir); if ("." == d_name || ".." == d_name) { continue; } #if 0 /* * d_type: not supported by all filesystem */ if (DT_DIR == (DT_DIR & d_type)) { m_current_sub_path_short_name = ansi_to_utf8(d_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name + g_directory_separator; m_current_sub_path_is_directory = true; return(true); } else if (DT_REG == (DT_REG & d_type)) { m_current_sub_path_short_name = ansi_to_utf8(d_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name; m_current_sub_path_is_directory = false; return(true); } #else stupid_stat_t stat_buf = { 0x00 }; const std::string file_name(utf8_to_ansi(m_dir_name) + d_name); if (0 != stupid_stat(file_name.c_str(), &stat_buf)) { continue; } if (S_IFDIR == (S_IFDIR & stat_buf.st_mode)) { m_current_sub_path_short_name = ansi_to_utf8(d_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name + g_directory_separator; m_current_sub_path_is_directory = true; return(true); } else if (S_IFREG == (S_IFREG & stat_buf.st_mode)) { m_current_sub_path_short_name = ansi_to_utf8(d_name); m_current_sub_path_name = m_dir_name + m_current_sub_path_short_name; m_current_sub_path_is_directory = false; return(true); } #endif // 0 } #endif // _MSC_VER m_current_sub_path_short_name.clear(); m_current_sub_path_name.clear(); m_current_sub_path_is_directory = false; return(false); }
//! Scans dir for the next entry, using the state stored in a struct diri. static status_t _next_dirent_(struct diri *iter, struct _dirent_info_ *oinfo, char *filename, int len) { uint8 *buffer; uint8 hash = 0; uchar uni[1024]; uint16 *puni; uint32 i; // lfn state uint32 start_index = 0xffff, filename_len = 0; uint32 lfn_count = 0; if (iter->current_block == NULL) return ENOENT; if (len < 15) { DPRINTF(0, ("_next_dirent_: len too short (%x)\n", len)); return ENOMEM; } buffer = iter->current_block + ((iter->current_index) % (iter->csi.vol->bytes_per_sector / 0x20)) * 0x20; for (; buffer != NULL; buffer = diri_next_entry(iter)) { DPRINTF(2, ("_next_dirent_: %lx/%lx/%lx\n", iter->csi.cluster, iter->csi.sector, iter->current_index)); if (buffer[0] == 0) { // quit if at end of table if (start_index != 0xffff) dprintf("lfn entry (%" B_PRIu32 ") with no alias\n", lfn_count); return ENOENT; } if (buffer[0] == 0xe5) { // skip erased entries if (start_index != 0xffff) { dprintf("lfn entry (%" B_PRIu32 ") with intervening erased " "entries\n", lfn_count); start_index = 0xffff; } DPRINTF(2, ("entry erased, skipping...\n")); continue; } if (buffer[0xb] == 0xf) { // long file name if ((buffer[0xc] != 0) || (buffer[0x1a] != 0) || (buffer[0x1b] != 0)) { dprintf("invalid long file name: reserved fields munged\n"); continue; } if (start_index == 0xffff) { if ((buffer[0] & 0x40) == 0) { dprintf("bad lfn start entry in directory\n"); continue; } hash = buffer[0xd]; lfn_count = buffer[0] & 0x1f; start_index = iter->current_index; puni = (uint16 *)(uni + 2*13*(lfn_count - 1)); for (i = 1; i < 0x20; i += 2) { if (*(uint16 *)&buffer[i] == 0xffff) break; *puni++ = *(uint16 *)&buffer[i]; if (i == 0x9) i+=3; if (i == 0x18) i+=2; } *puni++ = 0; filename_len = (uchar *)(puni) - uni; continue; } else { if (buffer[0xd] != hash) { dprintf("error in long file name: hash values don't match\n"); start_index = 0xffff; continue; } if (buffer[0] != --lfn_count) { dprintf("bad lfn entry in directory\n"); start_index = 0xffff; continue; } puni = (uint16 *)(uni + 2*13*(lfn_count - 1)); for (i = 1; i < 0x20; i += 2) { if ((buffer[i] == 0xff) && (buffer[i+1] == 0xff)) { dprintf("bad lfn entry in directory\n"); start_index = 0xffff; break; } *puni++ = *(uint16 *)&buffer[i]; if (i == 0x9) i+=3; if (i == 0x18) i+=2; } continue; } } break; } // hit end of directory entries with no luck if (buffer == NULL) return ENOENT; // process long name if (start_index != 0xffff) { if (lfn_count != 1) { dprintf("unfinished lfn in directory\n"); start_index = 0xffff; } else { if (unicode_to_utf8(uni, filename_len, (uint8*)filename, len)) { // rewind to beginning of call dprintf("error: long file name too long\n"); diri_free(iter); diri_init(iter->csi.vol, iter->starting_cluster, start_index, iter); return ENAMETOOLONG; } else if (hash_msdos_name((const char *)buffer) != hash) { dprintf("error: long file name (%s) hash and short file name " "don't match\n", filename); start_index = 0xffff; } } } // process short name if (start_index == 0xffff) { start_index = iter->current_index; // korli : seen on FreeBSD /src/sys/fs/msdosfs/direntry.h msdos_to_utf8(buffer, (uchar *)filename, len, buffer[0xc] & 0x18); } if (oinfo) { oinfo->sindex = start_index; oinfo->eindex = iter->current_index; oinfo->mode = buffer[0xb]; oinfo->cluster = read16(buffer,0x1a); if (iter->csi.vol->fat_bits == 32) oinfo->cluster += 0x10000*read16(buffer,0x14); oinfo->size = read32(buffer,0x1c); oinfo->time = read32(buffer,0x16); } diri_next_entry(iter); return B_NO_ERROR; }
/* * pg_saslprep - Normalize a password with SASLprep. * * SASLprep requires the input to be in UTF-8 encoding, but PostgreSQL * supports many encodings, so we don't blindly assume that. pg_saslprep * will check if the input looks like valid UTF-8, and returns * SASLPREP_INVALID_UTF8 if not. * * If the string contains prohibited characters (or more precisely, if the * output string would contain prohibited characters after normalization), * returns SASLPREP_PROHIBITED. * * On success, returns SASLPREP_SUCCESS, and the normalized string in * *output. * * In frontend, the normalized string is malloc'd, and the caller is * responsible for freeing it. If an allocation fails, returns * SASLPREP_OOM. In backend, the normalized string is palloc'd instead, * and a failed allocation leads to ereport(ERROR). */ pg_saslprep_rc pg_saslprep(const char *input, char **output) { pg_wchar *input_chars = NULL; pg_wchar *output_chars = NULL; int input_size; char *result; int result_size; int count; int i; bool contains_RandALCat; unsigned char *p; pg_wchar *wp; /* Ensure we return *output as NULL on failure */ *output = NULL; /* Check that the password isn't stupendously long */ if (strlen(input) > MAX_PASSWORD_LENGTH) { #ifndef FRONTEND ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("password too long"))); #else return SASLPREP_OOM; #endif } /* * Quick check if the input is pure ASCII. An ASCII string requires no * further processing. */ if (pg_is_ascii_string(input)) { *output = STRDUP(input); if (!(*output)) goto oom; return SASLPREP_SUCCESS; } /* * Convert the input from UTF-8 to an array of Unicode codepoints. * * This also checks that the input is a legal UTF-8 string. */ input_size = pg_utf8_string_len(input); if (input_size < 0) return SASLPREP_INVALID_UTF8; input_chars = ALLOC((input_size + 1) * sizeof(pg_wchar)); if (!input_chars) goto oom; p = (unsigned char *) input; for (i = 0; i < input_size; i++) { input_chars[i] = utf8_to_unicode(p); p += pg_utf_mblen(p); } input_chars[i] = (pg_wchar) '\0'; /* * The steps below correspond to the steps listed in [RFC3454], Section * "2. Preparation Overview" */ /* * 1) Map -- For each character in the input, check if it has a mapping * and, if so, replace it with its mapping. */ count = 0; for (i = 0; i < input_size; i++) { pg_wchar code = input_chars[i]; if (IS_CODE_IN_TABLE(code, non_ascii_space_ranges)) input_chars[count++] = 0x0020; else if (IS_CODE_IN_TABLE(code, commonly_mapped_to_nothing_ranges)) { /* map to nothing */ } else input_chars[count++] = code; } input_chars[count] = (pg_wchar) '\0'; input_size = count; if (input_size == 0) goto prohibited; /* don't allow empty password */ /* * 2) Normalize -- Normalize the result of step 1 using Unicode * normalization. */ output_chars = unicode_normalize_kc(input_chars); if (!output_chars) goto oom; /* * 3) Prohibit -- Check for any characters that are not allowed in the * output. If any are found, return an error. */ for (i = 0; i < input_size; i++) { pg_wchar code = input_chars[i]; if (IS_CODE_IN_TABLE(code, prohibited_output_ranges)) goto prohibited; if (IS_CODE_IN_TABLE(code, unassigned_codepoint_ranges)) goto prohibited; } /* * 4) Check bidi -- Possibly check for right-to-left characters, and if * any are found, make sure that the whole string satisfies the * requirements for bidirectional strings. If the string does not satisfy * the requirements for bidirectional strings, return an error. * * [RFC3454], Section "6. Bidirectional Characters" explains in more * detail what that means: * * "In any profile that specifies bidirectional character handling, all * three of the following requirements MUST be met: * * 1) The characters in section 5.8 MUST be prohibited. * * 2) If a string contains any RandALCat character, the string MUST NOT * contain any LCat character. * * 3) If a string contains any RandALCat character, a RandALCat character * MUST be the first character of the string, and a RandALCat character * MUST be the last character of the string." */ contains_RandALCat = false; for (i = 0; i < input_size; i++) { pg_wchar code = input_chars[i]; if (IS_CODE_IN_TABLE(code, RandALCat_codepoint_ranges)) { contains_RandALCat = true; break; } } if (contains_RandALCat) { pg_wchar first = input_chars[0]; pg_wchar last = input_chars[input_size - 1]; for (i = 0; i < input_size; i++) { pg_wchar code = input_chars[i]; if (IS_CODE_IN_TABLE(code, LCat_codepoint_ranges)) goto prohibited; } if (!IS_CODE_IN_TABLE(first, RandALCat_codepoint_ranges) || !IS_CODE_IN_TABLE(last, RandALCat_codepoint_ranges)) goto prohibited; } /* * Finally, convert the result back to UTF-8. */ result_size = 0; for (wp = output_chars; *wp; wp++) { unsigned char buf[4]; unicode_to_utf8(*wp, buf); result_size += pg_utf_mblen(buf); } result = ALLOC(result_size + 1); if (!result) goto oom; /* * There are no error exits below here, so the error exit paths don't need * to worry about possibly freeing "result". */ p = (unsigned char *) result; for (wp = output_chars; *wp; wp++) { unicode_to_utf8(*wp, p); p += pg_utf_mblen(p); } Assert((char *) p == result + result_size); *p = '\0'; FREE(input_chars); FREE(output_chars); *output = result; return SASLPREP_SUCCESS; prohibited: if (input_chars) FREE(input_chars); if (output_chars) FREE(output_chars); return SASLPREP_PROHIBITED; oom: if (input_chars) FREE(input_chars); if (output_chars) FREE(output_chars); return SASLPREP_OOM; }
int FSSftp::CheckSession( int* err, FSCInfo* info ) { if ( sshSession ) { return 0; } try { unsigned ip; int e; if ( !GetHostIp( unicode_to_utf8( _operParam.server.Data() ).data(), &ip, &e ) ) { throw int( e ); } _sock.Create(); _sock.Connect( ntohl( ip ), _operParam.port ); sshSession = libssh2_session_init(); if ( !sshSession ) { throw int( SSH_INTERROR_X3 ); } libssh2_session_set_blocking( sshSession, 0 ); WHILE_EAGAIN_( e, libssh2_session_handshake( sshSession, _sock.Id() ) ); if ( e ) { throw int( e - 1000 ); } FSString userName = ""; if ( _operParam.user.Data()[0] ) { userName = _operParam.user.Data(); } else { #ifndef _WIN32 char* ret = getenv( "LOGNAME" ); if ( ret ) { userName = FSString( sys_charset_id, ret ); _operParam.user = userName.GetUnicode(); MutexLock infoLock( &infoMutex ); _infoParam.user = userName.GetUnicode(); } #endif }; char* authList = 0; char* charUserName = ( char* )userName.Get( _operParam.charset ); while ( true ) { authList = libssh2_userauth_list( sshSession, charUserName, strlen( charUserName ) ); if ( authList ) { break; } CheckSessionEagain(); WaitSocket( info ); } //publickey,password,keyboard-interactive static const char passId[] = "password"; static const char kInterId[] = "keyboard-interactive"; static unicode_t userSymbol = '@'; while ( true ) { if ( !strncmp( authList, passId, strlen( passId ) ) ) { FSPromptData data; data.visible = false; data.prompt = utf8_to_unicode( "Password:"******"SFTP_" ).data(), carray_cat<unicode_t>( userName.GetUnicode(), &userSymbol, _operParam.server.Data() ).data(), &data, 1 ) ) { throw int( SSH_INTERROR_STOPPED ); } int ret; WHILE_EAGAIN_( ret, libssh2_userauth_password( sshSession, ( char* )FSString( _operParam.user.Data() ).Get( _operParam.charset ), ( char* )FSString( data.prompt.Data() ).Get( _operParam.charset ) ) ); if ( ret ) { throw int( ret - 1000 ); } break; //!!! } else if ( !strncmp( authList, kInterId, strlen( kInterId ) ) ) { MutexLock lock( &kbdIntMutex ); kbdIntInfo = info; kbdIntParam = &_operParam; int ret; WHILE_EAGAIN_( ret, libssh2_userauth_keyboard_interactive( sshSession, ( char* )FSString( _operParam.user.Data() ).Get( _operParam.charset ), KbIntCallback ) ); if ( ret ) { throw int( ret - 1000 ); } break; //!!! } char* s = authList; while ( *s && *s != ',' ) { s++; } if ( !*s ) { break; } authList = s + 1; }; while ( true ) { sftpSession = libssh2_sftp_init( sshSession ); if ( sftpSession ) { break; } if ( !sftpSession ) { int e = libssh2_session_last_errno( sshSession ); if ( e != LIBSSH2_ERROR_EAGAIN ) { throw int( e - 1000 ); } } WaitSocket( info ); } return 0; } catch ( int e ) { if ( err ) { *err = e; } //if (sftpSession) ??? похоже закрытие сессии все решает if ( sshSession ) { libssh2_session_free( sshSession ); } sshSession = 0; sftpSession = 0; _sock.Close( false ); return ( e == -2 ) ? -2 : -1; } }
/* * The next token in the input stream is known to be a string; lex it. */ static inline void json_lex_string(JsonLexContext *lex) { char *s; int len; int hi_surrogate = -1; if (lex->strval != NULL) resetStringInfo(lex->strval); Assert(lex->input_length > 0); s = lex->token_start; len = lex->token_start - lex->input; for (;;) { s++; len++; /* Premature end of the string. */ if (len >= lex->input_length) { lex->token_terminator = s; report_invalid_token(lex); } else if (*s == '"') break; else if ((unsigned char) *s < 32) { /* Per RFC4627, these characters MUST be escaped. */ /* Since *s isn't printable, exclude it from the context string */ lex->token_terminator = s; ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Character with value 0x%02x must be escaped.", (unsigned char) *s), report_json_context(lex))); } else if (*s == '\\') { /* OK, we have an escape character. */ s++; len++; if (len >= lex->input_length) { lex->token_terminator = s; report_invalid_token(lex); } else if (*s == 'u') { int i; int ch = 0; for (i = 1; i <= 4; i++) { s++; len++; if (len >= lex->input_length) { lex->token_terminator = s; report_invalid_token(lex); } else if (*s >= '0' && *s <= '9') ch = (ch * 16) + (*s - '0'); else if (*s >= 'a' && *s <= 'f') ch = (ch * 16) + (*s - 'a') + 10; else if (*s >= 'A' && *s <= 'F') ch = (ch * 16) + (*s - 'A') + 10; else { lex->token_terminator = s + pg_mblen(s); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("\"\\u\" must be followed by four hexadecimal digits."), report_json_context(lex))); } } if (lex->strval != NULL) { char utf8str[5]; int utf8len; if (ch >= 0xd800 && ch <= 0xdbff) { if (hi_surrogate != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode high surrogate must not follow a high surrogate."), report_json_context(lex))); hi_surrogate = (ch & 0x3ff) << 10; continue; } else if (ch >= 0xdc00 && ch <= 0xdfff) { if (hi_surrogate == -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode low surrogate must follow a high surrogate."), report_json_context(lex))); ch = 0x10000 + hi_surrogate + (ch & 0x3ff); hi_surrogate = -1; } if (hi_surrogate != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode low surrogate must follow a high surrogate."), report_json_context(lex))); /* * For UTF8, replace the escape sequence by the actual utf8 * character in lex->strval. Do this also for other encodings * if the escape designates an ASCII character, otherwise * raise an error. We don't ever unescape a \u0000, since that * would result in an impermissible nul byte. */ if (ch == 0) { appendStringInfoString(lex->strval, "\\u0000"); } else if (GetDatabaseEncoding() == PG_UTF8) { unicode_to_utf8(ch, (unsigned char *) utf8str); utf8len = pg_utf_mblen((unsigned char *) utf8str); appendBinaryStringInfo(lex->strval, utf8str, utf8len); } else if (ch <= 0x007f) { /* * This is the only way to designate things like a form feed * character in JSON, so it's useful in all encodings. */ appendStringInfoChar(lex->strval, (char) ch); } else { ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8."), report_json_context(lex))); } } } else if (lex->strval != NULL) { if (hi_surrogate != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode low surrogate must follow a high surrogate."), report_json_context(lex))); switch (*s) { case '"': case '\\': case '/': appendStringInfoChar(lex->strval, *s); break; case 'b': appendStringInfoChar(lex->strval, '\b'); break; case 'f': appendStringInfoChar(lex->strval, '\f'); break; case 'n': appendStringInfoChar(lex->strval, '\n'); break; case 'r': appendStringInfoChar(lex->strval, '\r'); break; case 't': appendStringInfoChar(lex->strval, '\t'); break; default: /* Not a valid string escape, so error out. */ lex->token_terminator = s + pg_mblen(s); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Escape sequence \"\\%s\" is invalid.", extract_mb_char(s)), report_json_context(lex))); } } else if (strchr("\"\\/bfnrt", *s) == NULL) { /* * Simpler processing if we're not bothered about de-escaping * * It's very tempting to remove the strchr() call here and * replace it with a switch statement, but testing so far has * shown it's not a performance win. */ lex->token_terminator = s + pg_mblen(s); ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Escape sequence \"\\%s\" is invalid.", extract_mb_char(s)), report_json_context(lex))); } } else if (lex->strval != NULL) { if (hi_surrogate != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode low surrogate must follow a high surrogate."), report_json_context(lex))); appendStringInfoChar(lex->strval, *s); } } if (hi_surrogate != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type json"), errdetail("Unicode low surrogate must follow a high surrogate."), report_json_context(lex))); /* Hooray, we found the end of the string! */ lex->prev_token_terminator = lex->token_terminator; lex->token_terminator = s + 1; }
void MainViewController::viewDidLoad() { // Do any additional setup after loading the view from its nib. m_winSize = this->getView()->getBounds().size; // header CAScale9ImageView* header = CAScale9ImageView::createWithImage(CAImage::create("common/sky_bg.png")); if (header) { header->setFrame(DRect((0), (0), m_winSize.width, (120))); header->setTouchEnabled(false); this->getView()->addSubview(header); // title lable CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, (80), m_winSize.width, (50))); if (label) { label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_white); label->setFontSize(SAP_TITLE_FONT_SIZE); label->setText("SAP d-kom"); label->setFontName(SAP_FONT_ARIAL); label->setTouchEnabled(false); header->addSubview(label); } } // left notification button CAButton* button = CAButton::createWithFrame(DRect((0), (20), (100), (100)), CAButtonTypeCustom); if (button) { button->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(20); this->getView()->addSubview(button); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_notification.png")); if (imageView) { imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackGroundViewForState(CAControlStateAll, imageView); } m_timeNoticeImageView = CAImageView::createWithFrame(DRect((60), (30), (20), (20))); if (m_timeNoticeImageView) { m_timeNoticeImageView->setImage(CAImage::create("common/reddot.png")); button->addSubview(m_timeNoticeImageView); } //refreshNoticeRedPoint(); } // notification alert point /* // right survey button button = CAButton::createWithFrame(DRect(m_winSize.width - (100), (20), (100), (100)), CAButtonTypeCustom); if (button) { button->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); button->setTag(30); this->getView()->addSubview(button); CAImageView* imageView = CAImageView::createWithImage(CAImage::create("main/nav_survey.png")); if (imageView) { imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); button->setBackgroundViewForState(CAControlStateAll, imageView); } } // survey lable CALabel * surveylable = CALabel::createWithFrame(DRect(m_winSize.width - (75), (100), (100), (25))); if (surveylable) { surveylable->setTextAlignment(CATextAlignmentLeft); surveylable->setColor(CAColor_white); surveylable->setFontSize(15); surveylable->setText("Survey"); surveylable->setFontName(SAP_FONT_ARIAL); surveylable->setTouchEnabled(false); this->getView()->addSubview(surveylable); } */ int pageViewHeight = m_winSize.height * 0.3; int butViewHeight = m_winSize.height * 0.15; int headerHeight = (120); int buttitleHeight = (40); /* // Page view if (!m_pageView) { m_pageView = CAPageView::createWithFrame(DRect(0, headerHeight, m_winSize.width, pageViewHeight), CAPageViewDirectionHorizontal); if (m_pageView) { m_pageView->setPageViewDelegate(this); m_pageView->setTouchEnabled(true); CAVector<CAView* > viewList; for (int i = 0; i<m_page.size(); i++) { CommonUrlImageView* temImage = CommonUrlImageView::createWithFrame(DRect(0, (0), m_winSize.width, pageViewHeight - headerHeight)); temImage->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); temImage->setImage(CAImage::create("common/bg.png")); temImage->setUrl(m_page[i].m_imageUrl); temImage->setTouchEnabled(false); viewList.pushBack(temImage); } m_pageView->setViews(viewList); m_pageView->setCurrPage(0, false); this->getView()->addSubview(m_pageView); //headView->addSubview(m_pageView); } } // picture dots bg in page view m_pageControlBG = CAView::createWithColor(ccc4(0, 0, 0, 20)); m_pageControlBG->setFrame(DRect(0, pageViewHeight + headerHeight - (50), m_winSize.width, (50))); m_pageControlBG->setTouchEnabled(false); this->getView()->addSubview(m_pageControlBG); //headView->addSubview(bg); // picture dots m_pageControl = CAPageControl::createWithCenter(DRect(m_winSize.width / 2, pageViewHeight + headerHeight - (25), (120), (50))); if (m_pageControl) { m_pageControl->setNumberOfPages((int)m_page.size()); m_pageControl->setTag(200); m_pageControl->addTarget(this, CAControl_selector(MainViewController::buttonCallBack)); this->getView()->addSubview(m_pageControl); } //headView->addSubview(m_pageControl); */ int buttonHight = (150);//m_winSize.height * 0.15;//(116); // three center button for (int i = 0; i < 3; i++) { DRect r(i * (m_winSize.width / 3), headerHeight + pageViewHeight, m_winSize.width / 3, buttonHight); CAButton* btn = CAButton::createWithFrame(r, CAButtonTypeCustom); btn->setTag(300 + i); CAImageView* imageView = CAImageView::createWithCenter(DRect(m_winSize.width / 3 / 2, (60), (60), (60)));//createWithImage(CAImage::create(crossapp_format_string("main/short_%d.png", i))); imageView->setImage(CAImage::create(crossapp_format_string("main/short_%d.png", i))); imageView->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); //imageView->setFrame(DRect(m_winSize.width / 3 / 2, (30), (60), (60))); imageView->setTouchEnabled(false); btn->addSubview(imageView); CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 3 / 2, (140), m_winSize.width / 3, (60))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray); label->setFontSize((28)); label->setText(unicode_to_utf8(mainShort[i])); label->setFontName(SAP_FONT_ARIAL); label->setTouchEnabled(false); btn->addSubview(label); btn->addTarget(this, CAControl_selector(MainViewController::buttonCallBack), CAControlEventTouchUpInSide); this->getView()->addSubview(btn); //headView->addSubview(btn); } /* if (m_page.size() > 0) { m_pageViewTitle = CALabel::createWithFrame(DRect(20, m_winSize.width / 2 - 40, m_winSize.width - 50, 50)); m_pageViewTitle->setText(m_page[0].m_title); m_pageViewTitle->setColor(CAColor_white); m_pageViewTitle->setFontSize((28)); m_pageViewTitle->setScrollEnabled(false); m_pageViewTitle->setTouchEnabled(false); this->getView()->addSubview(m_pageViewTitle); //headView->addSubview(m_pageViewTitle); } */ // sub title bar left picture CAView *subViewleft = CAView::createWithCenter(DRect((100), headerHeight + pageViewHeight + buttonHight + (20), m_winSize.width / 4, (20))); //CAView *subViewleft = CAView::createWithFrame(DRect(0, 0, m_winSize.width, (20))); CAImageView* subbarView1 = CAImageView::createWithImage(CAImage::create("main/home_bar.png")); subbarView1->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); subbarView1->setFrame(DRect(0, 0, m_winSize.width / 4, (20))); subbarView1->setTouchEnabled(false); subViewleft->addSubview(subbarView1); this->getView()->addSubview(subViewleft); // sub title CALabel* label = CALabel::createWithCenter(DRect(m_winSize.width / 2, headerHeight + pageViewHeight + buttonHight + (30), m_winSize.width / 2, (45))); label->setTextAlignment(CATextAlignmentCenter); label->setColor(CAColor_gray);//ccc4(0x0f, 0xaa, 0xff, 0xff));//CAColor_gray);//CAColor_blue); label->setFontSize((27)); label->setText("My Agenda"); label->setFontName(SAP_FONT_ARIAL);//markerfelt.ttf"); label->setTouchEnabled(false); this->getView()->addSubview(label); // sub title bar right picture CAView *subViewright = CAView::createWithCenter(DRect(m_winSize.width - (100), headerHeight + pageViewHeight +buttonHight + (20), m_winSize.width / 4, (20))); CAImageView* subbarView2 = CAImageView::createWithImage(CAImage::create("main/home_bar.png")); subbarView2->setImageViewScaleType(CAImageViewScaleTypeFitImageXY); subbarView2->setFrame(DRect(0, 0, m_winSize.width / 4, (20))); subbarView2->setTouchEnabled(false); subViewright->addSubview(subbarView2); this->getView()->addSubview(subViewright); //CAView* headView = CAView::createWithFrame(DRect(0, 0, m_winSize.width, m_winSize.width * 0.6 - (120))); //m_msgTableView->setTableHeaderView(headView); //m_msgTableView->setTableHeaderHeight(m_winSize.width / 2 + (130)); int tableStartY = pageViewHeight + butViewHeight + headerHeight + buttitleHeight + (15); m_msgTableView = CATableView::createWithFrame(DRect(0, tableStartY, m_winSize.width, m_winSize.height - tableStartY)); if (m_msgTableView) { m_msgTableView->setTableViewDataSource(this); m_msgTableView->setTableViewDelegate(this); m_msgTableView->setScrollViewDelegate(this); m_msgTableView->setAllowsSelection(true); m_msgTableView->setSeparatorColor(ccc4(200, 200, 200, 80)); //m_msgTableView->setSeparatorViewHeight((2)); this->getView()->addSubview(m_msgTableView); CAPullToRefreshView *refreshDiscount = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeFooter); if (refreshDiscount) { refreshDiscount->setLabelColor(CAColor_black); m_msgTableView->setFooterRefreshView(refreshDiscount); } // CAPullToRefreshView *refreshDiscount1 = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader); // if (refreshDiscount1) { // refreshDiscount1->setLabelColor(CAColor_black); // m_msgTableView->setHeaderRefreshView(refreshDiscount1); // } } if (m_msg->empty()) { requestSessionMsg(); p_pLoading = CAActivityIndicatorView::createWithCenter(DRect(m_winSize.width / 2, m_winSize.height / 2, 50, 50)); this->getView()->insertSubview(p_pLoading, CAWindowZOderTop); p_pLoading->setLoadingMinTime(0.5f); // p_pLoading->setTargetOnCancel(this, callfunc_selector(MainViewController::initMsgTableView)); } else { // this->initMsgTableView(); } }
int main(int argc, char *argv[]) { int fd; char * pb, *pe; char * rd_buf = NULL; struct stat st; u16_t unicode = 0x0000; u32_t utf8 = 0x00; i32_t utf8_len = 0; i32_t line_len = 0; if (argc < 2) { return 1; } fd = open(argv[1], O_RDONLY, 0); if (fd < 0) { return 0; } if (0 != fstat(fd, &st)) { close(fd); return 1; } if (st.st_size <= 0) { close(fd); return 1; } rd_buf = (char*)malloc(st.st_size+1); if (NULL == rd_buf) { close(fd); return 1; } if (read(fd, rd_buf, st.st_size) != st.st_size) { close(fd); return 1; } rd_buf[st.st_size] = '\0'; pb = strtok(rd_buf, "\n"); while (NULL != pb) { line_len = strlen(pb); char *pf; pe = strtok(pb, "\t"); pf = strtok(NULL, "\t"); unicode = strtoul(pf, NULL, 16); utf8_len = sizeof(utf8); unicode_to_utf8(&unicode, 1, (u8_p)&utf8, &utf8_len); //fprintf(stdout, "%s %s 0x%08x[%d]\n", pe, pf, utf8, utf8_len); fprintf(stdout, "%s %s 0x%08x\n", pe, pf, utf8); pb = pb + line_len + 1; pb = strtok(pb, "\n"); } if (rd_buf) { free(rd_buf); rd_buf = NULL; } if (fd > 0) { close(fd); } return 0; }