static int lua_EnumProtos(lua_State *L) { ObsoleteMethod(L, "Use \"for x in protos.AllProtos \" instead"); if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); return 1; } lua_pushvalue(L, 1); int ref = luaL_ref(L, LUA_REGISTRYINDEX); int count; PROTOCOLDESCRIPTOR** protos; Proto_EnumProtocols(&count, &protos); for (int i = 0; i < count; i++) { lua_rawgeti(L, LUA_REGISTRYINDEX, ref); MapToTable(L, protos[i]); if (lua_pcall(L, 1, 0, 0)) CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); } luaL_unref(L, LUA_REGISTRYINDEX, ref); lua_pushinteger(L, count); return 1; }
static int lua_AllProtos(lua_State *L) { int count; PROTOCOLDESCRIPTOR** protos; Proto_EnumProtocols(&count, &protos); lua_pushinteger(L, 0); lua_pushinteger(L, count); lua_pushlightuserdata(L, protos); lua_pushcclosure(L, lua_ProtoIterator, 3); return 1; }
static void GetProtocolStrings(CMString& buffer) { PROTOACCOUNT **accList; int accCount; int i, j; Proto_EnumAccounts(&accCount, &accList); int protoCount; PROTOCOLDESCRIPTOR **protoList; Proto_EnumProtocols(&protoCount, &protoList); int protoCountMy = 0; char** protoListMy = (char**)alloca((protoCount + accCount) * sizeof(char*)); for (i = 0; i < protoCount; i++) { if (protoList[i]->type != PROTOTYPE_PROTOCOL) continue; protoListMy[protoCountMy++] = protoList[i]->szName; } for (j = 0; j < accCount; j++) { for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) break; if (i == protoCountMy) protoListMy[protoCountMy++] = accList[j]->szProtoName; } ProtoCount *protos = (ProtoCount*)alloca(sizeof(ProtoCount) * protoCountMy); memset(protos, 0, sizeof(ProtoCount) * protoCountMy); for (j = 0; j < accCount; j++) for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) { protos[i].nloaded = accList[j]->bDynDisabled != 0; if (Proto_IsAccountEnabled(accList[j])) ++protos[i].countse; else ++protos[i].countsd; break; } for (i = 0; i < protoCountMy; i++) buffer.AppendFormat(TEXT("%-24s %d - Enabled %d - Disabled %sLoaded\r\n"), (TCHAR*)_A2T(protoListMy[i]), protos[i].countse, protos[i].countsd, protos[i].nloaded ? _T("Not ") : _T("")); }
void SmileyCategoryListType::AddAllProtocolsAsCategory(void) { CMString displayName = TranslateT("Standard"); CMString tname = _T("Standard"); AddCategory(tname, displayName, smcStd); const CMString &defaultFile = GetSmileyCategory(tname)->GetFilename(); PROTOCOLDESCRIPTOR **proto; int protoCount = 0; Proto_EnumProtocols(&protoCount, &proto); for (int i = 0; i < protoCount; i++) { PROTOCOLDESCRIPTOR *pd = proto[i]; if (pd->type == PROTOTYPE_PROTOCOL && pd->cbSize == sizeof(*pd)) AddProtoAsCategory(pd->szName, defaultFile); } PROTOACCOUNT **accList; Proto_EnumAccounts(&protoCount, &accList); for (int i = 0; i < protoCount; i++) AddAccountAsCategory(accList[i], defaultFile); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) AddContactTransportAsCategory(hContact, defaultFile); CMString cats; opt.ReadCustomCategories(cats); int cppv = 0; for (;;) { int cp = cats.Find('#', cppv); if (cp == -1) break; displayName = cats.Mid(cppv, cp - cppv); AddCategory(displayName, displayName, smcCustom, defaultFile); cppv = cp + 1; } if (cppv != cats.GetLength()) { displayName = cats.Mid(cppv); AddCategory(displayName, displayName, smcCustom, defaultFile); } }
static INT_PTR CALLBACK AccFormDlgProc(HWND hwndDlg,UINT message, WPARAM wParam, LPARAM lParam) { switch( message ) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { PROTOCOLDESCRIPTOR** proto; int protoCount, i, cnt = 0; Proto_EnumProtocols(( WPARAM )&protoCount, ( LPARAM )&proto ); for ( i=0; i < protoCount; i++ ) { PROTOCOLDESCRIPTOR* pd = proto[i]; if ( pd->type == PROTOTYPE_PROTOCOL && pd->cbSize == sizeof( *pd )) { SendDlgItemMessageA( hwndDlg, IDC_PROTOTYPECOMBO, CB_ADDSTRING, 0, (LPARAM)proto[i]->szName ); ++cnt; } } SendDlgItemMessage( hwndDlg, IDC_PROTOTYPECOMBO, CB_SETCURSEL, 0, 0 ); EnableWindow( GetDlgItem( hwndDlg, IDOK ), cnt != 0 ); SetWindowLongPtr( hwndDlg, GWLP_USERDATA, lParam ); AccFormDlgParam* param = ( AccFormDlgParam* )lParam; if ( param->action == PRAC_ADDED ) // new account SetWindowText( hwndDlg, TranslateT( "Create new account" )); else { TCHAR str[200]; if ( param->action == PRAC_CHANGED ) { // update EnableWindow( GetDlgItem( hwndDlg, IDC_PROTOTYPECOMBO ), FALSE ); mir_sntprintf( str, SIZEOF(str), _T("%s: %s"), TranslateT( "Editing account" ), param->pa->tszAccountName ); } else mir_sntprintf( str, SIZEOF(str), _T("%s: %s"), TranslateT( "Upgrading account" ), param->pa->tszAccountName ); SetWindowText( hwndDlg, str ); SetDlgItemText( hwndDlg, IDC_ACCNAME, param->pa->tszAccountName ); SetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, param->pa->szModuleName ); SendDlgItemMessageA( hwndDlg, IDC_PROTOTYPECOMBO, CB_SELECTSTRING, -1, (LPARAM)param->pa->szProtoName ); EnableWindow( GetDlgItem( hwndDlg, IDC_ACCINTERNALNAME ), FALSE ); } SendDlgItemMessage( hwndDlg, IDC_ACCINTERNALNAME, EM_LIMITTEXT, 40, 0 ); } return TRUE; case WM_COMMAND: switch( LOWORD(wParam)) { case IDOK: { AccFormDlgParam* param = ( AccFormDlgParam* )GetWindowLongPtr( hwndDlg, GWLP_USERDATA ); PROTOACCOUNT* pa = param->pa; if ( param->action == PRAC_ADDED ) { char buf[200]; GetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, buf, SIZEOF( buf )); rtrim( buf ); if ( buf[0] ) { for (int i = 0; i < accounts.getCount(); ++i) if (_stricmp(buf, accounts[i]->szModuleName) == 0) return FALSE; } } switch( param->action ) { case PRAC_UPGRADED: { int idx; BOOL oldProto = pa->bOldProto; TCHAR szPlugin[MAX_PATH]; mir_sntprintf(szPlugin, SIZEOF(szPlugin), _T("%s.dll"), StrConvT(pa->szProtoName)); idx = accounts.getIndex(pa); UnloadAccount(pa, false, false); accounts.remove(idx); if (oldProto && UnloadPlugin(szPlugin, SIZEOF(szPlugin))) { TCHAR szNewName[MAX_PATH]; mir_sntprintf(szNewName, SIZEOF(szNewName), _T("%s~"), szPlugin); MoveFile(szPlugin, szNewName); } } // fall through case PRAC_ADDED: pa = (PROTOACCOUNT*)mir_calloc( sizeof( PROTOACCOUNT )); pa->cbSize = sizeof( PROTOACCOUNT ); pa->bIsEnabled = TRUE; pa->bIsVisible = TRUE; pa->iOrder = accounts.getCount(); pa->type = PROTOTYPE_PROTOCOL; break; } { TCHAR buf[256]; GetDlgItemText( hwndDlg, IDC_ACCNAME, buf, SIZEOF( buf )); mir_free(pa->tszAccountName); pa->tszAccountName = mir_tstrdup( buf ); } if ( param->action == PRAC_ADDED || param->action == PRAC_UPGRADED ) { char buf[200]; GetDlgItemTextA( hwndDlg, IDC_PROTOTYPECOMBO, buf, SIZEOF( buf )); pa->szProtoName = mir_strdup( buf ); GetDlgItemTextA( hwndDlg, IDC_ACCINTERNALNAME, buf, SIZEOF( buf )); rtrim( buf ); if ( buf[0] == 0 ) { int count = 1; for( ;; ) { DBVARIANT dbv; mir_snprintf( buf, SIZEOF(buf), "%s_%d", pa->szProtoName, count++ ); if ( DBGetContactSettingString( NULL, buf, "AM_BaseProto", &dbv )) break; DBFreeVariant( &dbv ); } } pa->szModuleName = mir_strdup( buf ); if ( !pa->tszAccountName[0] ) { mir_free(pa->tszAccountName); pa->tszAccountName = mir_a2t(buf); } DBWriteContactSettingString( NULL, pa->szModuleName, "AM_BaseProto", pa->szProtoName ); accounts.insert( pa ); if ( ActivateAccount( pa )) { pa->ppro->OnEvent( EV_PROTO_ONLOAD, 0, 0 ); if (!DBGetContactSettingByte(NULL, "CList", "MoveProtoMenus", FALSE)) pa->ppro->OnEvent( EV_PROTO_ONMENU, 0, 0 ); } else pa->type = PROTOTYPE_DISPROTO; } WriteDbAccounts(); NotifyEventHooks( hAccListChanged, param->action, ( LPARAM )pa ); SendMessage( GetParent(hwndDlg), WM_MY_REFRESH, 0, 0 ); } EndDialog( hwndDlg, TRUE ); break; case IDCANCEL: EndDialog( hwndDlg, FALSE ); break; } } return FALSE; }