char* TNtlmAuth::getChallenge( const TCHAR* challenge ) { if ( !hProvider ) return NULL; char *text = t2a( challenge ), *result; if ( info->password[0] != 0 ) { char* user = t2a( info->username ); result = Netlib_NtlmCreateResponse( hProvider, text, user, info->password ); mir_free( user ); } else result = Netlib_NtlmCreateResponse( hProvider, text, NULL, NULL ); mir_free( text ); return result; }
void WriteDebugLog(DWORD dwLastError, LPCSTR file, int codeLine, LOG_LEVEL level, LPCTSTR content, ...) { //格式化日志 TCHAR logContent[ODS_LOG_MAXLENGTH + 1] = {0}; DWORD dwThreadID = ::GetCurrentThreadId(); std::string ansiCodefile = file; std::string::size_type pos = ansiCodefile.find_last_of('\\'); if (pos != std::string::npos && pos + 1 < ansiCodefile.size()) ansiCodefile = ansiCodefile.substr(pos + 1); tstring codeFile = s2ws(ansiCodefile); tstring strLevel; switch (level) { case ODSLEVEL_DEBUG: strLevel = _T("debug"); break; case ODSLEVEL_INFO: strLevel = _T("info"); break; case ODSLEVEL_ERROR: strLevel = _T("error"); break; default: strLevel = _T("unknown"); break; } int iWritten = _stprintf_s(logContent, _T("%s [%s:%d] %u "), strLevel.c_str(), codeFile.c_str(), codeLine, dwThreadID); va_list ap; va_start(ap, content); _vsntprintf_s(logContent + iWritten, ODS_LOG_MAXLENGTH - iWritten, _TRUNCATE, content, ap); va_end(ap); if (dwLastError != 0) { TCHAR lastError[16] = {0}; _stprintf_s(lastError, 15, _T(" E%u"), dwLastError); size_t len = _tcslen(logContent); if (len + _tcslen(lastError) < ODS_LOG_MAXLENGTH) { _tcscat_s(logContent, lastError); } } // //写入日志 // #ifdef ODS_OUTPUT_STD printf("%s\n", t2a(logContent)); // #endif #ifdef ODS_OUTPUT_FILE OutputFile(logContent); #endif OutputDebugString(logContent); }
static int PushIconLibRegistration( TCHAR* TransportDomain ) //need to push Imagelist addition to { if ( ServiceExists( MS_SKIN2_ADDICON )) { char* domain = t2a(TransportDomain); int result = GetTransportStatusIconIndex(GetTransportProtoID(domain),ID_STATUS_OFFLINE); mir_free( domain ); return result; } return 0; }
int JabberSearchByAdvanced( WPARAM wParam, LPARAM lParam ) { if ( !jabberOnline || !lParam) return 0; //error HWND hwndDlg=(HWND) lParam; JabberSearchData * dat=(JabberSearchData *)GetWindowLong(hwndDlg,GWL_USERDATA); if ( !dat ) return 0; //error // check if server connected (at least one field exists) if ( dat->nJSInfCount == 0 ) return 0; // formating request BOOL fRequestNotEmpty=FALSE; // get server name char szServerName[100]; GetDlgItemTextA( hwndDlg, IDC_SERVER, szServerName, sizeof( szServerName )); // formating query int iqId = JabberSerialNext(); XmlNodeIq iq( "set", iqId, szServerName ); XmlNode* query = iq.addChild( "query" ), *field; iq.addAttr( "xml:lang", "en" ); //? not sure is it needed ? query->addAttr( "xmlns", "jabber:iq:search" ); // next can be 2 cases: // Forms: XEP-0055 Example 7 if ( dat->fSearchRequestIsXForm ) { fRequestNotEmpty=TRUE; query->addChild(JabberFormGetData(GetDlgItem(hwndDlg, IDC_FRAME), dat->xNode)); } else { //and Simple fields: XEP-0055 Example 3 for ( int i=0; i<dat->nJSInfCount; i++ ) { TCHAR szFieldValue[100]; GetWindowText(dat->pJSInf[i].hwndValueItem, szFieldValue, SIZEOF(szFieldValue)); if ( szFieldValue[0] != _T('\0')) { char* szTemp=t2a(dat->pJSInf[i].szFieldName); field = query->addChild( szTemp, szFieldValue ); mir_free(szTemp); fRequestNotEmpty=TRUE; } } } if ( fRequestNotEmpty ) { // register search request result handler JabberIqAdd( iqId, IQ_PROC_GETSEARCH, JabberIqResultAdvancedSearch ); // send request JabberSend( jabberThreadInfo->s, iq ); return iqId; } return 0; }
char* TPlainAuth::getInitialRequest() { char *temp = t2a(info->username); int size = strlen(temp)*2+strlen(info->server)+strlen(info->password)+3; char *toEncode = ( char* )alloca( size+1 ); mir_snprintf( toEncode, size+1, "%s@%s%c%s%c%s", temp, info->server, 0, temp, 0, info->password ); char* result = JabberBase64Encode( toEncode, size ); mir_free(temp); JabberLog( "Never publish the hash below" ); return result; }
void Test2() { Harness::SpinBarrier barr(2); TestFunc2a func2a(barr); TestTask2a t2a(0, func2a); TestFunc2b func2b(barr, t2a); NativeParallelForTask<int,TestFunc2b> t2b(1, func2b); FinishedTasks = 0; t2a.start(); t2b.start(); Harness::Sleep(1000); // wait a second :) ASSERT( FinishedTasks==2, "Threads appear to deadlock" ); t2b.wait_to_finish(); // t2a is monitored by t2b }
// hKey must have been opened with KEY_QUERY_VALUE access right static BOOL IsRegStrValueA(HKEY hKey,const TCHAR *pszValName,const char *pszCmpVal) { BOOL fSame=FALSE; char *pszValA; TCHAR *pszVal=GetRegStrValue(hKey,pszValName); if (pszVal!=NULL) { pszValA=t2a(pszVal); if (pszValA!=NULL) fSame=!mir_strcmp(pszValA,pszCmpVal); mir_free(pszValA); /* does NULL check */ mir_free(pszVal); } return fSame; }
void Test2() { Harness::SpinBarrier barr(2); TestFunc2a func2a(barr); TestTask2a t2a(0, func2a); TestFunc2b func2b(barr, t2a); #if USE_LITHE tbb::lithe::scheduler sched; lithe_sched_enter(&sched); #endif NativeParallelForTask<int,TestFunc2b> t2b(1, func2b); FinishedTasks = 0; t2a.start(); t2b.start(); #if USE_LITHE sched.joinAll(); lithe_sched_exit(); #else Harness::Sleep(1000); // wait a second :) #endif ASSERT( FinishedTasks==2, "Threads appear to deadlock" ); t2b.wait_to_finish(); // t2a is monitored by t2b }
void CLPLpsolve::writeSolution(const TCHAR *pathname) { char buf[200]; buf[sizeof(buf) - 1] = '\0'; FILE *str = _tfopen(pathname, _T("w")); if (!str) { _snprintf(buf, sizeof(buf) - 1, "Can't create file: '%s'.", t2a(pathname).c_str()); GlobalMessage(buf); return; } _snprintf(buf, sizeof(buf) - 1, "Objective value :\t%f\n\n", getPrimalObjectiveValue()); fprintf(str, buf); for (int i = 0; i < m_lpFunction->getNumCoefficients(); i++) { _snprintf(buf, sizeof(buf) - 1, "%s : \t%f\n", m_lpFunction->getVarNames().at(i).c_str(), getPrimalVariableValue(i)); fprintf(str, buf); } fclose(str); }
void OutputFile(LPCTSTR content) { static BOOL bOpened = FALSE; g_fileSection.Enter(); { do { HANDLE hFile = CreateFile(_T("C:\\ods.log"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); if (hFile != INVALID_HANDLE_VALUE) ::SetFilePointer(hFile, 0, NULL, FILE_END); else break; std::string ansiContent = t2a(content); ansiContent += "\r\n"; DWORD dwWritten = 0 ; WriteFile(hFile,(LPBYTE)ansiContent.c_str(), ansiContent.size(),&dwWritten,0); CloseHandle(hFile); } while (FALSE); } g_fileSection.Leave(); }
static BOOL CALLBACK JabberGroupchatDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { HWND lv; LVCOLUMN lvCol; LVITEM lvItem; JABBER_LIST_ITEM *item; switch ( msg ) { case WM_INITDIALOG: // lParam is the initial conference server ( if any ) SendMessage( hwndDlg, WM_SETICON, ICON_BIG, ( LPARAM )iconBigList[0] ); TranslateDialogDefault( hwndDlg ); sortColumn = -1; // Add columns lv = GetDlgItem( hwndDlg, IDC_ROOM ); lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; lvCol.pszText = TranslateT( "JID" ); lvCol.cx = 210; lvCol.iSubItem = 0; ListView_InsertColumn( lv, 0, &lvCol ); lvCol.pszText = TranslateT( "Name" ); lvCol.cx = 150; lvCol.iSubItem = 1; ListView_InsertColumn( lv, 1, &lvCol ); lvCol.pszText = TranslateT( "Type" ); lvCol.cx = 60; lvCol.iSubItem = 2; ListView_InsertColumn( lv, 2, &lvCol ); if ( jabberOnline ) { if (( TCHAR* )lParam != NULL ) { SetDlgItemText( hwndDlg, IDC_SERVER, ( TCHAR* )lParam ); int iqId = JabberSerialNext(); JabberIqAdd( iqId, IQ_PROC_DISCOROOMSERVER, JabberIqResultDiscoRoomItems ); XmlNodeIq iq( "get", iqId, ( TCHAR* )lParam ); XmlNode* query = iq.addQuery( "http://jabber.org/protocol/disco#items" ); JabberSend( jabberThreadInfo->s, iq ); } else { for ( int i=0; i < GC_SERVER_LIST_SIZE; i++ ) { char text[100]; mir_snprintf( text, sizeof( text ), "GcServerLast%d", i ); DBVARIANT dbv; if ( !JGetStringT( NULL, text, &dbv )) { SendDlgItemMessage( hwndDlg, IDC_SERVER, CB_ADDSTRING, 0, ( LPARAM )dbv.ptszVal ); JFreeVariant( &dbv ); } } } } else EnableWindow( GetDlgItem( hwndDlg, IDC_JOIN ), FALSE ); return TRUE; case WM_JABBER_ACTIVATE: // lParam = server from which agent information is obtained if ( lParam ) SetDlgItemText( hwndDlg, IDC_SERVER, ( TCHAR* )lParam ); ListView_DeleteAllItems( GetDlgItem( hwndDlg, IDC_ROOM )); EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), FALSE ); return TRUE; case WM_JABBER_REFRESH: // lParam = server from which agent information is obtained { int i; TCHAR szBuffer[256]; char text[128]; if ( lParam ){ _tcsncpy( szBuffer, ( TCHAR* )lParam, SIZEOF( szBuffer )); for ( i=0; i<GC_SERVER_LIST_SIZE; i++ ) { mir_snprintf( text, SIZEOF( text ), "GcServerLast%d", i ); DBVARIANT dbv; if ( !JGetStringT( NULL, text, &dbv )) { JSetStringT( NULL, text, szBuffer ); if ( !_tcsicmp( dbv.ptszVal, ( TCHAR* )lParam )) { JFreeVariant( &dbv ); break; } _tcsncpy( szBuffer, dbv.ptszVal, SIZEOF( szBuffer )); JFreeVariant( &dbv ); } else { JSetStringT( NULL, text, szBuffer ); break; } } SendDlgItemMessage( hwndDlg, IDC_SERVER, CB_RESETCONTENT, 0, 0 ); for ( i=0; i<GC_SERVER_LIST_SIZE; i++ ) { mir_snprintf( text, SIZEOF( text ), "GcServerLast%d", i ); DBVARIANT dbv; if ( !JGetStringT( NULL, text, &dbv )) { SendDlgItemMessage( hwndDlg, IDC_SERVER, CB_ADDSTRING, 0, ( LPARAM )dbv.ptszVal ); JFreeVariant( &dbv ); } } SetDlgItemText( hwndDlg, IDC_SERVER, ( TCHAR* )lParam ); } i = 0; lv = GetDlgItem( hwndDlg, IDC_ROOM ); ListView_DeleteAllItems( lv ); LVITEM lvItem; lvItem.iItem = 0; while (( i=JabberListFindNext( LIST_ROOM, i )) >= 0 ) { if (( item=JabberListGetItemPtrFromIndex( i )) != NULL ) { lvItem.mask = LVIF_PARAM | LVIF_TEXT; lvItem.iSubItem = 0; _tcsncpy( szBuffer, item->jid, SIZEOF(szBuffer)); szBuffer[ SIZEOF(szBuffer)-1 ] = 0; lvItem.lParam = ( LPARAM )item->jid; lvItem.pszText = szBuffer; ListView_InsertItem( lv, &lvItem ); lvItem.mask = LVIF_TEXT; lvItem.iSubItem = 1; lvItem.pszText = item->name; ListView_SetItem( lv, &lvItem ); lvItem.iSubItem = 2; lvItem.pszText = item->type; ListView_SetItem( lv, &lvItem ); lvItem.iItem++; } i++; } EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), TRUE ); } return TRUE; case WM_JABBER_CHECK_ONLINE: { TCHAR text[128]; if ( jabberOnline ) { EnableWindow( GetDlgItem( hwndDlg, IDC_JOIN ), TRUE ); GetDlgItemText( hwndDlg, IDC_SERVER, text, SIZEOF( text )); EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), ( text[0]!='\0' )); } else { EnableWindow( GetDlgItem( hwndDlg, IDC_JOIN ), FALSE ); EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), FALSE ); SetDlgItemTextA( hwndDlg, IDC_SERVER, "" ); lv = GetDlgItem( hwndDlg, IDC_ROOM ); ListView_DeleteAllItems( lv ); } break; } case WM_NOTIFY: switch ( wParam ) { case IDC_ROOM: switch (( ( LPNMHDR )lParam )->code ) { case LVN_COLUMNCLICK: { LPNMLISTVIEW pnmlv = ( LPNMLISTVIEW ) lParam; if ( pnmlv->iSubItem>=0 && pnmlv->iSubItem<=1 ) { if ( pnmlv->iSubItem == sortColumn ) sortAscending = !sortAscending; else { sortAscending = TRUE; sortColumn = pnmlv->iSubItem; } ListView_SortItems( GetDlgItem( hwndDlg, IDC_ROOM ), GroupchatCompare, sortColumn ); } } break; } break; } break; case WM_COMMAND: switch ( LOWORD( wParam )) { case WM_JABBER_JOIN: if ( jabberChatDllPresent ) { lv = GetDlgItem( hwndDlg, IDC_ROOM ); if (( lvItem.iItem=ListView_GetNextItem( lv, -1, LVNI_SELECTED )) >= 0 ) { lvItem.iSubItem = 0; lvItem.mask = LVIF_PARAM; ListView_GetItem( lv, &lvItem ); ListView_SetItemState( lv, lvItem.iItem, 0, LVIS_SELECTED ); // Unselect the item DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_GROUPCHAT_JOIN ), hwndDlg, JabberGroupchatJoinDlgProc, ( LPARAM )lvItem.lParam ); } else { TCHAR text[128]; GetDlgItemText( hwndDlg, IDC_SERVER, text, SIZEOF( text )); DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_GROUPCHAT_JOIN ), hwndDlg, JabberGroupchatJoinDlgProc, ( LPARAM )text ); } } else JabberChatDllError(); return TRUE; case WM_JABBER_ADD_TO_ROSTER: lv = GetDlgItem( hwndDlg, IDC_ROOM ); if (( lvItem.iItem=ListView_GetNextItem( lv, -1, LVNI_SELECTED )) >= 0 ) { lvItem.iSubItem = 0; lvItem.mask = LVIF_PARAM; ListView_GetItem( lv, &lvItem ); TCHAR* jid = ( TCHAR* )lvItem.lParam; { GCSESSION gcw = {0}; gcw.cbSize = sizeof(GCSESSION); gcw.iType = GCW_CHATROOM; gcw.pszID = t2a(jid); gcw.pszModule = jabberProtoName; gcw.pszName = NEWSTR_ALLOCA(gcw.pszID); char* p = ( char* )strchr( gcw.pszName, '@' ); if ( p != NULL ) *p = 0; CallService( MS_GC_NEWSESSION, 0, ( LPARAM )&gcw ); mir_free((void*)gcw.pszID); } { XmlNodeIq iq( "set" ); XmlNode* query = iq.addQuery( "jabber:iq:roster" ); XmlNode* item = query->addChild( "item" ); item->addAttr( "jid", jid ); JabberSend( jabberThreadInfo->s, iq ); } { XmlNode p( "presence" ); p.addAttr( "to", jid ); p.addAttr( "type", "subscribe" ); JabberSend( jabberThreadInfo->s, p ); } } break; case WM_JABBER_ADD_TO_BOOKMARKS: lv = GetDlgItem( hwndDlg, IDC_ROOM ); if (( lvItem.iItem=ListView_GetNextItem( lv, -1, LVNI_SELECTED )) >= 0 ) { lvItem.iSubItem = 0; lvItem.mask = LVIF_PARAM; ListView_GetItem( lv, &lvItem ); JABBER_LIST_ITEM* item = JabberListGetItemPtr( LIST_BOOKMARK, ( TCHAR* )lvItem.lParam ); if ( item == NULL ) { item = JabberListGetItemPtr( LIST_ROOM, ( TCHAR* )lvItem.lParam ); if (item != NULL) { item->type = _T("conference"); JabberAddEditBookmark(NULL, (LPARAM) item); } } } break; case IDC_SERVER: { TCHAR text[ 128 ]; GetDlgItemText( hwndDlg, IDC_SERVER, text, SIZEOF( text )); if ( jabberOnline && ( text[0] || HIWORD( wParam )==CBN_SELCHANGE )) EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), TRUE ); break; } case IDC_BROWSE: { TCHAR text[ 128 ]; GetDlgItemText( hwndDlg, IDC_SERVER, text, SIZEOF( text )); if ( jabberOnline && text[0] ) { EnableWindow( GetDlgItem( hwndDlg, IDC_BROWSE ), FALSE ); ListView_DeleteAllItems( GetDlgItem( hwndDlg, IDC_ROOM )); GetDlgItemText( hwndDlg, IDC_SERVER, text, SIZEOF( text )); int iqId = JabberSerialNext(); JabberIqAdd( iqId, IQ_PROC_DISCOROOMSERVER, JabberIqResultDiscoRoomItems ); XmlNodeIq iq( "get", iqId, text ); XmlNode* query = iq.addQuery( "http://jabber.org/protocol/disco#items" ); JabberSend( jabberThreadInfo->s, iq ); } return TRUE; } case IDCLOSE: DestroyWindow( hwndDlg ); return TRUE; } break; case WM_CONTEXTMENU: if (( HWND )wParam == GetDlgItem( hwndDlg, IDC_ROOM )) { HMENU hMenu = CreatePopupMenu(); AppendMenu( hMenu, MF_STRING, WM_JABBER_JOIN, TranslateT( "Join" )); AppendMenu( hMenu, MF_STRING, WM_JABBER_ADD_TO_ROSTER, TranslateT( "Add to roster" )); if ( jabberThreadInfo->caps & CAPS_BOOKMARK ) AppendMenu( hMenu, MF_STRING, WM_JABBER_ADD_TO_BOOKMARKS, TranslateT( "Add to Bookmarks" )); TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_NONOTIFY, LOWORD(lParam), HIWORD(lParam), 0, hwndDlg, 0 ); ::DestroyMenu( hMenu ); return TRUE; } break; case WM_CLOSE: DestroyWindow( hwndDlg ); break; case WM_DESTROY: hwndJabberGroupchat = NULL; break; } return FALSE; }
void JabberFtHandleSiRequest( XmlNode *iqNode ) { TCHAR* from, *sid, *str, *szId, *filename; XmlNode *siNode, *fileNode, *featureNode, *xNode, *fieldNode, *optionNode, *n; int filesize, i; JABBER_FT_TYPE ftType; if ( iqNode==NULL || ( from=JabberXmlGetAttrValue( iqNode, "from" ))==NULL || ( str=JabberXmlGetAttrValue( iqNode, "type" ))==NULL || _tcscmp( str, _T("set")) || ( siNode=JabberXmlGetChildWithGivenAttrValue( iqNode, "si", "xmlns", _T("http://jabber.org/protocol/si"))) == NULL ) return; szId = JabberXmlGetAttrValue( iqNode, "id" ); if (( sid=JabberXmlGetAttrValue( siNode, "id" ))!=NULL && ( fileNode=JabberXmlGetChildWithGivenAttrValue( siNode, "file", "xmlns", _T("http://jabber.org/protocol/si/profile/file-transfer")))!=NULL && ( filename=JabberXmlGetAttrValue( fileNode, "name" ))!=NULL && ( str=JabberXmlGetAttrValue( fileNode, "size" ))!=NULL ) { filesize = _ttoi( str ); if (( featureNode=JabberXmlGetChildWithGivenAttrValue( siNode, "feature", "xmlns", _T("http://jabber.org/protocol/feature-neg"))) != NULL && ( xNode=JabberXmlGetChildWithGivenAttrValue( featureNode, "x", "xmlns", _T("jabber:x:data")))!=NULL && ( fieldNode=JabberXmlGetChildWithGivenAttrValue( xNode, "field", "var", _T("stream-method")))!=NULL ) { for ( i=0; i<fieldNode->numChild; i++ ) { optionNode = fieldNode->child[i]; if ( optionNode->name && !strcmp( optionNode->name, "option" )) { if (( n=JabberXmlGetChild( optionNode, "value" ))!=NULL && n->text ) { if ( !_tcscmp( n->text, _T("http://jabber.org/protocol/bytestreams"))) { ftType = FT_BYTESTREAM; break; } } } } if ( i < fieldNode->numChild ) { // Found known stream mechanism CCSDATA ccs; PROTORECVEVENT pre; char *localFilename = t2a( filename ); char *desc = (( n=JabberXmlGetChild( fileNode, "desc" ))!=NULL && n->text!=NULL ) ? t2a( n->text ) : mir_strdup( "" ); filetransfer* ft = new filetransfer; ft->jid = mir_tstrdup( from ); ft->std.hContact = JabberHContactFromJID( from ); ft->sid = mir_tstrdup( sid ); ft->iqId = mir_tstrdup( szId ); ft->type = ftType; ft->std.totalFiles = 1; ft->std.currentFile = localFilename; ft->std.totalBytes = ft->std.currentFileSize = filesize; char* szBlob = ( char* )alloca( sizeof( DWORD )+ strlen( localFilename ) + strlen( desc ) + 2 ); *(( PDWORD ) szBlob ) = ( DWORD )ft; strcpy( szBlob + sizeof( DWORD ), localFilename ); strcpy( szBlob + sizeof( DWORD )+ strlen( localFilename ) + 1, desc ); pre.flags = 0; pre.timestamp = time( NULL ); pre.szMessage = szBlob; pre.lParam = 0; ccs.szProtoService = PSR_FILE; ccs.hContact = ft->std.hContact; ccs.wParam = 0; ccs.lParam = ( LPARAM )⪯ JCallService( MS_PROTO_CHAINRECV, 0, ( LPARAM )&ccs ); mir_free( desc ); return; } else { // Unknown stream mechanism XmlNodeIq iq( "error", szId, from ); XmlNode* e = iq.addChild( "error" ); e->addAttr( "code", 400 ); e->addAttr( "type", "cancel" ); XmlNode* br = e->addChild( "bad-request" ); br->addAttr( "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas" ); XmlNode* nvs = e->addChild( "no-valid-streams" ); nvs->addAttr( "xmlns", "http://jabber.org/protocol/si" ); JabberSend( jabberThreadInfo->s, iq ); return; } } } // Bad stream initiation, reply with bad-profile XmlNodeIq iq( "error", szId, from ); XmlNode* e = iq.addChild( "error" ); e->addAttr( "code", 400 ); e->addAttr( "type", "cancel" ); XmlNode* br = e->addChild( "bad-request" ); br->addAttr( "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas" ); XmlNode* nvs = e->addChild( "bad-profile" ); nvs->addAttr( "xmlns", "http://jabber.org/protocol/si" ); JabberSend( jabberThreadInfo->s, iq ); }
int main(int argc, char * const argv[]) { int opt_index, c; static struct option long_opts[] = { {"target", 1, 0, 0}, {"dumpfile", 1, 0, 0}, {"ssh", 1, 0, 0}, {0, 0, 0, 0} }; if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE))) usage(argv[0]); while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) { switch (c) { case 0: { if (!optarg[0]) usage(argv[0]); if (!strcmp(long_opts[opt_index].name, "target")) { setenv(ENV_LUSTRE_MNTTGT, optarg, 1); } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) { setenv(ENV_LUSTRE_DUMPFILE, optarg, 1); } else if (!strcmp(long_opts[opt_index].name, "ssh")) { safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE); } else usage(argv[0]); break; } case 's': safe_strncpy(mds_server, optarg, MAX_STRING_SIZE); break; case 'b': safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE); break; case 'f': safe_strncpy(failover_script, optarg, MAX_STRING_SIZE); break; default: usage(argv[0]); } } if (optind != argc) usage(argv[0]); if (!strlen(mds_server) || !strlen(barrier_script) || !strlen(failover_script)) usage(argv[0]); /* default to using ssh */ if (!strlen(ssh_cmd)) { safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE); } test_ssh(); /* prepare remote command */ sprintf(barrier_cmd, "%s %s \"%s\"", ssh_cmd, mds_server, barrier_script); sprintf(failover_cmd, "%s %s \"%s\"", ssh_cmd, mds_server, failover_script); setenv(ENV_LUSTRE_TIMEOUT, "10", 1); __liblustre_setup_(); t0(); t1(); t2a(); t2b(); t3a(); t3b(); t4(); t5(); t6(); t7(); t8(); t9(); t10(); printf("liblustre is about shutdown\n"); __liblustre_cleanup_(); printf("complete successfully\n"); return 0; }
void test_constructors() { cout << "test_constructors" << endl; sc_time t1; cout << t1 << endl; sc_time t2a( 0, SC_SEC ); cout << t2a << endl; sc_time t2b( 1.2345, SC_NS ); cout << t2b << endl; sc_time t2c( 1.2341, SC_NS ); cout << t2c << endl; sc_time t2d( 1, SC_FS ); cout << t2d << endl; sc_time t2e( -1.2345, SC_NS ); cout << t2e << endl; sc_time t2f( -1.2341, SC_NS ); cout << t2f << endl; char v1 = 1; signed char v2 = 2; unsigned char v3 = 3; short v4 = 4; unsigned short v5 = 5; int v6 = 6; unsigned int v7 = 7; long v8 = 8; unsigned long v9 = 9; float v10 = 10; double v11 = 11; sc_time t2g( v1, SC_NS ); cout << t2g << endl; sc_time t2h( v2, SC_NS ); cout << t2h << endl; sc_time t2i( v3, SC_NS ); cout << t2i << endl; sc_time t2j( v4, SC_NS ); cout << t2j << endl; sc_time t2k( v5, SC_NS ); cout << t2k << endl; sc_time t2l( v6, SC_NS ); cout << t2l << endl; sc_time t2m( v7, SC_NS ); cout << t2m << endl; sc_time t2n( v8, SC_NS ); cout << t2n << endl; sc_time t2o( v9, SC_NS ); cout << t2o << endl; sc_time t2p( v10, SC_NS ); cout << t2p << endl; sc_time t2q( v11, SC_NS ); cout << t2q << endl; sc_time t3a( 0, SC_SEC ); cout << t3a << endl; sc_time t3b( 1.2341, true ); cout << t3b << endl; sc_time t3c( 1.2345, true ); cout << t3c << endl; sc_time t3d( -1.2341, true ); cout << t3d << endl; sc_time t3e( -1.2345, true ); cout << t3e << endl; sc_time t3f( 1.2345, false ); cout << t3f << endl; sc_time t3g( 1.5432, false ); cout << t3g << endl; sc_time t3h( -1.2345, false ); cout << t3h << endl; sc_time t3i( -1.5432, false ); cout << t3i << endl; #if !defined( _MSC_VER ) sc_time t4a( 0ull, true ); cout << t4a << endl; sc_time t4b( 25ull, true ); cout << t4b << endl; sc_time t4c( 25ull, false ); cout << t4c << endl; #else sc_time t4a( 0ui64, true ); cout << t4a << endl; sc_time t4b( 25ui64, true ); cout << t4b << endl; sc_time t4c( 25ui64, false ); cout << t4c << endl; #endif sc_time t5( t4c ); cout << t5 << endl; }
void ClientInfoManager::TransferInfo( LPCTSTR clientid, const CLIENT_BASE_INFO* pBaseInfo, CLIENT_INFO& info ) const { ZeroMemory(&info, sizeof(CLIENT_INFO)); _tcscpy_s(info.clientid, clientid); //ZeroMemory(&info.installTime, sizeof(info.installTime)); if (NULL != pBaseInfo) { info.bX64 = pBaseInfo->bX64; _tcscpy_s(info.computerName, pBaseInfo->computerName.c_str()); info.connectIP = pBaseInfo->connectIP; info.windowsVersion = pBaseInfo->windowsVersion; _tcscpy_s(info.mods, pBaseInfo->mods.c_str()); _tcscpy_s(info.groups,pBaseInfo->groups.c_str()); _tcscpy_s(info.priv,pBaseInfo->priv.c_str()); _tcscpy_s(info.lang,pBaseInfo->lang.c_str()); _tcscpy_s(info.vercode,pBaseInfo->vercode.c_str()); info.cpufrep = pBaseInfo->cpufrep; info.memsize = pBaseInfo->memsize; info.cpunum = pBaseInfo->cpunum; switch (pBaseInfo->commtype) { case COMMNAME_HTTP: _tcscpy_s(info.proto,_T("HTTP")); break; case COMMNAME_HTTPS: _tcscpy_s(info.proto,_T("HTTPS")); break; case COMMNAME_TCP: _tcscpy_s(info.proto,_T("TCP")); break; case COMMNAME_TCPS: _tcscpy_s(info.proto,_T("TCPS")); break; case COMMNAME_UDP: _tcscpy_s(info.proto,_T("UDP")); break; case COMMNAME_UDPS: _tcscpy_s(info.proto,_T("UDPS")); break; default: break; } FILETIME ftInstallTime = {0}; if (Time2Filetime(pBaseInfo->installTime, &ftInstallTime)) { FILETIME ftLocalInstallTime = {0}; if (FileTimeToLocalFileTime(&ftInstallTime, &ftLocalInstallTime)) { FileTimeToSystemTime(&ftLocalInstallTime, &info.installTime); } } info.localIPCount = min(MAX_LOCALIP_COUNT, pBaseInfo->localIPList.size()); for (USHORT i = 0; i < info.localIPCount; i++) { info.localIPList[i] = ::htonl(inet_addr(t2a(pBaseInfo->localIPList[i].c_str()))); } } else { info.bX64 = FALSE; info.connectIP = 0; info.windowsVersion = WINDOWS_VERSION_NONE; info.localIPCount = 0; } }
BOOL Redirector::StartChildProcess(LPCTSTR lpszCmdLine, BOOL bShowChildWindow) { if (m_bWorking) return TRUE; Handle hProcess = ::GetCurrentProcess(); // Set up the security attributes struct. SECURITY_ATTRIBUTES sa = {0}; sa.nLength= sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; Handle hStdInWriteTmp, hStdOutReadTmp, hStdErrReadTmp; // Create the child stdin pipe. if (! ::CreatePipe(&m_hStdIn, &hStdInWriteTmp, &sa, 0)) return FALSE; // Create the child stdout pipe. if (! ::CreatePipe(&hStdOutReadTmp, &m_hStdOut, &sa, 0)) return FALSE; // Create the child stderr pipe. if (! ::CreatePipe(&hStdErrReadTmp, &m_hStdErr, &sa, 0)) return FALSE; // Create new stdin write, stdout and stderr read handles. // Set the properties to FALSE. Otherwise, the child inherits the // properties and, as a result, non-closeable handles to the pipes // are created. if (! ::DuplicateHandle(hProcess, hStdInWriteTmp, hProcess, &m_hStdInWrite, 0, FALSE, DUPLICATE_SAME_ACCESS)) return FALSE; if (! ::DuplicateHandle(hProcess, hStdOutReadTmp, hProcess, &m_hStdOutRead, 0, FALSE, DUPLICATE_SAME_ACCESS)) return FALSE; if (! ::DuplicateHandle(hProcess, hStdErrReadTmp, hProcess, &m_hStdErrRead, 0, FALSE, DUPLICATE_SAME_ACCESS)) return FALSE; // Close inheritable copies of the handles you do not want to be // inherited. hStdInWriteTmp.Close(); hStdOutReadTmp.Close(); hStdErrReadTmp.Close(); // Start child process with redirected stdout, stdin & stderr BOOL bCreateOK = PrepAndLaunchRedirectedChild(lpszCmdLine, m_hStdOut, m_hStdIn, m_hStdErr, bShowChildWindow, &m_hChildProcess); if (! bCreateOK) { CHAR lpszBuffer[BUFFER_SIZE]; sprintf_s(lpszBuffer, "Unable to start %s", t2a(lpszCmdLine)); OnChildStdOutWrite(lpszBuffer); // close all handles and return FALSE m_hStdIn.Close(); m_hStdOut.Close(); m_hStdErr.Close(); return FALSE; } DWORD dwThreadID; m_bRunThread = TRUE; // Create Exit event m_hExitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL); if (! m_hExitEvent.IsValid()) return FALSE; // Launch the thread that read the child stdout. m_hStdOutThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)staticStdOutThread, (LPVOID)this, 0, &dwThreadID); if (! m_hStdOutThread.IsValid()) return FALSE; // Launch the thread that read the child stderr. m_hStdErrThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)staticStdErrThread, (LPVOID)this, 0, &dwThreadID); if (! m_hStdErrThread.IsValid()) return FALSE; // Launch the thread that monitoring the child process. m_hProcessThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)staticProcessThread, (LPVOID)this, 0, &dwThreadID); if (! m_hProcessThread.IsValid()) return FALSE; // Virtual function to notify derived class that the child is started. OnChildStarted(t2a(lpszCmdLine)); m_bWorking = TRUE; return TRUE; }
static void JabberSearchReturnResults( HANDLE id, void * pvUsersInfo /*LIST<void>* */, U_TCHAR_MAP * pmAllFields /*U_TCHAR_MAP*/ ) { LIST<TCHAR> ListOfNonEmptyFields(20,(LIST<TCHAR>::FTSortFunc)TCharKeyCmp); LIST<TCHAR> ListOfFields(20); LIST<void>* plUsersInfo = ( LIST<void>* )pvUsersInfo; int i, nUsersFound = plUsersInfo->getCount(); // lets fill the ListOfNonEmptyFields but in users order for ( i=0; i < nUsersFound; i++ ) { U_TCHAR_MAP* pmUserData = ( U_TCHAR_MAP* )plUsersInfo->operator [](i); int nUserFields = pmUserData->getCount(); for (int j=0; j < nUserFields; j++) { TCHAR* var = pmUserData->getKeyName(j); if (var && ListOfNonEmptyFields.getIndex(var) < 0) ListOfNonEmptyFields.insert(var); } } // now fill the ListOfFields but order is from pmAllFields int nAllCount = pmAllFields->getCount(); for ( i=0; i < nAllCount; i++ ) { TCHAR * var=pmAllFields->getUnOrderedKeyName(i); if ( var && ListOfNonEmptyFields.getIndex(var) < 0 ) continue; ListOfFields.insert(var); } // now lets transfer field names int nFieldCount = ListOfFields.getCount(); JABBER_CUSTOMSEARCHRESULTS Results={0}; Results.nSize=sizeof(Results); Results.pszFields=(TCHAR**)mir_alloc(sizeof(TCHAR*)*nFieldCount); Results.nFieldCount=nFieldCount; /* Sending Columns Titles */ for ( i=0; i < nFieldCount; i++ ) { TCHAR* var = ListOfFields[i]; if ( var ) Results.pszFields[i] = pmAllFields->operator [](var); } Results.jsr.hdr.cbSize = 0; // sending column names JSendBroadcast( NULL, ACKTYPE_SEARCH, ACKRESULT_SEARCHRESULT, id, (LPARAM) &Results ); /* Sending Users Data */ Results.jsr.hdr.cbSize = sizeof(Results.jsr); // sending user data for ( i=0; i < nUsersFound; i++ ) { Results.jsr.jid[0]=_T('\0'); U_TCHAR_MAP * pmUserData = (U_TCHAR_MAP *) plUsersInfo->operator [](i); for ( int j=0; j < nFieldCount; j++ ) { TCHAR* var = ListOfFields[j]; TCHAR* value = pmUserData->operator [](var); Results.pszFields[j] = value ? value : (TCHAR *)_T(" "); if (!_tcsicmp(var,_T("jid")) && value ) _tcsncpy(Results.jsr.jid, value, SIZEOF(Results.jsr.jid)); } { TCHAR * nickfields[]={ _T("nick"), _T("nickname"), _T("fullname"), _T("name"), _T("given"), _T("first"), _T("jid"), NULL }; TCHAR * nick=NULL; int i=0; while (nickfields[i] && !nick) nick=pmUserData->operator [](nickfields[i++]); TCHAR buff[200]={0}; if (_tcsicmp(nick, Results.jsr.jid)) _sntprintf(buff,SIZEOF(buff),_T("%s ( %s )"),nick, Results.jsr.jid); else _tcsncpy(buff, nick, SIZEOF(buff)); Results.jsr.hdr.nick=nick ? t2a(buff): NULL; } JSendBroadcast( NULL, ACKTYPE_SEARCH, ACKRESULT_SEARCHRESULT, id, (LPARAM) &Results ); if (Results.jsr.hdr.nick) mir_free(Results.jsr.hdr.nick); Results.jsr.hdr.nick=NULL; } mir_free( Results.pszFields ); }