From cb4a46e7fbe62d788e66ed6121c717a2d22a4d7c Mon Sep 17 00:00:00 2001 From: watcherhd Date: Thu, 21 Apr 2011 14:14:52 +0000 Subject: svn.miranda.im is moving to a new home! git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- miranda-wine/protocols/MSN/msn_srv.cpp | 184 +++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 miranda-wine/protocols/MSN/msn_srv.cpp (limited to 'miranda-wine/protocols/MSN/msn_srv.cpp') diff --git a/miranda-wine/protocols/MSN/msn_srv.cpp b/miranda-wine/protocols/MSN/msn_srv.cpp new file mode 100644 index 0000000..80fb64e --- /dev/null +++ b/miranda-wine/protocols/MSN/msn_srv.cpp @@ -0,0 +1,184 @@ +/* +Plugin of Miranda IM for communicating with users of the MSN Messenger protocol. +Copyright (c) 2003-5 George Hazan. +Copyright (c) 2002-3 Richard Hughes (original version). + +Miranda IM: the free icq client for MS Windows +Copyright (C) 2000-2002 Richard Hughes, Roland Rabien & Tristan Van de Vreede + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "msn_global.h" + +struct ServerGroupItem +{ + char* id; + char* name; // in UTF8 + int number; + + ServerGroupItem* next; +}; + +static ServerGroupItem* sttFirst = NULL; + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_AddGroup - adds new server group to the list + +bool MSN_AddGroup( const char* pName, const char* pId ) +{ + ServerGroupItem* p = new ServerGroupItem; + if ( p == NULL ) + return false; + + p->number = -1; + p->id = strdup( pId ); + p->name = strdup( pName ); + p->next = sttFirst; + sttFirst = p; + return true; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_DeleteGroup - deletes a group from the list + +void MSN_DeleteGroup( const char* pId ) +{ + ServerGroupItem* prev = NULL; + + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) { + if ( !strcmp( p->id, pId )) { + if ( prev == NULL ) sttFirst = p->next; + else prev->next = p->next; + free( p->id ); + free( p->name ); + delete p; + return; + } + + prev = p; +} } + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_FreeGroups - clears the server groups list + +void MSN_FreeGroups() +{ + ServerGroupItem* p1; + + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p1 ) { + p1 = p->next; + + free( p->id ); + free( p->name ); + delete p; + } + + sttFirst = NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_GetGroupById - tries to return a group name associated with given UUID + +LPCSTR MSN_GetGroupById( const char* pId ) +{ + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) + if ( stricmp( p->id, pId ) == 0 ) + return p->name; + + return NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_GetGroupByName - tries to return a group UUID associated with the given name + +LPCSTR MSN_GetGroupByName( const char* pName ) +{ + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) + if ( strcmp( p->name, pName ) == 0 ) + return p->id; + + return NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_GetGroupByNumber - tries to return a group UUID associated with the given id + +LPCSTR MSN_GetGroupByNumber( int pNumber ) +{ + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) + if ( p->number == pNumber ) + return p->id; + + return NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_MoveContactToGroup - sends a contact to the specified group + +void MSN_MoveContactToGroup( HANDLE hContact, const char* grpName ) +{ + LPCSTR szId; + char szContactID[ 100 ], szGroupID[ 100 ]; + if ( MSN_GetStaticString( "ID", hContact, szContactID, sizeof szContactID )) + return; + + if ( MSN_GetStaticString( "GroupID", hContact, szGroupID, sizeof szGroupID )) + szGroupID[ 0 ] = 0; + + bool bInsert = szGroupID[0] == 0, bDelete = szGroupID[0] != 0; + + if ( grpName != NULL ) + { + if (( szId = MSN_GetGroupByName( grpName )) == NULL ) { + MSN_AddServerGroup( grpName ); + if (( szId = MSN_GetGroupByName( grpName )) == NULL ) + return; + } + + if ( !strcmp( szGroupID, szId )) bDelete = false; + else bInsert = true; + } + else bInsert = false; + + if ( bInsert ) + msnNsThread->sendPacket( "ADC", "FL C=%s %s", szContactID, szId ); + + if ( bDelete ) + msnNsThread->sendPacket( "REM", "FL %s %s", szContactID, szGroupID ); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_SetGroupName - sets a new name to a server group + +void MSN_SetGroupName( const char* pId, const char* pNewName ) +{ + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) { + if ( strcmp( p->id, pId ) == 0 ) { + free( p->name ); + p->name = strdup( pNewName ); + return; +} } } + +///////////////////////////////////////////////////////////////////////////////////////// +// MSN_SetGroupNumber - associate a server group with Miranda's group number + +void MSN_SetGroupNumber( const char* pId, int pNumber ) +{ + for ( ServerGroupItem* p = sttFirst; p != NULL; p = p->next ) { + if ( strcmp( p->id, pId ) == 0 ) { + p->number = pNumber; + return; +} } } -- cgit v1.2.3