summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/IMO2sProxy/src/imo2skype
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/!NotAdopted/IMO2sProxy/src/imo2skype')
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/Makefile19
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.c110
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.h16
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.c204
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.h28
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.c95
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.h32
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.c295
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.h1
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.c1959
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.h13
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.c78
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.h28
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2stest.c60
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/main.c197
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/imoproxy.c882
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/io_layer_netlib.c340
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.apsbin0 -> 20400 bytes
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.rc145
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/resource.h39
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/sdk/m_updater.h146
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.c233
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.h10
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.c158
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.h28
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.c94
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.h17
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.c565
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.h11
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.c1143
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.h5
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.c387
-rw-r--r--plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.h6
33 files changed, 7344 insertions, 0 deletions
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/Makefile b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/Makefile
new file mode 100644
index 0000000000..7e4420f87f
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/Makefile
@@ -0,0 +1,19 @@
+CFLAGS = -O0 -g -I../common/ -I../imolib/ -lcurl -lpthread -lm
+CC = gcc
+COMMON = ../common/fifo.c ../common/cJSON.c ../common/memlist.c
+IMOLIB = ../imolib/imo_request.c ../imolib/imo_skype.c ../imolib/io_layer.c
+IMO2S = buddylist.c queue.c msgqueue.c imo2skypeapi.c callqueue.c socksproxy.c avatarlist.c
+.PHONY: all imo2stest imo2sproxy clean
+
+all : imo2stest imo2sproxy
+
+imo2stest: $(COMMON) $(IMO2S) $(IMOLIB) imo2stest.c
+ $(CC) -o imo2stest $(COMMON) $(IMO2S) $(IMOLIB) imo2stest.c $(CFLAGS)
+ strip imo2stest
+
+imo2sproxy: $(COMMON) $(IMO2S) $(IMOLIB) imo2sproxy.c main.c
+ $(CC) -o imo2sproxy $(COMMON) $(IMO2S) $(IMOLIB) imo2sproxy.c main.c $(CFLAGS)
+# strip imo2sproxy
+
+clean :
+ rm imo2stest imo2sproxy
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.c
new file mode 100644
index 0000000000..f1c78f0567
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.c
@@ -0,0 +1,110 @@
+/* Module: avatarlist.c
+ Purpose: Manages the avatars of your buddies
+ Author: leecher
+ Date: 18.08.2011
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "memlist.h"
+#include "avatarlist.h"
+
+static void SetEntry(AVATARENTRY *pEntry, cJSON *pNick);
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+TYP_LIST *AvatarList_Init(void)
+{
+ TYP_LIST *hList = List_Init(16);
+
+ return hList;
+}
+
+// -----------------------------------------------------------------------------
+
+void AvatarList_Exit(TYP_LIST *hList)
+{
+ AVATARENTRY *pEntry;
+
+ while (pEntry=(AVATARENTRY*)List_Pop(hList))
+ {
+ AvatarList_FreeEntry(pEntry);
+ free (pEntry);
+ }
+ List_Exit(hList);
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL AvatarList_Insert(TYP_LIST *hList, cJSON *pIcon)
+{
+ AVATARENTRY *pEntry;
+
+ if (pEntry=AvatarList_Find (hList, cJSON_GetObjectItem(pIcon, "buid")->valuestring))
+ AvatarList_FreeEntry (pEntry);
+ else
+ {
+ if (!(pEntry = calloc (1, sizeof(AVATARENTRY)))) return FALSE;
+ if (!List_Push(hList, pEntry)) return FALSE;
+ }
+ SetEntry(pEntry, pIcon);
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL AvatarList_Remove(TYP_LIST *hList, AVATARENTRY *pEntry)
+{
+ AVATARENTRY *pListEntry;
+ int i, nCount;
+
+ for (i=0, nCount=List_Count(hList); i<nCount; i++)
+ {
+ pListEntry = List_ElementAt (hList, i);
+ if (pListEntry == pEntry) break;
+ }
+ if (i<nCount)
+ {
+ AvatarList_FreeEntry (pEntry);
+ List_RemoveElementAt(hList, i);
+ free (pEntry);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+AVATARENTRY *AvatarList_Find(TYP_LIST *hList, char *pszUser)
+{
+ int i, nCount;
+ AVATARENTRY *pEntry;
+
+ for (i=0, nCount=List_Count(hList); i<nCount; i++)
+ {
+ pEntry = List_ElementAt (hList, i);
+ if (strcmp(pEntry->pszUser, pszUser) == 0)
+ return pEntry;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+void AvatarList_FreeEntry(AVATARENTRY *pEntry)
+{
+ if (pEntry->pszUser) free (pEntry->pszUser);
+ if (pEntry->pszIcon) free (pEntry->pszIcon);
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+static void SetEntry(AVATARENTRY *pEntry, cJSON *pNick)
+{
+ pEntry->pszUser = strdup(cJSON_GetObjectItem(pNick, "buid")->valuestring);
+ pEntry->pszIcon = strdup(cJSON_GetObjectItem(pNick, "icon")->valuestring);
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.h
new file mode 100644
index 0000000000..6a47ed2fa5
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/avatarlist.h
@@ -0,0 +1,16 @@
+#include "cJSON.h"
+#include "memlist.h"
+
+typedef struct
+{
+ char *pszUser;
+ char *pszIcon;
+} AVATARENTRY;
+
+TYP_LIST *AvatarList_Init(void);
+void AvatarList_Exit(TYP_LIST *hList);
+
+BOOL AvatarList_Insert(TYP_LIST *hList, cJSON *pIcon);
+BOOL AvatarList_Remove(TYP_LIST *hList, AVATARENTRY *pEntry);
+AVATARENTRY *AvatarList_Find(TYP_LIST *hList, char *pszUser);
+void AvatarList_FreeEntry(AVATARENTRY *pEntry);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.c
new file mode 100644
index 0000000000..6d228ae4b9
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.c
@@ -0,0 +1,204 @@
+/* Module: buddylist.c
+ Purpose: Manages your list of buddies in memory
+ Author: leecher
+ Date: 30.08.2009
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "memlist.h"
+#include "buddylist.h"
+
+static void SetEntry(NICKENTRY *pEntry, cJSON *pNick);
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+TYP_LIST *BuddyList_Init(void)
+{
+ TYP_LIST *hList = List_Init(16);
+
+ return hList;
+}
+
+// -----------------------------------------------------------------------------
+
+void BuddyList_Exit(TYP_LIST *hList)
+{
+ NICKENTRY *pEntry;
+
+ while (pEntry=(NICKENTRY*)List_Pop(hList))
+ {
+ BuddyList_FreeEntry(pEntry, TRUE);
+ free (pEntry);
+ }
+ List_Exit(hList);
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL BuddyList_Insert(TYP_LIST *hList, cJSON *pNick)
+{
+ NICKENTRY *pEntry;
+ cJSON *pElem;
+
+ if (pEntry=BuddyList_Find (hList, cJSON_GetObjectItem(pNick, "buid")->valuestring))
+ BuddyList_FreeEntry (pEntry, FALSE);
+ else
+ {
+ if (!(pEntry = calloc (1, sizeof(NICKENTRY)))) return FALSE;
+ if ((pElem=cJSON_GetObjectItem(pNick, "group")) && strcmp(pElem->valuestring, "Skype"))
+ {
+ char szBUID[256];
+ NICKENTRY *pGroup;
+
+ // Buddy Belongs to a chatgroup
+ sprintf (szBUID, "%s;", pElem->valuestring);
+ pGroup = BuddyList_Find (hList, szBUID);
+
+ if (pGroup) // Group not yet created? Shouldn't be the case
+ {
+ if (!pGroup->hGCMembers) pGroup->hGCMembers=List_Init(1);
+ hList = pGroup->hGCMembers;
+ pEntry->pGroup = pGroup;
+ }
+ }
+ if (!List_Push(hList, pEntry)) return FALSE;
+ }
+ SetEntry(pEntry, pNick);
+ pEntry->iBuddyStatus = 3;
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL BuddyList_AddTemporaryUser(TYP_LIST *hList, char *pszUser)
+{
+ NICKENTRY *pEntry;
+
+ if (BuddyList_Find (hList, pszUser)) return TRUE;
+ if (!(pEntry = calloc (1, sizeof(NICKENTRY)))) return FALSE;
+ pEntry->pszUser = strdup(pszUser);
+ pEntry->pszAlias = strdup(pszUser);
+ strcpy (pEntry->szStatus, "OFFLINE");
+ pEntry->iBuddyStatus = 2;
+ return List_Push(hList, pEntry);
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL BuddyList_Remove(TYP_LIST *hList, NICKENTRY *pEntry)
+{
+ NICKENTRY *pListEntry;
+ int i, nCount;
+
+ if (pEntry->pGroup) hList=pEntry->pGroup->hGCMembers;
+ for (i=0, nCount=List_Count(hList); i<nCount; i++)
+ {
+ pListEntry = List_ElementAt (hList, i);
+ if (pListEntry == pEntry) break;
+ }
+ if (i<nCount)
+ {
+ BuddyList_FreeEntry (pEntry, TRUE);
+ List_RemoveElementAt(hList, i);
+ free (pEntry);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+NICKENTRY *BuddyList_Find(TYP_LIST *hList, char *pszUser)
+{
+ int i, nCount;
+ NICKENTRY *pEntry;
+
+ for (i=0, nCount=List_Count(hList); i<nCount; i++)
+ {
+ pEntry = List_ElementAt (hList, i);
+ if (strcmp(pEntry->pszUser, pszUser) == 0)
+ return pEntry;
+ else if (pEntry->hGCMembers)
+ {
+ if (pEntry = BuddyList_Find(pEntry->hGCMembers, pszUser))
+ return pEntry;
+ }
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL BuddyList_SetStatus(TYP_LIST *hList, cJSON *pNick)
+{
+ NICKENTRY *pEntry;
+
+ if ((pEntry = BuddyList_Find(hList, cJSON_GetObjectItem(pNick, "buid")->valuestring)))
+ {
+ BuddyList_FreeEntry(pEntry, FALSE);
+ SetEntry(pEntry, pNick);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+void BuddyList_FreeEntry(NICKENTRY *pEntry, BOOL bFreeGC)
+{
+ if (pEntry->pszAlias)
+ {
+ free (pEntry->pszAlias);
+ pEntry->pszAlias = NULL;
+ }
+ if (pEntry->pszUser)
+ {
+ free (pEntry->pszUser);
+ pEntry->pszUser = NULL;
+ }
+ if (pEntry->pszStatusText)
+ {
+ free(pEntry->pszStatusText);
+ pEntry->pszStatusText = NULL;
+ }
+ if (pEntry->pszDisplay)
+ {
+ free(pEntry->pszDisplay);
+ pEntry->pszDisplay = NULL;
+ }
+ if (bFreeGC && pEntry->hGCMembers)
+ {
+ NICKENTRY *pNick;
+
+ while (pNick=(NICKENTRY*)List_Pop(pEntry->hGCMembers))
+ {
+ BuddyList_FreeEntry(pNick, bFreeGC);
+ free (pNick);
+ }
+ List_Exit (pEntry->hGCMembers);
+ pEntry->hGCMembers = NULL;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+static void SetEntry(NICKENTRY *pEntry, cJSON *pNick)
+{
+ cJSON *obj;
+
+ if ((obj=cJSON_GetObjectItem(pNick, "alias")) && obj->valuestring)
+ pEntry->pszAlias = strdup(obj->valuestring);
+ pEntry->pszUser = strdup(cJSON_GetObjectItem(pNick, "buid")->valuestring);
+ if ((obj=cJSON_GetObjectItem(pNick, "status")) && obj->valuestring)
+ pEntry->pszStatusText = strdup(obj->valuestring);
+ if ((obj=cJSON_GetObjectItem(pNick, "primitive")) && obj->valuestring)
+ strcpy (pEntry->szStatus, obj->valuestring);
+ if ((obj=cJSON_GetObjectItem(pNick, "display")) && obj->valuestring)
+ pEntry->pszDisplay = strdup(obj->valuestring);
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.h
new file mode 100644
index 0000000000..3774ef3e5e
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/buddylist.h
@@ -0,0 +1,28 @@
+#include "cJSON.h"
+#include "memlist.h"
+
+struct tag_nickentry;
+typedef struct tag_nickentry NICKENTRY;
+
+struct tag_nickentry
+{
+ char *pszUser;
+ char *pszStatusText;
+ char szStatus[16];
+ char *pszAlias;
+ char *pszDisplay; // Display name, on Groupchat it is topic
+ int iBuddyStatus;
+ TYP_LIST *hGCMembers; // List of groupchat members, if this is a groupchat
+ NICKENTRY *pGroup; // Uplink to Chatgroup, if Groupchat-Member
+};
+
+TYP_LIST *BuddyList_Init(void);
+void BuddyList_Exit(TYP_LIST *hList);
+
+BOOL BuddyList_Insert(TYP_LIST *hList, cJSON *pNick);
+BOOL BuddyList_AddTemporaryUser(TYP_LIST *hList, char *pszUser);
+BOOL BuddyList_Remove(TYP_LIST *hList, NICKENTRY *pEntry);
+NICKENTRY *BuddyList_Find(TYP_LIST *hList, char *pszUser);
+BOOL BuddyList_SetStatus(TYP_LIST *hList, cJSON *pNick);
+void BuddyList_FreeEntry(NICKENTRY *pEntry, BOOL bFreeGC);
+#define BuddyList_IsGroupchat(pEntry) (pEntry->hGCMembers!=NULL)
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.c
new file mode 100644
index 0000000000..f579eb184e
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.c
@@ -0,0 +1,95 @@
+/* Module: callqueue.c
+ Purpose: Queue for incoming calls
+ Author: leecher
+ Date: 02.09.2009
+
+ Fixme: Sort on insert, do a binary search instead of iterating list.
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "callqueue.h"
+
+static volatile unsigned int m_uMsgNr=0;
+static void FreeEntry(void *pPEntry);
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+TYP_LIST *CallQueue_Init(void)
+{
+ TYP_LIST *hList = List_Init(16);
+
+ return hList;
+}
+
+// -----------------------------------------------------------------------------
+
+void CallQueue_Exit(TYP_LIST *hList)
+{
+ Queue_Exit (hList, FreeEntry);
+}
+
+// -----------------------------------------------------------------------------
+
+CALLENTRY *CallQueue_Insert(TYP_LIST *hList, cJSON *pNick, int iDirection)
+{
+ CALLENTRY *pEntry;
+ cJSON *pStream, *pVal, *pPipe;
+
+ if (!(pEntry = Queue_InsertEntry(hList, sizeof(CALLENTRY), ++m_uMsgNr,
+ FreeEntry))) return NULL;
+ pEntry->pszUser = strdup(cJSON_GetObjectItem(pNick, "buid")->valuestring);
+ time (&pEntry->timestamp);
+ strcpy (pEntry->szStatus, "RINGING");
+
+ if (pStream = cJSON_GetObjectItem(pNick, "send_stream"))
+ {
+ strcpy (pEntry->szSendStream, pStream->valuestring);
+ if (pStream = cJSON_GetObjectItem(pNick, "recv_stream"))
+ strcpy (pEntry->szRecvStream, pStream->valuestring);
+ }
+ else
+ {
+ // Copy pipe to Call object
+ if (pPipe = cJSON_GetObjectItem(pNick, "pipe"))
+ {
+ if (pVal = cJSON_GetObjectItem(pPipe, "ip"))
+ strncpy (pEntry->szIP, pVal->valuestring, sizeof(pEntry->szIP));
+ if (pVal = cJSON_GetObjectItem(pPipe, "conv"))
+ strncpy (pEntry->szConv, pVal->valuestring, sizeof(pEntry->szConv));
+ if (pVal = cJSON_GetObjectItem(pPipe, "role"))
+ pEntry->iRole = pVal->valueint;
+ }
+ }
+ pEntry->iDirection = iDirection;
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL CallQueue_Remove(TYP_LIST *hList, unsigned int uMsgNr)
+{
+ return Queue_Remove (hList, uMsgNr, FreeEntry);
+}
+
+// -----------------------------------------------------------------------------
+
+CALLENTRY *CallQueue_Find(TYP_LIST *hList, unsigned int uMsgNr)
+{
+ return (CALLENTRY*)Queue_Find(hList, uMsgNr);
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+static void FreeEntry(void *pPEntry)
+{
+ CALLENTRY *pEntry = (CALLENTRY*)pPEntry;
+
+ free (pEntry->pszUser);
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.h
new file mode 100644
index 0000000000..0c4fcfd2cf
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/callqueue.h
@@ -0,0 +1,32 @@
+#include "cJSON.h"
+#include "queue.h"
+#include <time.h>
+
+#define CALL_INCOMING 0
+#define CALL_OUTGOING 1
+
+typedef struct
+{
+ QUEUEHDR hdr;
+ char *pszUser;
+ char szStatus[16];
+
+ char szSendStream[18];
+ char szRecvStream[18];
+
+ char szConv[18];
+ char szIP[16];
+ int iRole;
+
+ char szCallFile[256];
+ void *hCallWnd;
+ int iDirection;
+ time_t timestamp;
+} CALLENTRY;
+
+TYP_LIST *CallQueue_Init(void);
+void CallQueue_Exit(TYP_LIST *hList);
+
+CALLENTRY *CallQueue_Insert(TYP_LIST *hList, cJSON *pNick, int iDirection);
+BOOL CallQueue_Remove(TYP_LIST *hList, unsigned int uCallNr);
+CALLENTRY *CallQueue_Find(TYP_LIST *hList, unsigned int uCallNr);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.c
new file mode 100644
index 0000000000..91ad90032e
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.c
@@ -0,0 +1,295 @@
+#include <imagehlp.h>
+#include <malloc.h>
+#pragma comment (lib, "imagehlp.lib")
+
+#define MAXNAMELEN 1024
+#define HEXDUMP_BREAK 16
+
+void HexDump(char *pszOutput, PBYTE pData, int cbLength, BOOL bShow)
+{
+ char *pszLastLine;
+ int i;
+
+ *pszOutput=0;
+ pszLastLine = pszOutput;
+ for (i=0; i<cbLength; i++)
+ {
+ if (i%HEXDUMP_BREAK == 0)
+ {
+ if (i>=HEXDUMP_BREAK)
+ {
+ int j;
+
+ strcat (pszOutput, " ");
+ for (j=i-HEXDUMP_BREAK; j<i; j++) sprintf (pszOutput+strlen(pszOutput), "%c", pData[j]);
+ }
+ sprintf (pszOutput+strlen(pszOutput), "\r\n");
+ if (bShow) LOG (("\t%s", pszLastLine));
+ if (i==0) *pszOutput=0;
+ pszLastLine = pszOutput+strlen(pszOutput);
+ }
+ sprintf (pszOutput+strlen(pszOutput), "%02X ", pData[i]);
+ if (i == cbLength-1)
+ {
+ int j;
+
+ for (j=0; j<HEXDUMP_BREAK - i%HEXDUMP_BREAK - 1; j++) sprintf (pszOutput+strlen(pszOutput), " ");
+ sprintf (pszOutput+strlen(pszOutput), " ");
+ for (j=i-i%HEXDUMP_BREAK; j<i; j++) sprintf (pszOutput+strlen(pszOutput), "%c",
+ (isprint(pData[j]) && pData[j]!=0x0D && pData[j]!=0x0A && pData[j]!=0x09)?pData[j]:'.');
+ if (bShow) LOG (("\t%s", pszLastLine));
+ }
+ }
+}
+
+
+void CrashDumpMem (DWORD dwBase, char *pszName, DWORD dwDwords)
+{
+ int cbLength = sizeof(DWORD) * dwDwords;
+ PBYTE mem = (PBYTE)alloca (cbLength*2);
+ SYSTEM_INFO sysInfo;
+ SIZE_T read=0;
+
+ dwBase &= ~3;
+
+ dwBase-=cbLength; cbLength*=2;
+ GetSystemInfo(&sysInfo);
+ if (dwBase < (DWORD)sysInfo.lpMinimumApplicationAddress || dwBase > (DWORD)sysInfo.lpMaximumApplicationAddress)
+ return;
+
+ if (ReadProcessMemory (GetCurrentProcess(), (PVOID)dwBase, mem, cbLength, &read))
+ {
+ char *pszHexdump = (char *)alloca (((cbLength/HEXDUMP_BREAK)+1)*81);
+
+ LOG (("Memory dump for %s:\n", pszName));
+ HexDump (pszHexdump, mem, read, TRUE);
+ LOG (("\n"));
+ }
+}
+
+
+BOOL ShowThreadStack (HANDLE hThread, CONTEXT *c)
+{
+ STACKFRAME stFrame={0};
+ DWORD dwSymOptions, dwFrameNum=0, dwMachine, dwOffsetFromSym=0;
+ IMAGEHLP_LINE Line={0};
+ IMAGEHLP_MODULE Module={0};
+ HANDLE hProcess = GetCurrentProcess();
+ BYTE pbSym[sizeof(IMAGEHLP_SYMBOL) + MAXNAMELEN];
+ IMAGEHLP_SYMBOL *pSym = (IMAGEHLP_SYMBOL *)&pbSym;
+ char szUndecName[MAXNAMELEN], szUndecFullName[MAXNAMELEN];
+
+ /*
+ if ( ! GetThreadContext( hThread, &c ) )
+ {
+ SetError (NULL, NULL, 0);
+ LOG (("Cannot get thread context%d\n", GetLastError()));
+ return FALSE;
+ }
+ */
+ LOG (("Please wait...\n"));
+ if (!SymInitialize (hProcess, NULL, TRUE))
+ {
+ LOG (("Cannot initialize symbol engine (%08X)\n", GetLastError()));
+ return FALSE;
+ }
+
+ dwSymOptions = SymGetOptions();
+ dwSymOptions |= SYMOPT_LOAD_LINES;
+ dwSymOptions &= ~SYMOPT_UNDNAME;
+ SymSetOptions (dwSymOptions);
+
+ stFrame.AddrPC.Mode = AddrModeFlat;
+ dwMachine = IMAGE_FILE_MACHINE_I386;
+ stFrame.AddrPC.Offset = c->Eip;
+ stFrame.AddrStack.Offset = c->Esp;
+ stFrame.AddrStack.Mode = AddrModeFlat;
+ stFrame.AddrFrame.Offset = c->Ebp;
+ stFrame.AddrFrame.Mode = AddrModeFlat;
+
+ Module.SizeOfStruct = sizeof(Module);
+ Line.SizeOfStruct = sizeof(Module);
+
+ LOG (("\n--# FV EIP----- RetAddr- FramePtr StackPtr Symbol\n"));
+ do
+ {
+ if (!StackWalk (dwMachine, hProcess, hThread, &stFrame, &c, NULL, &SymFunctionTableAccess, &SymGetModuleBase, NULL))
+ break;
+
+ LOG (( "\n%3d %c%c %08lx %08lx %08lx %08lx ",
+ dwFrameNum, stFrame.Far? 'F': '.', stFrame.Virtual? 'V': '.',
+ stFrame.AddrPC.Offset, stFrame.AddrReturn.Offset,
+ stFrame.AddrFrame.Offset, stFrame.AddrStack.Offset ));
+
+ if (stFrame.AddrPC.Offset == 0)
+ {
+ LOG (( "(-nosymbols-)\n" ));
+ }
+ else
+ { // we seem to have a valid PC
+ if (!SymGetSymFromAddr (hProcess, stFrame.AddrPC.Offset, &dwOffsetFromSym, pSym))
+ {
+ if (GetLastError() != 487)
+ {
+ LOG (("Unable to get symbol from addr (%08X)", GetLastError()));
+ }
+ }
+ else
+ {
+ UnDecorateSymbolName (pSym->Name, szUndecName, MAXNAMELEN, UNDNAME_NAME_ONLY );
+ UnDecorateSymbolName (pSym->Name, szUndecFullName, MAXNAMELEN, UNDNAME_COMPLETE );
+ LOG (("%s", szUndecName));
+ if (dwOffsetFromSym) LOG ((" %+ld bytes", (long)dwOffsetFromSym));
+ LOG (("\n Sig: %s\n Decl: %s\n", pSym->Name, szUndecFullName));
+ }
+
+ if (!SymGetLineFromAddr (hProcess, stFrame.AddrPC.Offset, &dwOffsetFromSym, &Line))
+ {
+ if (GetLastError() != 487)
+ {
+ LOG (("Unable to get line from addr (%08X)", GetLastError()));
+ }
+ }
+ else
+ {
+ LOG ((" Line: %s(%lu) %+ld bytes\n", Line.FileName, Line.LineNumber, dwOffsetFromSym ));
+ }
+
+ if (!SymGetModuleInfo (hProcess, stFrame.AddrPC.Offset, &Module))
+ {
+ if (GetLastError() != 487)
+ {
+ LOG (("Unable to get module info (%08X)", GetLastError()));
+ }
+ }
+ else
+ {
+ char ty[80];
+
+ switch ( Module.SymType )
+ {
+ case SymNone:
+ strcpy( ty, "-nosymbols-" );
+ break;
+ case SymCoff:
+ strcpy( ty, "COFF" );
+ break;
+ case SymCv:
+ strcpy( ty, "CV" );
+ break;
+ case SymPdb:
+ strcpy( ty, "PDB" );
+ break;
+ case SymExport:
+ strcpy( ty, "-exported-" );
+ break;
+ case SymDeferred:
+ strcpy( ty, "-deferred-" );
+ break;
+ case SymSym:
+ strcpy( ty, "SYM" );
+ break;
+ default:
+ _snprintf( ty, sizeof ty, "symtype=%ld", (long) Module.SymType );
+ break;
+
+ }
+ LOG (( " Mod: %s[%s], base: %08lxh\n", Module.ModuleName, Module.ImageName, Module.BaseOfImage ));
+ LOG (( " Sym: type: %s, file: %s\n", ty, Module.LoadedImageName));
+ }
+ }
+ dwFrameNum++;
+ } while (stFrame.AddrReturn.Offset);
+ SymCleanup (hProcess);
+ return TRUE;
+}
+
+
+LONG Win32FaultHandler(struct _EXCEPTION_POINTERS * ExInfo)
+{
+ char *FaultTx;
+ int wsFault = ExInfo->ExceptionRecord->ExceptionCode;
+ PVOID CodeAdress = ExInfo->ExceptionRecord->ExceptionAddress;
+#ifndef USE_GUI
+ char choice[10];
+#endif
+
+ if (//IsDebuggerPresent() ||
+ ExInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
+ return EXCEPTION_CONTINUE_SEARCH;
+
+ switch(ExInfo->ExceptionRecord->ExceptionCode)
+ {
+ case EXCEPTION_ACCESS_VIOLATION : FaultTx = "ACCESS VIOLATION"; break;
+ case EXCEPTION_DATATYPE_MISALIGNMENT : FaultTx = "DATATYPE MISALIGNMENT"; break;
+ case EXCEPTION_FLT_DIVIDE_BY_ZERO : FaultTx = "FLT DIVIDE BY ZERO"; break;
+ case EXCEPTION_ARRAY_BOUNDS_EXCEEDED : FaultTx = "ARRAY BOUNDS EXCEEDED"; break;
+ case EXCEPTION_FLT_DENORMAL_OPERAND : FaultTx = "FLT DENORMAL OPERAND"; break;
+ case EXCEPTION_FLT_INEXACT_RESULT : FaultTx = "FLT INEXACT RESULT"; break;
+ case EXCEPTION_FLT_INVALID_OPERATION : FaultTx = "FLT INVALID OPERATION"; break;
+ case EXCEPTION_FLT_OVERFLOW : FaultTx = "FLT OVERFLOW"; break;
+ case EXCEPTION_FLT_STACK_CHECK : FaultTx = "FLT STACK CHECK"; break;
+ case EXCEPTION_FLT_UNDERFLOW : FaultTx = "FLT UNDERFLOW"; break;
+ case EXCEPTION_ILLEGAL_INSTRUCTION : FaultTx = "ILLEGAL INSTRUCTION"; break;
+ case EXCEPTION_IN_PAGE_ERROR : FaultTx = "IN PAGE ERROR"; break;
+ case EXCEPTION_INT_DIVIDE_BY_ZERO : FaultTx = "INT DEVIDE BY ZERO"; break;
+ case EXCEPTION_INT_OVERFLOW : FaultTx = "INT OVERFLOW"; break;
+ case EXCEPTION_INVALID_DISPOSITION : FaultTx = "INVALID DISPOSITION"; break;
+ case EXCEPTION_NONCONTINUABLE_EXCEPTION:FaultTx= "NONCONTINUABLE EXCEPTION"; break;
+ case EXCEPTION_PRIV_INSTRUCTION : FaultTx = "PRIVILEGED INSTRUCTION";break;
+ case EXCEPTION_SINGLE_STEP : FaultTx = "SINGLE STEP"; break;
+ case EXCEPTION_STACK_OVERFLOW : FaultTx = "STACK OVERFLOW"; break;
+ case DBG_CONTROL_C : return EXCEPTION_EXECUTE_HANDLER;
+ default : FaultTx = "(unknown)"; break;
+ }
+
+ LOG (("****************************************************\n"));
+ LOG (("*** A Program Fault occurred: ***\n"));
+ LOG (("*** Error code %08X: %-24s***\n", wsFault, FaultTx));
+ LOG (("****************************************************\n"));
+ LOG (("*** Address: %08X Flags: %08X ***\n", (int)CodeAdress, ExInfo->ExceptionRecord->ExceptionFlags));
+ LOG (("*** EAX=%08X EBX=%08X ECX=%08X ***\n", ExInfo->ContextRecord->Eax, ExInfo->ContextRecord->Ebx, ExInfo->ContextRecord->Ecx));
+ LOG (("*** EDX=%08X EBP=%08X ESI=%08X ***\n", ExInfo->ContextRecord->Edx, ExInfo->ContextRecord->Ebp, ExInfo->ContextRecord->Esi));
+ LOG (("*** EDI=%08X ESP=%08X EIP=%08X ***\n", ExInfo->ContextRecord->Edi, ExInfo->ContextRecord->Esp, ExInfo->ContextRecord->Eip));
+ LOG (("****************************************************\n"));
+ CrashDumpMem (ExInfo->ContextRecord->Eax, "EAX", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Ebx, "EBX", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Ecx, "ECX", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Edx, "EDX", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Esi, "ESI", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Edi, "EDI", 8);
+ CrashDumpMem (ExInfo->ContextRecord->Esp, "ESP", 32);
+ CrashDumpMem (ExInfo->ContextRecord->Ebp, "EBP", 32);
+ {
+ OSVERSIONINFO ov={0};
+
+ ov.dwOSVersionInfoSize=sizeof(ov);
+ GetVersionEx (&ov);
+ LOG (("Target platform: Microsoft Windows NT %d.%d Build %d %s\n", ov.dwMajorVersion, ov.dwMinorVersion,
+ ov.dwBuildNumber, ov.szCSDVersion));
+ }
+
+ //LogStackFrames(CodeAddress, (char *)ExInfo->ContextRecord->Ebp);
+ ShowThreadStack (GetCurrentThread(), ExInfo->ContextRecord);
+
+#ifdef USE_GUI
+ if (MessageBox(NULL, "A Program Fault occurred. Do you want to continue execution (not recommended)?", "CRASH!", MB_ICONERROR | MB_YESNO) == IDYES)
+#else
+ printf ("Do you want to continue program execution (not recommended) [y/N]? ");
+ fgets(choice, sizeof(choice) - 1, stdin);
+
+ if (*choice=='y' || *choice=='Y')
+#endif
+ {
+ ExInfo->ContextRecord->Eip++;
+ return EXCEPTION_CONTINUE_EXECUTION;
+ }
+ return EXCEPTION_EXECUTE_HANDLER;
+}
+
+void Crash_Init(void)
+{
+//#ifndef _DEBUG
+ SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) Win32FaultHandler);
+//#endif
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.h
new file mode 100644
index 0000000000..7f2d790f6c
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/crash.h
@@ -0,0 +1 @@
+void Crash_Init(void);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.c
new file mode 100644
index 0000000000..de0a9b4028
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.c
@@ -0,0 +1,1959 @@
+/* Module: imo2skypeapi.c
+ Purpose: Simple wrapper for imo.im Webservice to SKYPE API to maintain compatibility with Skype-Plugins
+ Author: leecher
+ Date: 30.08.2009
+*/
+
+#define VOICECALL_VERSION 1221873445
+#define IVC_VERSION "98a29c15e305a7af04634b03d5e1425d6c67806e"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <time.h>
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+#include <direct.h>
+#include "w32browser.h"
+#define strcasecmp stricmp
+#define strncasecmp strnicmp
+#define thread_t HANDLE
+#define vsnprintf _vsnprintf
+#define GWL_PINST 0
+#define GWL_ORIGWPRC 1*sizeof(PVOID)
+#else
+#define thread_t pthread_t
+#include <unistd.h>
+#include <pthread.h>
+#endif
+#include "imo_skype.h"
+#include "imo_request.h"
+#include "fifo.h"
+#include "memlist.h"
+#include "buddylist.h"
+#include "avatarlist.h"
+#include "msgqueue.h"
+#include "callqueue.h"
+#include "imo2skypeapi.h"
+
+typedef struct
+{
+ char *pszImoStat;
+ char *pszSkypeStat;
+} STATMAP;
+
+struct _tagIMOSAPI
+{
+ IMOSKYPE *hInst;
+ NICKENTRY myUser;
+ char *pszPass;
+ char *pszLogBuf;
+ char *pszClientName;
+ int cbBuf;
+ TYP_LIST *hBuddyList;
+ TYP_LIST *hAvatarList;
+ TYP_LIST *hMsgQueue;
+ TYP_LIST *hCallQueue;
+ int iProtocol;
+ int iLoginStat;
+ IMO2SCB Callback;
+ void *pUser;
+ FILE *fpLog;
+ thread_t hThread;
+ int bFriendsPending;
+ int iFlags;
+ int iShuttingDown;
+ volatile time_t tSetMoodText;
+ char *pszCmdID;
+ char *pszBuddiesToAdd;
+};
+
+static STATMAP m_stMap[] =
+{
+ {"available", "ONLINE"},
+ {"available", "SKYPEME"},
+ {"offline", "OFFLINE"},
+ {"away", "AWAY"},
+ {"busy", "DND"},
+ {"busy", "NA"},
+ {"invisible", "INVISIBLE"}
+};
+
+static int StartCallSWF (IMOSAPI *pInst, CALLENTRY *pCall);
+static int StatusCallback (cJSON *pMsg, void *pUser);
+static void DispatcherThread(void *pUser);
+static int Dispatcher_Start(IMOSAPI *pInst);
+static int Dispatcher_Stop(IMOSAPI *pInst);
+static void Send(IMOSAPI *pInst, const char *pszMsg, ...);
+static void HandleMessage(IMOSAPI *pInst, char *pszMsg);
+
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+IMOSAPI *Imo2S_Init(IMO2SCB Callback, void *pUser, int iFlags)
+{
+ IMOSAPI *pInst = calloc(1, sizeof(IMOSAPI));
+
+ if (!pInst) return NULL;
+ if (!(pInst->pszLogBuf = malloc(pInst->cbBuf=512)) ||
+ !(pInst->hInst = ImoSkype_Init(StatusCallback, pInst)) ||
+ !(pInst->hBuddyList = BuddyList_Init()) ||
+ !(pInst->hAvatarList = AvatarList_Init()) ||
+ !(pInst->hMsgQueue = MsgQueue_Init()) ||
+#ifdef WIN32
+ ((iFlags & IMO2S_FLAG_ALLOWINTERACT) && W32Browser_Init(0)==-1) ||
+#endif
+ !(pInst->hCallQueue = CallQueue_Init()))
+ {
+ Imo2S_Exit(pInst);
+ return NULL;
+ }
+ pInst->Callback = Callback;
+ pInst->pUser = pUser;
+ pInst->iFlags = iFlags;
+ pInst->myUser.iBuddyStatus = 3;
+ strcpy (pInst->myUser.szStatus, "OFFLINE");
+ pInst->iProtocol = 3;
+ return pInst;
+}
+
+// -----------------------------------------------------------------------------
+
+void Imo2S_SetLog (IMOSAPI *pInst, FILE *fpLog)
+{
+ pInst->fpLog = fpLog;
+}
+
+// -----------------------------------------------------------------------------
+
+void Imo2S_Exit (IMOSAPI *pInst)
+{
+ if (!pInst) return;
+ pInst->iShuttingDown = 1;
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S_Exit()\n");
+ if (pInst->iLoginStat == 1) Imo2S_Logout(pInst);
+ if (pInst->hInst) ImoSkype_Exit(pInst->hInst);
+ if (pInst->hBuddyList) BuddyList_Exit(pInst->hBuddyList);
+ if (pInst->hAvatarList) AvatarList_Exit(pInst->hAvatarList);
+ if (pInst->hMsgQueue) MsgQueue_Exit(pInst->hMsgQueue);
+ if (pInst->hCallQueue) CallQueue_Exit(pInst->hCallQueue);
+ if (pInst->pszPass) free (pInst->pszPass);
+ if (pInst->pszLogBuf) free(pInst->pszLogBuf);
+ if (pInst->pszClientName) free(pInst->pszClientName);
+#ifdef WIN32
+ if (pInst->iFlags & IMO2S_FLAG_ALLOWINTERACT) W32Browser_Exit();
+#endif
+ BuddyList_FreeEntry(&pInst->myUser, TRUE);
+ memset (pInst, 0, sizeof(IMOSAPI));
+ free (pInst);
+}
+
+// -----------------------------------------------------------------------------
+
+int Imo2S_Login (IMOSAPI *pInst, char *pszUser, char *pszPass, char **ppszError)
+{
+ // In case this module is passing in the original values...
+ char *pszLocalUser, *pszLocalPass;
+
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S_Login(%s, ****)\n", pszUser);
+ if (pInst->iLoginStat == 1) return pInst->iLoginStat;
+ if (!pInst->hInst) pInst->hInst=ImoSkype_Init(StatusCallback, pInst);
+ pszLocalUser = strdup(pszUser);
+ if (pInst->myUser.pszUser) free (pInst->myUser.pszUser);
+ pInst->myUser.pszUser = pszLocalUser;
+ pszLocalPass = strdup(pszPass);
+ if (pInst->pszPass) free (pInst->pszPass);
+ pInst->pszPass = pszLocalPass;
+ Send(pInst, "CONNSTATUS CONNECTING");
+ pInst->iLoginStat = ImoSkype_Login(pInst->hInst, pszLocalUser, pszLocalPass);
+ if (pInst->iLoginStat == 1)
+ {
+ ImoSkype_GetUnreadMsgs(pInst->hInst);
+ if (IMO_API_VERSION > 0) ImoSkype_GetAlpha(pInst->hInst);
+ Dispatcher_Start(pInst);
+ }
+ else
+ if (ppszError) *ppszError = ImoSkype_GetLastError(pInst->hInst);
+ return pInst->iLoginStat;
+}
+
+// -----------------------------------------------------------------------------
+
+void Imo2S_Logout(IMOSAPI *pInst)
+{
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S_Logout()\n");
+ Dispatcher_Stop(pInst);
+ if (ImoSkype_Logout(pInst->hInst) == 1)
+ {
+ pInst->iLoginStat = 0;
+ strcpy (pInst->myUser.szStatus, "OFFLINE");
+ }
+
+
+ // If we relogin, user information won't be re-propagated if we
+ // reuse the same connection. Therefore also dispose the connection
+ // to imo.im service (wouldn't be necessary, but to ensure proper
+ // repropagation of contacts on login, we have to do it, sorry)
+ if (!pInst->iShuttingDown)
+ {
+ ImoSkype_Exit(pInst->hInst);
+ pInst->hInst = NULL;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+int Imo2S_Send (IMOSAPI *pInst, char *pszMsg)
+{
+ char *pszDup = strdup(pszMsg);
+ char *pszRealMsg = pszMsg;
+
+ if (*pszRealMsg=='#')
+ {
+ char *p;
+ if (p = strchr (pszRealMsg, ' ')) pszRealMsg=p+1;
+ }
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S_Send(%s)\n", pszMsg);
+ if (strlen(pszRealMsg)>15 && strncasecmp (pszRealMsg, "SET ", 4)== 0 &&
+ (strncasecmp (pszRealMsg+4, "USERSTATUS", 10)==0 ||
+ strncasecmp (pszRealMsg+4, "CONNSTATUS", 10)==0))
+ {
+// if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S_Send: iLoginStat = %d\n",
+// pInst->iLoginStat);
+ if (pInst->iLoginStat == 0)
+ {
+ if (pInst->myUser.pszUser && pInst->pszPass && strncasecmp (pszRealMsg+15, "OFFLINE", 7))
+ {
+ Imo2S_Login(pInst, pInst->myUser.pszUser, pInst->pszPass, NULL);
+ }
+ }
+ else
+ {
+ HandleMessage (pInst, pszDup);
+ if (strncasecmp (pszRealMsg+15, "OFFLINE", 7) == 0)
+ Imo2S_Logout(pInst);
+ free (pszDup);
+ return 0;
+ }
+ }
+ if (pInst->iLoginStat != 1) return -1;
+ HandleMessage(pInst, pszDup);
+ free (pszDup);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+
+static int StatusCallback (cJSON *pMsg, void *pUser)
+{
+ char *pszName;
+ BOOL bAdded;
+ cJSON *pContent, *pProto;
+ IMOSAPI *pInst = (IMOSAPI*)pUser;
+ int m, iSize = cJSON_GetArraySize(pMsg);
+
+ if (pInst->fpLog)
+ {
+ char *pszMsg = cJSON_Print(pMsg);
+ fprintf (pInst->fpLog, "Imo2S::StatusCallback():%s\n", pszMsg);
+ free(pszMsg);
+ }
+
+ for (m=0; m<iSize; m++)
+ {
+ pContent = cJSON_GetArrayItem(pMsg, m);
+ if (!pContent) return 0;
+ pszName = cJSON_GetObjectItem(pContent,"name")->valuestring;
+
+ if ((pProto = cJSON_GetObjectItem(pContent,"proto")) && strcasecmp (pProto->valuestring, "prpl-skype"))
+ continue;
+
+ if (!strcmp(pszName, "recv_im"))
+ {
+ // I got a message!
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata");
+
+ if (pEdata)
+ {
+ MSGENTRY *pMsg;
+
+ // imo.im sometimes seems to send information about messages you sent yourself.
+ // We have to ignore them.
+ if (strcmp(cJSON_GetObjectItem(pEdata, "buid")->valuestring, pInst->myUser.pszUser) &&
+ (pMsg = MsgQueue_Insert(pInst->hMsgQueue, pEdata)))
+ {
+ if (pInst->iFlags & IMO2S_FLAG_CURRTIMESTAMP) time(&pMsg->timestamp);
+ Send(pInst, "%sMESSAGE %d STATUS %s", pInst->iProtocol>=3?"CHAT":"",
+ pMsg->hdr.uMsgNr, pMsg->szStatus);
+ }
+ }
+ }
+ else if (!strcmp(pszName, "signed_on"))
+ {
+ // I just signed on.
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata");
+ char *pszAlias;
+
+ Send(pInst, "CONNSTATUS ONLINE");
+ if (strcmp(pInst->myUser.szStatus, "OFFLINE")==0)
+ strcpy (pInst->myUser.szStatus, "ONLINE");
+ Send(pInst, "USERSTATUS %s", pInst->myUser.szStatus);
+ if (pEdata && (pszAlias = cJSON_GetObjectItem(pEdata, "alias")->valuestring))
+ {
+ pInst->myUser.pszAlias = strdup(pszAlias);
+ }
+ Send(pInst, "CURRENTUSERHANDLE %s", cJSON_GetObjectItem(pContent, "uid")->valuestring);
+ }
+ else if (!strcmp(pszName, "buddy_icon"))
+ {
+ // Here are the Avatars for the buddies
+ //We have to track them in a seperate list as the buddies may get populated lateron
+ cJSON *pArray = cJSON_GetObjectItem(pContent,"edata"), *pItem;
+ int i, iCount;
+
+ if (pArray)
+ {
+ for (i=0, iCount = cJSON_GetArraySize(pArray); i<iCount; i++)
+ {
+ if (pItem = cJSON_GetArrayItem(pArray, i))
+ AvatarList_Insert(pInst->hAvatarList, pItem);
+ }
+ }
+ }
+ else if (!strcmp(pszName, "disconnect"))
+ {
+ // I got disconnected (wrong user/pass?)
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata");
+ //char *pszMsg;
+
+ Send(pInst, "CONNSTATUS OFFLINE");
+ Send(pInst, "USERSTATUS OFFLINE");
+ strcpy (pInst->myUser.szStatus, "OFFLINE");
+ /*
+ if (pEdata && (pszMsg = cJSON_GetObjectItem(pEdata, "msg")->valuestring))
+ {
+ if (strcmp(pszMsg, "uidpassword")==0)
+ {
+ fprintf (stderr, "Invalid username / password combination!\n");
+ }
+ }
+ */
+ }
+ else if ((bAdded = !strcmp(pszName, "buddy_added")) || !strcmp(pszName, "buddy_status"))
+ {
+ // Here comes the contact list
+ cJSON *pArray = cJSON_GetObjectItem(pContent,"edata"), *pItem;
+ char *pszLastBUID = NULL, *pszLastGroup = NULL;
+ int i, iCount;
+
+ if (pArray)
+ {
+ TYP_LIST *hListMemToAdd = NULL;
+
+ for (i=0, iCount = cJSON_GetArraySize(pArray); i<iCount; i++)
+ {
+ if (pItem = cJSON_GetArrayItem(pArray, i))
+ {
+ char szQuery[256];
+ char *pszBUID = cJSON_GetObjectItem(pItem, "buid")->valuestring;
+ cJSON *pGroup = cJSON_GetObjectItem(pItem, "group");
+ cJSON *pDisplay = cJSON_GetObjectItem(pItem, "display");
+
+ if (bAdded)
+ {
+ /*
+ if (BuddyList_Find (pInst->hBuddyList, cJSON_GetObjectItem(pItem, "buid")->valuestring))
+ bAdded=FALSE;
+ else
+ */
+ BuddyList_Insert(pInst->hBuddyList, pItem);
+ }
+ else BuddyList_SetStatus(pInst->hBuddyList, pItem);
+
+ if ((!pGroup || strcmp(pGroup->valuestring, "Skype")==0 ||
+ strcmp(pGroup->valuestring, "Offline")==0) &&
+ !pDisplay)
+ {
+ // Normal user, not groupchat, so output this
+ sprintf (szQuery, "GET USER %s ONLINESTATUS", pszBUID);
+ HandleMessage (pInst, szQuery);
+ sprintf (szQuery, "GET USER %s MOOD_TEXT", pszBUID);
+ HandleMessage (pInst, szQuery);
+ }
+ else
+ {
+ // Groupchat created/added
+ MSGENTRY * pMsgEntry = NULL;
+
+ if (bAdded && pInst->pszBuddiesToAdd)
+ {
+ // Process pending ADDs
+ char *pTok, szQuery[256];
+
+ for (pTok = strtok(pInst->pszBuddiesToAdd, ", "); pTok; pTok=strtok(NULL, ", "))
+ ImoSkype_GroupInvite(pInst->hInst, pszBUID, pTok);
+ free (pInst->pszBuddiesToAdd);
+ pInst->pszBuddiesToAdd = NULL;
+ sprintf (szQuery, "GET CHAT %s STATUS", pszBUID);
+ HandleMessage (pInst, szQuery);
+ }
+ else
+ {
+ if (bAdded || !pDisplay)
+ {
+ char szQuery[256], szGroup[256]={0};
+ NICKENTRY *pChat;
+
+ if (pGroup) sprintf (szGroup, "%s;", pGroup->valuestring);
+ if (pGroup && (pChat=BuddyList_Find(pInst->hBuddyList, szGroup)) &&
+ pChat->hGCMembers)
+ {
+ sprintf (szQuery, "GET CHAT %s MEMBERS", szGroup);
+ HandleMessage (pInst, szQuery);
+ }
+ else
+ {
+ if ((bAdded || !pChat) && (!pszLastBUID || strcmp(pszLastBUID, pszBUID)) &&
+ (!pszLastGroup || (pGroup && strcmp(pszLastGroup, pGroup->valuestring))))
+ {
+ if (!hListMemToAdd) hListMemToAdd=List_Init(0);
+ List_Push(hListMemToAdd, pItem);
+ pszLastBUID = pszBUID;
+ if (pGroup) pszLastGroup = pGroup->valuestring;
+ }
+ }
+ }
+ /*
+ else
+ {
+ pMsgEntry = MsgQueue_AddEvent (pInst->hMsgQueue, pszBUID, "SETTOPIC");
+ if (pDisplay->valuestring) pMsgEntry->pszMessage = strdup(pDisplay->valuestring);
+ }
+ */
+ if (pMsgEntry)
+ Send(pInst, "%sMESSAGE %d STATUS %s", pInst->iProtocol>=3?"CHAT":"",
+ pMsgEntry->hdr.uMsgNr, pMsgEntry->szStatus);
+
+ }
+ }
+ }
+ }
+ if (hListMemToAdd)
+ {
+ int nCount;
+
+ for (i=0, nCount=List_Count(hListMemToAdd); i<nCount; i++)
+ {
+ cJSON *pItem = List_ElementAt(hListMemToAdd, i);
+ cJSON *pInviter = cJSON_GetObjectItem(pItem, "inviter");
+ MSGENTRY *pMsgEntry;
+
+ if (pMsgEntry = MsgQueue_AddEvent (pInst->hMsgQueue, cJSON_GetObjectItem(pItem, "buid")->valuestring, "ADDEDMEMBERS")) // MULTI_SUBSCRIBED
+ {
+ if (pInviter) pMsgEntry->pszAuthor = strdup(pInviter->valuestring);
+ Send(pInst, "%sMESSAGE %d STATUS %s", pInst->iProtocol>=3?"CHAT":"",
+ pMsgEntry->hdr.uMsgNr, pMsgEntry->szStatus);
+ }
+ }
+
+ List_Exit(hListMemToAdd);
+ hListMemToAdd = NULL;
+ }
+ if (bAdded && pInst->bFriendsPending)
+ {
+ char szMsg[]="SEARCH FRIENDS";
+ pInst->bFriendsPending = 0;
+ HandleMessage (pInst, szMsg);
+ }
+ }
+ }
+ else if (!strcmp(pszName, "buddy_removed"))
+ {
+ // Here comes the contact list
+ cJSON *pArray = cJSON_GetObjectItem(pContent,"edata"), *pItem;
+ int i, iCount;
+
+ if (pArray)
+ {
+ for (i=0, iCount = cJSON_GetArraySize(pArray); i<iCount; i++)
+ {
+ char *pszUser;
+ cJSON *pBuid;
+
+ if (iCount==1) pItem=pArray; else pItem = cJSON_GetArrayItem(pArray, i);
+ if (pItem && (pBuid = cJSON_GetObjectItem(pItem, "buid")) &&
+ (pszUser = pBuid->valuestring))
+ {
+ NICKENTRY *pNick = BuddyList_Find (pInst->hBuddyList, pszUser);
+
+ if (pNick && pNick->pGroup)
+ {
+ MSGENTRY *pMsg = MsgQueue_AddEvent (pInst->hMsgQueue, pszUser, "KICKED");
+ cJSON *pUid = cJSON_GetObjectItem(pContent,"uid");
+ if (pUid) pMsg->pszAuthor = strdup(pUid->valuestring);
+ Send(pInst, "%sMESSAGE %d STATUS %s", pInst->iProtocol>=3?"CHAT":"",
+ pMsg->hdr.uMsgNr, pMsg->szStatus);
+ }
+ else
+ Send (pInst, "USER %s BUDDYSTATUS 1", pszUser);
+ if (pNick)
+ BuddyList_Remove (pInst->hBuddyList, pNick);
+ }
+ }
+ }
+ }
+ else
+ if (/*!strcmp(pszName, "recv") || */!strcmp(pszName, "streams_info"))
+ {
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata"),
+ *pType = cJSON_GetObjectItem(pContent,"type"), *pVal;
+
+ if (pType && pEdata)
+ {
+ if (strcasecmp(pType->valuestring, "call")==0 || strcasecmp(pType->valuestring, "video")==0 ||
+ strcasecmp(pType->valuestring, "av")==0)
+ {
+ // Rring, rrring...
+ int iDirection = ((pVal = cJSON_GetObjectItem(pEdata, "is_initiator")) && pVal->type == cJSON_True)?CALL_OUTGOING:CALL_INCOMING;
+ CALLENTRY *pCall = CallQueue_Insert (pInst->hCallQueue, pEdata, iDirection);
+ if (pCall)
+ {
+ Send (pInst, "CALL %d STATUS %s", pCall->hdr.uMsgNr, pCall->szStatus);
+ if ((pInst->iFlags & IMO2S_FLAG_ALLOWINTERACT) && iDirection == CALL_OUTGOING)
+ StartCallSWF (pInst, pCall);
+ }
+ }
+ }
+ }
+ else
+ if (!strcmp(pszName, "ended"))
+ {
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata"),
+ *pType = cJSON_GetObjectItem(pContent,"type");
+
+ if (pType && pEdata)
+ {
+ if (strcasecmp(pType->valuestring, "call")==0 || strcasecmp(pType->valuestring, "video")==0)
+ {
+ // No call ID, so just hangup all calls to this user
+ int i, nCount = List_Count(pInst->hCallQueue);
+ char *pszUser = cJSON_GetObjectItem(pEdata, "buid")->valuestring;
+
+ for (i=0; i<nCount; i++)
+ {
+ CALLENTRY *pCall = (CALLENTRY*)List_ElementAt(pInst->hCallQueue, i);
+
+ if (!strcmp(pCall->pszUser, pszUser) && strcmp (pCall->szStatus, "FINISHED"))
+ {
+ char szQuery[256];
+
+ sprintf (szQuery, "SET CALL %d STATUS FINISHED", pCall->hdr.uMsgNr);
+ HandleMessage (pInst, szQuery);
+ }
+ }
+ }
+ }
+ }
+ else
+ if (!strcmp(pszName, "reflect")) // Status reflections. We may want to support more of them in the future
+ {
+ cJSON *pEdata = cJSON_GetObjectItem(pContent,"edata"),
+ *pType = cJSON_GetObjectItem(pContent,"type"), *pRname, *pValue;
+
+ if (pEdata && pType && (pRname = cJSON_GetObjectItem(pEdata,"r_name")))
+ {
+ if (strcasecmp(pType->valuestring, "account") == 0)
+ {
+ if (strcasecmp (pRname->valuestring, "set_status") == 0 &&
+ (pValue = cJSON_GetObjectItem(pEdata,"primitive")) )
+ {
+ unsigned int i;
+
+ for (i=0; i<sizeof(m_stMap)/sizeof(m_stMap[0]); i++)
+ {
+ if (!strcasecmp(m_stMap[i].pszImoStat, pValue->valuestring))
+ {
+ strcpy (pInst->myUser.szStatus, m_stMap[i].pszSkypeStat);
+ Send (pInst, "USERSTATUS %s", pInst->myUser.szStatus);
+ break;
+ }
+ }
+
+ // Just ensure that on autoaway we notify imo.im that we are still there
+ if (!strcmp (pValue->valuestring, "away"))
+ ImoSkype_KeepAlive(pInst->hInst);
+
+ if (pValue = cJSON_GetObjectItem(pEdata,"status"))
+ {
+ if (pInst->myUser.pszStatusText) free (pInst->myUser.pszStatusText);
+ pInst->myUser.pszStatusText = NULL;
+ if (*pValue->valuestring)
+ pInst->myUser.pszStatusText = strdup(pValue->valuestring);
+ }
+
+ }
+ }
+ else
+ if (strcasecmp(pType->valuestring, "conv") == 0)
+ {
+ if (strcasecmp (pRname->valuestring, "send_im") == 0)
+ {
+ MSGENTRY *pMsg;
+
+ if (pMsg = MsgQueue_AddReflect(pInst->hMsgQueue, pEdata, pInst->hBuddyList))
+ {
+ if (pInst->iFlags & IMO2S_FLAG_CURRTIMESTAMP) time(&pMsg->timestamp);
+ Send(pInst, "%sMESSAGE %d STATUS %s", pInst->iProtocol>=3?"CHAT":"",
+ pMsg->hdr.uMsgNr, pMsg->szStatus);
+ }
+ }
+
+ }
+ }
+ }
+ else
+ if (!strcmp(pszName, "expired") && m>=iSize-1)
+ {
+ // Session expired, so we have to reconnect
+ Send(pInst, "CONNSTATUS OFFLINE");
+ Send(pInst, "USERSTATUS OFFLINE");
+ strcpy (pInst->myUser.szStatus, "OFFLINE");
+ pInst->iLoginStat = 0;
+ Dispatcher_Stop(pInst);
+ if (pInst->myUser.pszUser && pInst->pszPass)
+ Imo2S_Login(pInst, pInst->myUser.pszUser, pInst->pszPass, NULL);
+ }
+ else
+ if (!strcmp(pszName, "ack"))
+ {
+ MSGENTRY *pMsg;
+ cJSON *pRqId = cJSON_GetObjectItem(pContent,"request_id");
+
+ if (pRqId && (pMsg = MsgQueue_FindByRqId(pInst->hMsgQueue, pRqId->valueint)))
+ {
+ cJSON *pResp, *pTS;
+
+ strcpy (pMsg->szStatus, "SENT");
+ if ((pResp = cJSON_GetObjectItem(pContent,"response")) &&
+ (pTS = cJSON_GetObjectItem(pResp,"timestamp")))
+ pMsg->timestamp = pTS->valueint;
+ Send (pInst, "MESSAGE %d STATUS %s", pMsg->hdr.uMsgNr, pMsg->szStatus);
+ }
+ }
+ else
+ {
+ char *pszMsg = cJSON_Print(pMsg);
+ fprintf (stderr, "%s\n\n", pszMsg);
+ free (pszMsg);
+ }
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+#ifdef WIN32
+// Set call status to finished when closing phone applet window just in case
+// there is no callback by imo.im upon closure
+static LRESULT CallWndFilter(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message)
+ {
+ case WM_DESTROY:
+ {
+ IMOSAPI *pInst = (IMOSAPI*)GetWindowLong (hWnd, GWL_PINST);
+ int i, nCount;
+
+ if (!pInst) break;
+ for (i=0, nCount = List_Count(pInst->hCallQueue); i<nCount; i++)
+ {
+ CALLENTRY *pCall = (CALLENTRY*)List_ElementAt(pInst->hCallQueue, i);
+
+ if (pCall->hCallWnd == hWnd)
+ {
+ char szQuery[256];
+
+ sprintf (szQuery, "SET CALL %d STATUS FINISHED", pCall->hdr.uMsgNr);
+ HandleMessage (pInst, szQuery);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return CallWindowProc((WNDPROC)GetWindowLong (hWnd, GWL_ORIGWPRC), hWnd, message, wParam, lParam);
+}
+#endif
+
+
+// -----------------------------------------------------------------------------
+
+static int StartCallSWF (IMOSAPI *pInst, CALLENTRY *pCall)
+{
+ char szSWF[256], szFlashVars[1024], szID[18];
+ char szHTML[2048];
+ static unsigned int id=100;
+
+
+ /* The flash plugin basically opens rtmp://[host]/mchat in case of type=imo, otherwise rtmp://[host]/ivc
+ Maybe this can also be used with a SIP-phone or Asterisk?
+ */
+#ifndef WIN32
+ FILE *fpTemp;
+ int iFound;
+
+ sprintf (pCall->szCallFile, "xdg-open %s.html", tmpnam(NULL));
+ if (!(fpTemp=fopen(pCall->szCallFile, "w"))) return -1;
+#else
+ // Windows:
+ // Ensure that we are allowed to load the .swf from imo.im
+#ifndef CSIDL_APPDATA
+#define CSIDL_APPDATA 0x001a
+#endif
+ static BOOL bInit = TRUE;
+
+ if (bInit)
+ {
+ char szPath[MAX_PATH]={0};
+ HMODULE hModule;
+ typedef HMODULE (__stdcall *SHGETFOLDERPATH)(HWND, int, HANDLE, DWORD, LPTSTR);
+
+ if (hModule = LoadLibrary("SHFOLDER.DLL"))
+ {
+ SHGETFOLDERPATH fnShGetFolderPath = (SHGETFOLDERPATH)GetProcAddress(hModule, "SHGetFolderPathA");
+
+ if (fnShGetFolderPath && fnShGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, szPath)==S_OK)
+ {
+ strcat (szPath, "\\Macromedia\\Flash Player");
+ if (GetFileAttributes (szPath) != 0xFFFFFFFF)
+ {
+ strcat (szPath, "\\#Security");
+ _mkdir (szPath);
+ strcat (szPath, "\\FlashPlayerTrust");
+ _mkdir (szPath);
+ strcat (szPath, "\\imo2sproxy.cfg");
+ if (GetFileAttributes (szPath) == 0xFFFFFFFF)
+ {
+ FILE *fp = fopen (szPath, "w");
+
+ if (fp)
+ {
+ fputs ("https://imo.im/images/nchat.swf\nabout:blank\n", fp);
+ fclose (fp);
+ }
+ }
+ }
+ }
+ FreeLibrary(hModule);
+ }
+ bInit = FALSE;
+ }
+#endif
+ sprintf (szSWF, "https://imo.im/images/nchat.swf?%s", IVC_VERSION);
+ ImoRq_CreateID (szID, 16);
+ //sprintf (szID, "imo%d", id++);
+
+ if (*pCall->szSendStream)
+ sprintf (szFlashVars,
+ "type=skype&amp;"
+ "send_stream=%s&amp;"
+ "recv_stream=%s&amp;"
+ "id=skype#%s&amp;"
+ "host=video0.imo.im&amp;"
+ "debug=conv net&amp;"
+ "buddy_icon=https://imo.im/assets/main/icn_default.png&amp;"
+ "setCookie=setCookie&amp;"
+ "getCookie=getCookie&amp;"
+ "removeCookie=removeCookie&amp;"
+ "log=log&amp;"
+ "init_callback=init_callback&amp;"
+ "video_options_changed_cb=video_options_changed_cb&amp;"
+ "options_changed_cb=options_changed_cb&amp;"
+ "mic_changed_cb=mic_changed_cb&amp;"
+ "cam_changed_cb=cam_changed_cb&amp;"
+ "connection_status_cb=connection_status_cb",
+ pCall->szSendStream, pCall->szRecvStream, pCall->szSendStream);
+ else
+ return -1;
+ // sprintf (szFlashVars, "type=imo&amp;conv=%s&amp;role=%d&amp;host=%s&amp;id=%s", pCall->szConv, pCall->iRole, pCall->szIP, szID);
+
+ strcat (szFlashVars, "&amp;audio_only=true");
+ // Currently not supported
+ sprintf (szHTML, "<html>\n"
+ "<head><script language='javascript'>\n"
+ "function log(t, s) { document.all.log.innerHTML+=s+'<br>'; }\n"
+ "function setCookie (N, L, M) { alert ('setcookie av_chat_'+L+' = '+M); }\n"
+ "function getCookie (M, L) { alert ('getcookie av_chat_'+L); }\n"
+ "function removeCookie (M, L) { alert ('removecookie av_chat_'+L); }\n"
+ "function init_callback(L) { }\n"
+ "function video_options_changed_cb(v, t, s) { }\n"
+ "function options_changed_cb(v, t, s) { }\n"
+ "function mic_changed_cb(u, s) { }\n"
+ "function cam_changed_cb(u, t) { }\n"
+ "function connection_status_cb (u, s) { }\n"
+ "</script></head>"
+ "<body>\n"
+ "<object width=\"400\" height=\"208\" type=\"application/x-shockwave-flash\" data=\"%s\" id=\"flash_widget_%s\" "
+ "style=\"visibility: visible; width: 400px; height: 208px;\">\n"
+ "<param name=\"movie\" value=\"%s\">\n"
+ "<param name=\"allowscriptaccess\" value=\"always\">\n"
+ "<param name=\"bgcolor\" value=\"#ffffff\">"
+ "<param name=\"flashvars\" value=\"%s\">\n"
+ "</object><br><div id=\"log\"></div>\n"
+ "</body></html>\n",
+ szSWF, szID, szSWF, szFlashVars);
+
+#ifdef WIN32
+ //OutputDebugString (szHTML);
+ sprintf (szSWF, "Voicechat with %s", pCall->pszUser);
+
+ /*
+
+ {
+ FILE *fpOut = fopen("C:\\TEMP\\CALL.HTML", "w");
+
+ fputs (szHTML, fpOut);
+ fclose (fpOut);
+ system ("\"C:\\Programme\\Internet Explorer\\IEXPLORE.EXE\" C:\\TEMP\\CALL.HTML");
+ }
+ */
+
+ if ((pCall->hCallWnd = W32Browser_ShowHTMLStr (szHTML,420, 280, szSWF))>0)
+ {
+ // Hook WndProc to handle WM_DESTROY so that we generate a CALL %d STATUS FINISHED on
+ // closing the chat window
+#ifdef _WIN64
+ SetWindowLongPtr ((HWND)pCall->hCallWnd, GWL_PINST, (LONG_PTR)pInst);
+ SetWindowLongPtr ((HWND)pCall->hCallWnd, GWL_ORIGWPRC,
+ GetWindowLongPtr ((HWND)pCall->hCallWnd, GWLP_WNDPROC));
+ SetWindowLongPtr ((HWND)pCall->hCallWnd, GWLP_WNDPROC, (LONG_PTR)CallWndFilter);
+#else
+ SetWindowLong ((HWND)pCall->hCallWnd, GWL_PINST, (LONG)pInst);
+ SetWindowLong ((HWND)pCall->hCallWnd, GWL_ORIGWPRC, GetWindowLong ((HWND)pCall->hCallWnd, GWL_WNDPROC));
+ SetWindowLong((HWND)pCall->hCallWnd, GWL_WNDPROC, (LONG)CallWndFilter);
+#endif
+ return 0;
+ }
+ return -1;
+#else
+ fprintf (fpTemp, "%s", szHTML);
+ fclose (fpTemp);
+ iFound = system(pCall->szCallFile);
+ return (iFound == -1 || iFound == 127)?-1:0;
+#endif
+}
+
+// -----------------------------------------------------------------------------
+
+static void DispatcherThread(void *pUser)
+{
+ IMOSAPI *pInst = (IMOSAPI*)pUser;
+ time_t t = 0, tcur;
+
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S::DispatcherThread() start\n");
+ while (!pInst->iShuttingDown)
+ {
+#if defined(WIN32) && defined(WIN32)
+ char szBuf[128];
+
+ sprintf (szBuf, "DispatcherThread %d loops.\n", GetCurrentThreadId());
+ OutputDebugString (szBuf);
+#endif
+ if (time(&tcur)>=t+300)
+ {
+ t=tcur;
+ //ImoSkype_Ping (pInst->hInst);
+ ImoSkype_KeepAlive(pInst->hInst);
+ }
+
+ // Set status in case this is needed
+ if (pInst->tSetMoodText && tcur>=pInst->tSetMoodText)
+ {
+ int i;
+
+ pInst->tSetMoodText = 0;
+ for (i=0; i<sizeof(m_stMap)/sizeof(m_stMap[0]); i++)
+ {
+ if (!strcasecmp(m_stMap[i].pszSkypeStat, pInst->myUser.szStatus))
+ {
+ ImoSkype_SetStatus(pInst->hInst, m_stMap[i].pszImoStat,
+ pInst->myUser.pszStatusText?pInst->myUser.pszStatusText:"");
+ break;
+ }
+ }
+ }
+ ImoSkype_Poll(pInst->hInst);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+#ifdef WIN32
+static int Dispatcher_Start(IMOSAPI *pInst)
+{
+ DWORD ThreadID;
+
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S::Dispatcher_Start()\n");
+ return (pInst->hThread=(thread_t)_beginthreadex(NULL, 0,
+ (unsigned(__stdcall *)(void*))DispatcherThread, pInst, 0, &ThreadID))!=0;
+
+}
+
+static int Dispatcher_Stop(IMOSAPI *pInst)
+{
+ int iRet, iOldShutdown;
+
+ if (pInst->fpLog)
+ {
+ fprintf (pInst->fpLog, "Imo2S::Dispatcher_Stop()\n");
+ fflush(pInst->fpLog);
+ }
+
+ // Shutdown polling socket and wait some time if thread terminates
+ // gracefully, otherwise kill it
+ iOldShutdown = pInst->iShuttingDown;
+ pInst->iShuttingDown = 1;
+ ImoSkype_CancelPolling (pInst->hInst);
+ if (WaitForSingleObject (pInst->hThread, 2000) == WAIT_TIMEOUT)
+ iRet = TerminateThread (pInst->hThread, 0);
+ else iRet = 1;
+ pInst->iShuttingDown = iOldShutdown;
+
+ if (iRet)
+ {
+ CloseHandle (pInst->hThread);
+ pInst->hThread = 0;
+ }
+
+ if (pInst->fpLog)
+ {
+ fprintf (pInst->fpLog, "Imo2S::Dispatcher_Stop() done.\n");
+ pInst->fpLog = NULL;
+ }
+
+ return iRet;
+}
+
+#else
+static int Dispatcher_Start(IMOSAPI *pInst)
+{
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S::Dispatcher_Start()\n");
+ return pthread_create(&pInst->hThread, NULL, DispatcherThread, pInst)==0;
+}
+
+static int Dispatcher_Stop(IMOSAPI *pInst)
+{
+ if (pInst->fpLog) fprintf (pInst->fpLog, "Imo2S::Dispatcher_Stop()\n");
+ if (pthread_cancel(pInst->hThread))
+ {
+ pInst->hThread=0;
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+// -----------------------------------------------------------------------------
+
+static void Send(IMOSAPI *pInst, const char *pszMsg, ...)
+{
+ va_list ap;
+ int iLen, iLenCmdID;
+ char *pszLogBuf = pInst->pszLogBuf;
+ int cbBuf = pInst->cbBuf;
+
+ iLenCmdID = pInst->pszCmdID?strlen(pInst->pszCmdID)+1:0;
+ do
+ {
+ cbBuf = pInst->cbBuf - iLenCmdID;
+ pszLogBuf = pInst->pszLogBuf + iLenCmdID;
+ va_start(ap, pszMsg);
+ iLen = vsnprintf (pszLogBuf, cbBuf, pszMsg, ap);
+ va_end(ap);
+#ifndef WIN32
+ if (iLen>=cbBuf) iLen=-1;
+#endif
+ if (iLen == -1)
+ {
+ char *pNewBuf;
+
+ if (!(pNewBuf = realloc(pInst->pszLogBuf, pInst->cbBuf*2)))
+ {
+ break;
+ }
+ pInst->cbBuf*=2;
+ pInst->pszLogBuf = pNewBuf;
+ }
+ } while (iLen == -1);
+ if (pInst->pszCmdID && iLenCmdID>1)
+ {
+ memcpy (pInst->pszLogBuf, pInst->pszCmdID, iLenCmdID);
+ pInst->pszLogBuf[iLenCmdID-1]=' ';
+ }
+
+//printf ("%s\n", szBuf);
+ pInst->Callback(pInst->pszLogBuf, pInst->pUser);
+}
+
+// -----------------------------------------------------------------------------
+
+static void HandleMessage(IMOSAPI *pInst, char *pszMsg)
+{
+ char *pszCmd=strtok(pszMsg, " ");
+
+ if (!pInst || !pszCmd || !pInst->hInst) return;
+ if (*pszCmd=='#')
+ {
+ // This is a PROTOCOL 4 feature, but we will support it just in case...
+ pInst->pszCmdID = pszCmd;
+ if (!(pszCmd=strtok(NULL, " ")))
+ {
+ pInst->pszCmdID = NULL;
+ return;
+ }
+ }
+ else pInst->pszCmdID = NULL;
+
+ if (strcasecmp(pszCmd, "PROTOCOL") == 0)
+ {
+ if (pszCmd = strtok(NULL, " "))
+ {
+ pInst->iProtocol = atoi(pszCmd);
+ if (pInst->iProtocol>3) pInst->iProtocol=3;
+ }
+
+ Send (pInst, "PROTOCOL %d", pInst->iProtocol);
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "PING") == 0)
+ {
+ Send (pInst, "PONG");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "SEARCH") == 0)
+ {
+ TYP_FIFO *hFifo;
+
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 2 Invalid command");
+ return;
+ }
+
+ if (strcasecmp(pszCmd, "FRIENDS") == 0)
+ {
+ unsigned int nCount =List_Count(pInst->hBuddyList);
+
+ if (!nCount)
+ {
+ pInst->bFriendsPending = 1;
+ return;
+ }
+ if(hFifo=Fifo_Init(512))
+ {
+ unsigned int i;
+ char *pszUsers;
+
+ for (i=0; i<nCount; i++)
+ {
+ NICKENTRY *pEntry = List_ElementAt(pInst->hBuddyList, i);
+ if (!pEntry->pGroup && !pEntry->hGCMembers)
+ {
+ if (i>0) Fifo_AddString (hFifo, ", ");
+ Fifo_AddString (hFifo, pEntry->pszUser);
+ }
+ }
+ if (pszUsers = Fifo_Get(hFifo, NULL))
+ Send (pInst, "USERS %s", pszUsers);
+ else
+ pInst->bFriendsPending = 1;
+ Fifo_Exit(hFifo);
+ }
+ }
+ else if (strcasecmp(pszCmd, "MISSEDMESSAGES") == 0)
+ {
+ unsigned int nCount=List_Count(pInst->hMsgQueue);
+
+ if(nCount && (hFifo=Fifo_Init(512)))
+ {
+ unsigned int i, j=0;
+
+ for (i=0; i<nCount; i++)
+ {
+ MSGENTRY *pEntry = List_ElementAt(pInst->hMsgQueue, i);
+ char szNr[32];
+
+ if (!strcmp(pEntry->szStatus, "RECEIVED"))
+ {
+ if (j>0) Fifo_AddString (hFifo, ", ");
+ sprintf (szNr, "%d", pEntry->hdr.uMsgNr);
+ Fifo_AddString (hFifo, szNr);
+ j++;
+ }
+ }
+ Send (pInst, "MESSAGES %s", Fifo_Get(hFifo, NULL));
+ Fifo_Exit(hFifo);
+ }
+ }
+ else if (strcasecmp(pszCmd, "USERS") == 0)
+ {
+ // There is no possibility to search Skype users in imo.im
+ // therefore just return that the user exists even if it doesn't :(
+ Send (pInst, "USERS %s", pszCmd+6);
+ // We add the user as a temporary contact to our list so that the
+ // client can get the empty properties and set the buddystatus.
+ BuddyList_AddTemporaryUser (pInst->hBuddyList, pszCmd+6);
+ }
+ else if (strcasecmp(pszCmd, "USERSWAITINGMYAUTHORIZATION") == 0)
+ {
+ Send (pInst, "USERS");
+ }
+ else if (strcasecmp(pszCmd, "ACTIVECALLS") == 0)
+ {
+ char szCalls[512];
+ int i, nCount, iOffs=0;
+
+ iOffs = sprintf (szCalls, "CALLS");
+ for (i=0, nCount=List_Count(pInst->hCallQueue); i<nCount; i++)
+ {
+ if (i) iOffs+=sprintf(&szCalls[iOffs], ", ");
+ iOffs+=sprintf(&szCalls[iOffs], "%d", ((CALLENTRY*)List_ElementAt (pInst->hCallQueue, i))->hdr.uMsgNr);
+ if (iOffs+6>=sizeof(szCalls)) break;
+ }
+ Send (pInst, szCalls);
+ }
+ else if (strcasecmp(pszCmd, "RECENTCHATS") == 0)
+ {
+ char szChats[2056];
+ int i, nCount, iOffs=0, j=0;
+
+ iOffs = sprintf (szChats, "CHATS ");
+ for (i=0, nCount=List_Count(pInst->hBuddyList); i<nCount; i++)
+ {
+ NICKENTRY *pChat = (NICKENTRY*)List_ElementAt (pInst->hBuddyList, i);
+
+ if (BuddyList_IsGroupchat(pChat))
+ {
+ if (j) iOffs+=sprintf(&szChats[iOffs], ", ");
+ iOffs+=sprintf(&szChats[iOffs], "%s", pChat->pszUser);
+ if (iOffs+6>=sizeof(szChats)) break;
+ j++;
+ }
+ }
+ Send (pInst, szChats);
+ }
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "GET") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 7 Invalid property");
+ return;
+ }
+
+ if (strcasecmp(pszCmd, "USER") == 0)
+ {
+ NICKENTRY *pUser = NULL;
+
+ if (pszCmd = strtok(NULL, " "))
+ {
+ if (!strcasecmp (pszCmd, pInst->myUser.pszUser))
+ pUser = &pInst->myUser;
+ else
+ pUser = BuddyList_Find(pInst->hBuddyList, pszCmd);
+ }
+
+ if (!pUser)
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+
+ if (!strcasecmp (pszCmd, "HANDLE"))
+ {
+ if (pUser->pszAlias) Send (pInst, "USER %s HANDLE %s", pUser->pszUser, pUser->pszAlias);
+ }
+ else if (!strcasecmp (pszCmd, "FULLNAME")) /* Workaround */
+ Send (pInst, "USER %s FULLNAME %s", pUser->pszUser, pUser->pszAlias);
+ else if (!strcasecmp (pszCmd, "DISPLAYNAME"))
+ Send (pInst, "USER %s DISPLAYNAME %s", pUser->pszUser, pUser->pszAlias);
+ else if (!strcasecmp (pszCmd, "HASCALLEQUIPMENT"))
+ Send (pInst, "USER %s HASCALLEQUIPMENT TRUE", pUser->pszUser);
+ else if (!strcasecmp (pszCmd, "BUDDYSTATUS"))
+ Send (pInst, "USER %s BUDDYSTATUS %d", pUser->pszUser, pUser->iBuddyStatus);
+ else if (!strcasecmp (pszCmd, "ISAUTHORIZED"))
+ Send (pInst, "USER %s ISAUTHORIZED TRUE", pUser->pszUser);
+ else if (!strcasecmp (pszCmd, "MOOD_TEXT"))
+ Send (pInst, "USER %s MOOD_TEXT %s", pUser->pszUser,
+ pUser->pszStatusText?pUser->pszStatusText:"");
+ else if (!strcasecmp (pszCmd, "SEX"))
+ Send (pInst, "USER %s SEX UNKNOWN", pUser->pszUser);
+ else if (!strcasecmp (pszCmd, "BIRTHDAY"))
+ Send (pInst, "USER %s BIRTHDAY 0", pUser->pszUser);
+ else if (!strcasecmp (pszCmd, "ONLINESTATUS"))
+ {
+ unsigned int i;
+
+ for (i=0; i<sizeof(m_stMap)/sizeof(m_stMap[0]); i++)
+ {
+ if (!strcasecmp(m_stMap[i].pszImoStat, pUser->szStatus))
+ {
+ Send (pInst, "USER %s ONLINESTATUS %s", pUser->pszUser, m_stMap[i].pszSkypeStat);
+ break;
+ }
+ }
+ }
+ else if (!strcasecmp (pszCmd, "AVATAR"))
+ {
+ char *pszFile, *pAvatarBuf;
+ unsigned int dwLength;
+ AVATARENTRY *pAvatar;
+ FILE *fp;
+
+ if (!(pszFile = strtok(NULL, " ")) || strcasecmp (pszFile, "1"))
+ {
+ Send (pInst, "ERROR 116 GET invalid ID");
+ return;
+ }
+ if (!(pszFile = strtok(NULL, "\n")))
+ {
+ Send (pInst, "ERROR 7 GET: invalid WHAT");
+ return;
+ }
+ if (fp=fopen(pszFile, "r"))
+ {
+ fseek (fp, 0, SEEK_END);
+ if (ftell(fp))
+ {
+ fclose(fp);
+ Send (pInst, "ERROR 124 GET Destination file is not empty");
+ return;
+ }
+ fclose(fp);
+ }
+ if (!(pAvatar = AvatarList_Find(pInst->hAvatarList, pUser->pszUser)) ||
+ !(pAvatarBuf = ImoSkype_GetAvatar (pInst->hInst, pAvatar->pszIcon, &dwLength)))
+ {
+ // FIXME: Normally we should return default avatar if pAvatar is NULL.
+ // Default avatar from imo.im is PNG, but JPEG is expected, so we
+ // return an error here
+ Send (pInst, "ERROR 122 GET Unable to load avatar");
+ return;
+ }
+ if (!(fp=fopen(pszFile,
+#ifdef WIN32
+ "wb"
+#else
+ "w"
+#endif
+ )))
+ {
+ Send (pInst, "ERROR 121 GET File path doesn't exist");
+ return;
+ }
+ fwrite (pAvatarBuf, dwLength, 1, fp);
+ fclose (fp);
+ Send (pInst, "USER %s AVATAR 1 %s", pUser->pszUser, pszFile);
+ }
+ else
+ {
+ Send(pInst, "ERROR 10 Invalid propery");
+ }
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CURRENTUSERHANDLE") == 0)
+ {
+ if (pInst->myUser.pszUser)
+ Send(pInst, "CURRENTUSERHANDLE %s", pInst->myUser.pszUser);
+ }
+ else
+ if (strcasecmp(pszCmd, "USERSTATUS") == 0)
+ {
+ Send(pInst, "USERSTATUS %s", pInst->myUser.szStatus);
+ }
+ else
+ if (strcasecmp(pszCmd, "MESSAGE") == 0 || strcasecmp(pszCmd, "CHATMESSAGE") == 0)
+ {
+ MSGENTRY *pEntry;
+ char *pszMessage = pszCmd;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pEntry = MsgQueue_Find(pInst->hMsgQueue, atol(pszCmd))))
+ {
+ Send (pInst, "ERROR 14 Invalid message id");
+ return;
+ }
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+ if (!strcasecmp (pszCmd, "TIMESTAMP"))
+ Send (pInst, "%s %d TIMESTAMP %ld", pszMessage, pEntry->hdr.uMsgNr, pEntry->timestamp);
+ else if (!strcasecmp (pszCmd, "PARTNER_HANDLE") || !strcasecmp (pszCmd, "FROM_HANDLE"))
+ {
+ char *pszUser = strdup(pEntry->pszAuthor?pEntry->pszAuthor:pEntry->pszUser), *p, *pszRealUser=pszUser;
+
+ if (p=strtok(pszUser, ";"))
+ {
+ if (!(pszRealUser=strtok(NULL, ";"))) pszRealUser=p;
+ }
+ Send (pInst, "%s %d %s %s", pszMessage, pEntry->hdr.uMsgNr, pszCmd, pszRealUser);
+ free (pszUser);
+ }
+ else if (!strcasecmp (pszCmd, "PARTNER_DISPNAME"))
+ Send (pInst, "%s %d PARTNER_DISPNAME %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->pszAlias);
+ else if (!strcasecmp (pszCmd, "TYPE"))
+ Send (pInst, "%s %d TYPE %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->szType);
+ else if (!strcasecmp (pszCmd, "STATUS"))
+ Send (pInst, "%s %d STATUS %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->szStatus);
+ else if (!strcasecmp (pszCmd, "FAILUREREASON"))
+ Send (pInst, "%s %d FAILUREREASON %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->szFailure);
+ else if (!strcasecmp (pszCmd, "BODY"))
+ Send (pInst, "%s %d BODY %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->pszMessage);
+ else if (!strcasecmp (pszCmd, "CHATNAME"))
+ {
+ if (pEntry->pszAuthor || !pEntry->pszMessage || strchr(pEntry->pszUser, ';')) // Groupchat
+ {
+ char *pszUser = strdup(pEntry->pszUser), *p;
+
+ if (p=strchr(pszUser, ';')) p[1]=0;
+ Send (pInst, "%s %d CHATNAME %s", pszMessage, pEntry->hdr.uMsgNr, pszUser);
+ free (pszUser);
+ }
+ else
+ Send (pInst, "%s %d CHATNAME #%s/$%s", pszMessage, pEntry->hdr.uMsgNr, pInst->myUser.pszUser, pEntry->pszUser);
+ }
+ else if (!strcasecmp (pszCmd, "USERS"))
+ {
+ // On KICK, this is the user who GOT kicked
+ char *pszUser = strchr(pEntry->pszUser, ';');
+ if (pszUser) pszUser++; else pszUser=pEntry->pszUser;
+ Send (pInst, "%s %d USERS %s", pszMessage, pEntry->hdr.uMsgNr, pszUser);
+ }
+ else
+ Send (pInst, "ERROR 10 Invalid property / not implemented");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "PRIVILEGE") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")) ||
+ (strcasecmp (pszCmd, "SKYPEOUT") &&
+ strcasecmp (pszCmd, "SKYPEIN") &&
+ strcasecmp (pszCmd, "VOICEMAIL")))
+ {
+ Send (pInst, "ERROR 40 Unknown Privilege");
+ return;
+ }
+ Send (pInst, "PRIVILEGE %s FALSE", pszCmd);
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CHAT") == 0)
+ {
+ char *pszChat;
+ NICKENTRY *pChat=NULL;
+
+ // A $ sign is in the name of a dialog, otherwise it's a groupchat ID
+ if (!(pszChat = strtok(NULL, " ")) ||
+ (!strchr(pszChat, '$') && !(pChat=BuddyList_Find(pInst->hBuddyList, pszChat))))
+ {
+ Send (pInst, "ERROR 14 Invalid message id");
+ return;
+ }
+
+
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+
+ if (strcasecmp(pszCmd, "NAME") == 0)
+ Send (pInst, "CHAT %s NAME %s", pszChat, pszChat);
+ else if (strcasecmp(pszCmd, "STATUS") == 0)
+ // A $ sign is in the name of a dialog, otherwise it's a groupchat ID
+ Send (pInst, "CHAT %s STATUS %s", pszChat, pChat?"MULTI_SUBSCRIBED":"LEGACY_DIALOG");
+ else if (strcasecmp(pszCmd, "ADDER") == 0)
+ Send (pInst, "CHAT %s ADDER %s", pszChat, pInst->myUser.pszUser);
+ else if (strcasecmp(pszCmd, "TYPE") == 0)
+ Send (pInst, "CHAT %s TYPE %s", pszChat, pChat?"MULTICHAT":"DIALOG");
+ else if (strcasecmp(pszCmd, "MYROLE") == 0)
+ Send (pInst, "CHAT %s MYROLE USER", pszChat);
+ else if (strcasecmp(pszCmd, "MYSTATUS") == 0)
+ Send (pInst, "CHAT %s MYSTATUS SUBSCRIBED", pszChat);
+ else if ((strcasecmp(pszCmd, "TOPIC") == 0 || strcasecmp(pszCmd, "FRIENDLYNAME") == 0) && pChat)
+ Send (pInst, "CHAT %s %s %s", pszChat, pszCmd, pChat->pszDisplay);
+ else if ((strcasecmp(pszCmd, "ACTIVEMEMBERS") == 0 || strcasecmp(pszCmd, "MEMBERS") == 0) && pChat)
+ {
+ char szMembers[1024]={0};
+ int i, nCount, iOffs=0;
+
+ iOffs = sprintf (szMembers, "CHAT %s %s ", pszChat, pszCmd);
+ for (i=0, nCount=List_Count(pChat->hGCMembers); i<nCount; i++)
+ {
+ NICKENTRY *pMemb = (NICKENTRY*)List_ElementAt (pChat->hGCMembers, i);
+ char szUser[512], *pTok;
+
+ if (i) iOffs+=sprintf(&szMembers[iOffs], " ");
+ strcpy (szUser, pMemb->pszUser);
+ pTok=strtok(szUser, ";");
+ pTok=strtok(NULL, ";");
+ iOffs+=sprintf(&szMembers[iOffs], "%s", pTok);
+ if (iOffs+6>=sizeof(szMembers)) break;
+ }
+ Send (pInst, szMembers);
+ }
+ else
+ Send(pInst, "ERROR 7 Invalid property / not implemented");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CALL") == 0)
+ {
+ CALLENTRY *pEntry;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pEntry = CallQueue_Find(pInst->hCallQueue, atol(pszCmd))))
+ {
+ Send (pInst, "ERROR 11 Invalid call id");
+ return;
+ }
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+ if (!strcasecmp (pszCmd, "TIMESTAMP"))
+ Send (pInst, "CALL %d TIMESTAMP %ld", pEntry->hdr.uMsgNr, pEntry->timestamp);
+ else if (!strcasecmp (pszCmd, "PARTNER_HANDLE"))
+ Send (pInst, "CALL %d PARTNER_HANDLE %s", pEntry->hdr.uMsgNr, pEntry->pszUser);
+ else if (!strcasecmp (pszCmd, "PARTNER_DISPNAME"))
+ {
+ NICKENTRY *pNick = BuddyList_Find (pInst->hBuddyList, pEntry->pszUser);
+
+ if (pNick)
+ Send (pInst, "CALL %d PARTNER_DISPNAME %s", pEntry->hdr.uMsgNr, pNick->pszAlias);
+ }
+ else if (!strcasecmp (pszCmd, "CONF_ID"))
+ Send (pInst, "CALL %d CONF_ID 0", pEntry->hdr.uMsgNr);
+ else if (!strcasecmp (pszCmd, "TYPE"))
+ Send (pInst, "CALL %d TYPE %s", pEntry->hdr.uMsgNr, pEntry->iDirection==CALL_INCOMING?"INCOMING_P2P":"OUTGOING_P2P");
+ else if (!strcasecmp (pszCmd, "STATUS"))
+ Send (pInst, "CALL %d STATUS %s", pEntry->hdr.uMsgNr, pEntry->szStatus);
+ else if (!strcasecmp (pszCmd, "VIDEO_STATUS"))
+ Send (pInst, "CALL %d VIDEO_STATUS VIDEO_NONE", pEntry->hdr.uMsgNr);
+ else if (!strcasecmp (pszCmd, "VIDEO_SEND_STATUS") || !strcasecmp (pszCmd, "VIDEO_RECEIVE_STATUS"))
+ Send (pInst, "CALL %d %s NOT_AVAILABLE", pEntry->hdr.uMsgNr, pszCmd);
+ else if (!strcasecmp (pszCmd, "FAILUREREASON"))
+ Send (pInst, "CALL %d FAILUREREASON UNKNOWN", pEntry->hdr.uMsgNr);
+ else if (!strcasecmp (pszCmd, "DURATION"))
+ Send (pInst, "CALL %d DURATION 0", pEntry->hdr.uMsgNr);
+ else if (!strcasecmp (pszCmd, "CONF_PARTICIPANTS_COUNT"))
+ Send (pInst, "CALL %d CONF_PARTICIPANTS_COUNT 0", pEntry->hdr.uMsgNr);
+ else
+ Send (pInst, "ERROR 10 Invalid property / not implemented");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "SKYPEVERSION") == 0)
+ {
+ Send (pInst, "SKYPEVERSION 3.8.0.188"); // Fake
+ }
+ else
+ {
+ Send(pInst, "ERROR 7 Invalid property / not implemented");
+ }
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "SET") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 7 Invalid property");
+ return;
+ }
+
+ if (strcasecmp(pszCmd, "USER") == 0)
+ {
+ char *pszUser;
+ NICKENTRY *pUser = NULL;
+
+ if (!(pszUser = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 7 Invalid property");
+ return;
+ }
+
+ pUser = BuddyList_Find(pInst->hBuddyList, pszUser);
+
+ if (strcasecmp(pszCmd, "BUDDYSTATUS") == 0)
+ {
+ int iStatus = -1;
+
+ if (pszCmd = strtok(NULL, " "))
+ iStatus = atoi(pszCmd);
+
+ if (!pUser && iStatus < 2)
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+ if (iStatus == 2 || (iStatus > 2 && !pUser) || iStatus != pUser->iBuddyStatus)
+ {
+ switch (iStatus)
+ {
+ case 1:
+ if (ImoSkype_DelBuddy (pInst->hInst, pUser->pszUser,
+ strcmp(pUser->szStatus, "OFFLINE")?"Skype":"Offline") == 1)
+ pUser->iBuddyStatus = iStatus;
+ break;
+ case 2:
+ case 3:
+ ImoSkype_AddBuddy (pInst->hInst, pszUser);
+ return;
+ default:
+ Send (pInst, "ERROR 518 Invalid status given for BUDDYSTATUS");
+ return;
+ }
+ }
+ Send (pInst, "USER %s BUDDYSTATUS %d", pUser->pszUser, pUser->iBuddyStatus);
+ return;
+ }
+ else if (!pUser)
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+ else
+ {
+ // ISAUTHORIZED
+ Send (pInst, "ERROR 7 Not implemented");
+ }
+ }
+ else
+ if (strcasecmp(pszCmd, "USERSTATUS") == 0)
+ {
+ unsigned int i;
+
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 28 Unknown userstatus");
+ return;
+ }
+
+ if (strcasecmp(pInst->myUser.szStatus, pszCmd))
+ {
+ for (i=0; i<sizeof(m_stMap)/sizeof(m_stMap[0]); i++)
+ {
+ if (!strcasecmp(m_stMap[i].pszSkypeStat, pszCmd))
+ {
+ pInst->tSetMoodText = 0;
+ if (ImoSkype_SetStatus(pInst->hInst, m_stMap[i].pszImoStat,
+ pInst->myUser.pszStatusText?pInst->myUser.pszStatusText:"")>0)
+ strcpy (pInst->myUser.szStatus, pszCmd);
+ Send (pInst, "USERSTATUS %s", pInst->myUser.szStatus);
+ break;
+ }
+ }
+ if (i==sizeof(m_stMap)/sizeof(m_stMap[0]))
+ Send (pInst, "ERROR 28 Unknown userstatus");
+ } else Send (pInst, "USERSTATUS %s", pInst->myUser.szStatus);
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "MESSAGE") == 0 || strcasecmp(pszCmd, "CHATMESSAGE") == 0)
+ {
+ MSGENTRY *pEntry;
+ char *pszMessage = pszCmd;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pEntry = MsgQueue_Find(pInst->hMsgQueue, atol(pszCmd))))
+ {
+ Send (pInst, "ERROR 14 Invalid message id");
+ return;
+ }
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+ if (!strcasecmp (pszCmd, "SEEN"))
+ {
+ strcpy (pEntry->szStatus, "READ");
+ Send (pInst, "%s %d STATUS %s", pszMessage, pEntry->hdr.uMsgNr, pEntry->szStatus);
+ }
+ else
+ Send (pInst, "ERROR 10 Invalid property / not implemented");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CALL") == 0)
+ {
+ CALLENTRY *pEntry;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pEntry = CallQueue_Find(pInst->hCallQueue, atol(pszCmd))))
+ {
+ Send (pInst, "ERROR 11 Invalid call id");
+ return;
+ }
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+ if (!strcasecmp (pszCmd, "STATUS"))
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 21 Unknown/disallowed call prop");
+ return;
+ }
+ strcpy (pEntry->szStatus, pszCmd);
+ Send (pInst, "CALL %d STATUS %s", pEntry->hdr.uMsgNr, pEntry->szStatus);
+
+ // {RINGING, INPROGRESS, ONHOLD, FINISHED}
+ if (pInst->iFlags & IMO2S_FLAG_ALLOWINTERACT)
+ {
+ if (strcasecmp (pEntry->szStatus, "INPROGRESS") == 0 && pEntry->iDirection == CALL_INCOMING)
+ {
+ StartCallSWF (pInst, pEntry);
+ }
+ else
+ if (strcasecmp (pEntry->szStatus, "FINISHED") == 0 && pEntry->hCallWnd)
+ {
+ if (*pEntry->szCallFile)
+ {
+ unlink(pEntry->szCallFile);
+ *pEntry->szCallFile=0;
+ }
+#ifdef WIN32
+ if (pEntry->hCallWnd)
+ {
+ W32Browser_CloseWindow (pEntry->hCallWnd);
+ pEntry->hCallWnd = NULL;
+ }
+#endif
+
+ // On incoming call, hang up
+ }
+ }
+
+ // Currently we don't support calls, just hang up
+ /* FIXME: Hangup! */
+ return;
+ }
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "PROFILE") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 10 Invalid property");
+ return;
+ }
+
+ if (!strcasecmp (pszCmd, "MOOD_TEXT"))
+ {
+ if (!pInst->myUser.pszStatusText ||
+ strcasecmp(pInst->myUser.pszStatusText, pszCmd+10))
+ {
+ time_t t;
+ // Delay setting of MOOD_TEXT, as next command in chain may change online status
+ // and we want to prevent double calls
+ // The polling-thread will take care of this event
+ pInst->tSetMoodText = time(&t)+15;
+ if (pInst->myUser.pszStatusText) free (pInst->myUser.pszStatusText);
+ pInst->myUser.pszStatusText = strdup (pszCmd+10);
+ }
+ }
+ else
+ {
+ Send (pInst, "ERROR 552 Invalid property");
+ return;
+ }
+ }
+ else
+ {
+ Send (pInst, "ERROR 7 Invalid property");
+ return;
+ }
+ }
+ else
+ if (strcasecmp(pszCmd, "MESSAGE") == 0 || strcasecmp(pszCmd, "CHATMESSAGE") == 0)
+ {
+ NICKENTRY *pUser;
+ unsigned int uMsgId;
+ MSGENTRY *pMsg;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pUser = BuddyList_Find(pInst->hBuddyList, pszCmd)))
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+ pszCmd+=strlen(pszCmd)+1;
+ if (!*pszCmd)
+ {
+ Send (pInst, "ERROR 43 Cannot send empty message");
+ return;
+ }
+ if (!(pMsg = MsgQueue_AddSent (pInst->hMsgQueue, pUser->pszUser, pUser->pszAlias, pszCmd, &uMsgId)))
+ {
+ Send (pInst, "ERROR 9901 Internal error");
+ return;
+ }
+ if (IMO_API_VERSION == 0) Send (pInst, "MESSAGE %d STATUS SENDING", uMsgId);
+ if (ImoSkype_SendMessage(pInst->hInst, pUser->pszUser, pszCmd, &pMsg->uRqId)>0)
+ {
+ if (IMO_API_VERSION == 0) strcpy (pMsg->szStatus, "SENT");
+ }
+ else
+ {
+ strcpy (pMsg->szStatus, "FAILED");
+ strncpy (pMsg->szFailure, ImoSkype_GetLastError(pInst->hInst), sizeof(pMsg->szFailure));
+ }
+ Send (pInst, "MESSAGE %d STATUS %s", uMsgId, pMsg->szStatus);
+ }
+ else
+ if (strcasecmp(pszCmd, "CHAT") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 536 CREATE: no object or type given");
+ return;
+ }
+ if (strcasecmp(pszCmd, "CREATE") == 0)
+ {
+ char szName[128]; // No name given here, so make up a name
+ time_t t;
+
+ time(&t);
+ sprintf (szName, "%d", t);
+ if (ImoSkype_CreateSharedGroup(pInst->hInst, szName)<1) return;
+
+ // Now buddy_added should be called which gives us the ID of the new groupchat
+ // where we can then add members to. However this is not known here yet, so feed
+ // list with users to add to instance and let it be processed by buddy_added handler
+ if (pszCmd = strtok(NULL, "\n"))
+ {
+ if (pInst->pszBuddiesToAdd) free(pInst->pszBuddiesToAdd);
+ pInst->pszBuddiesToAdd = strdup(pszCmd);
+ }
+ }
+ else
+ Send (pInst, "ERROR 503 CHAT: Invalid or unknown action");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CALL") == 0)
+ {
+ NICKENTRY *pUser;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pUser = BuddyList_Find(pInst->hBuddyList, pszCmd)))
+ {
+ Send (pInst, "ERROR 26 Invalid user handle");
+ return;
+ }
+
+ ImoSkype_StartVoiceCall (pInst->hInst, pUser->pszUser);
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "OPEN") == 0)
+ {
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "CREATE") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 536 CREATE: no object or type given");
+ return;
+ }
+ if (strcasecmp(pszCmd, "APPLICATION") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")) || strcasecmp(pszCmd, "libpurple_typing"))
+ Send (pInst, "ERROR 540 CREATE APPLICATION: Missing or invalid name");
+ else
+ Send (pInst, "CREATE APPLICATION libpurple_typing");
+ }
+ else
+ Send (pInst, "ERROR 537 CREATE: Unknown object type given");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "DELETE") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 538 DELETE: no object or type given");
+ return;
+ }
+ if (strcasecmp(pszCmd, "APPLICATION") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")) || strcasecmp(pszCmd, "libpurple_typing"))
+ Send (pInst, "ERROR 542 DELETE APPLICATION: Missing or invalid application name");
+ else
+ Send (pInst, "DELETE APPLICATION libpurple_typing");
+ }
+ else
+ Send (pInst, "ERROR 539 DELETE: Unknown object type given");
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "ALTER") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")))
+ Send (pInst, "ERROR 526 ALTER: no object type given");
+ else
+ {
+ if (strcasecmp(pszCmd, "APPLICATION") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")) || strcasecmp(pszCmd, "libpurple_typing") ||
+ !(pszCmd = strtok(NULL, " ")))
+ Send (pInst, "ERROR 545 ALTER: missing or invalid action");
+ else
+ {
+ NICKENTRY *pUser;
+
+ if (strcasecmp (pszCmd, "CONNECT") == 0)
+ {
+ if (!(pszCmd = strtok(NULL, " ")) || !(pUser = BuddyList_Find(pInst->hBuddyList, pszCmd)))
+ Send (pInst, "ERROR 547 ALTER APPLICATION CONNECT: Invalid user handle");
+ else
+ {
+ Send (pInst, "ALTER APPLICATION libpurple_typing CONNECT %s", pszCmd);
+ Send (pInst, "APPLICATION CONNECTING %s", pszCmd);
+ Send (pInst, "APPLICATION libpurple_typing STREAMS %s:1", pszCmd);
+ // FIXME: Shouldn't we enumerate all STREAMS here? dunno...
+ }
+ } else
+ if (strcasecmp (pszCmd, "DATAGRAM") == 0)
+ {
+ char *pSep;
+
+ if (!(pszCmd = strtok(NULL, " ")) || !(pSep = strchr(pszCmd, ':')))
+ Send (pInst, "ERROR 551 ALTER APPLICATION DATAGRAM: Missing or invalid stream identifier");
+ else
+ {
+ *pSep=0;
+ if (!(pUser = BuddyList_Find(pInst->hBuddyList, pszCmd)))
+ Send (pInst, "ERROR 551 ALTER APPLICATION DATAGRAM: Missing or invalid stream identifier");
+ else
+ {
+ *pSep=':';
+ if (!(pszCmd = strtok(NULL, " ")))
+ Send (pInst, "ERROR 541 APPLICATION: Operation failed");
+ else
+ {
+ if (!strcmp (pszCmd, "PURPLE_TYPING"))
+ ImoSkype_Typing (pInst->hInst, pUser->pszUser, "typing");
+ else if (!strcmp (pszCmd, "PURPLE_TYPED"))
+ ImoSkype_Typing (pInst->hInst, pUser->pszUser, "typed");
+ else if (!strcmp (pszCmd, "PURPLE_NOT_TYPING"))
+ ImoSkype_Typing (pInst->hInst, pUser->pszUser, "not_typing");
+ }
+ }
+ }
+ }
+ }
+
+ }
+ else
+ if (strcasecmp(pszCmd, "CHAT") == 0)
+ {
+ char *pszChat;
+ NICKENTRY *pChat;
+
+ if (!(pszChat = strtok(NULL, " ")) ||
+ !(pChat=BuddyList_Find(pInst->hBuddyList, pszChat)))
+ {
+ Send (pInst, "ERROR 14 Invalid message id");
+ return;
+ }
+
+
+ if (!(pszCmd = strtok(NULL, " ")))
+ {
+ Send (pInst, "ERROR 503 CHAT: Invalid or unknown action");
+ return;
+ }
+
+ if (strcasecmp (pszCmd, "ADDMEMBERS") == 0)
+ {
+ while(pszCmd = strtok(NULL, ", "))
+ {
+ ImoSkype_GroupInvite (pInst->hInst, pChat->pszUser, pszCmd);
+ }
+ }
+ else if (strcasecmp (pszCmd, "KICK") == 0)
+ {
+ while(pszCmd = strtok(NULL, ", "))
+ {
+ ImoSkype_GroupKick (pInst->hInst, pChat->pszUser, pszCmd);
+ }
+ }
+ else if (strcasecmp (pszCmd, "SETTOPIC") == 0)
+ {
+ if(pszCmd = strtok(NULL, ""))
+ {
+ ImoSkype_GroupTopic (pInst->hInst, pChat->pszUser, pszCmd);
+ }
+ }
+ else if (strcasecmp (pszCmd, "LEAVE") == 0)
+ {
+ if(pszCmd = strtok(NULL, ""))
+ {
+ ImoSkype_GroupLeave (pInst->hInst, pChat->pszUser);
+ }
+ }
+ else Send (pInst, "ERROR 503 CHAT: Invalid or unknown action");
+ } else
+ Send (pInst, "ERROR 527 ALTER: unknown object type given");
+ }
+ return;
+ }
+ else
+ if (strcasecmp(pszCmd, "NAME") == 0)
+ {
+ if (pszCmd = strtok(NULL, " "))
+ {
+ if (pInst->pszClientName) free(pInst->pszClientName);
+ pInst->pszClientName = strdup(pszCmd);
+ }
+ Send (pInst, "OK");
+ return;
+ }
+ else
+ {
+ Send (pInst, "ERROR 2 Not Implemented");
+ }
+}
+
+// -----------------------------------------------------------------------------
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.h
new file mode 100644
index 0000000000..fa68dd3899
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2skypeapi.h
@@ -0,0 +1,13 @@
+typedef void(*IMO2SCB)(char *pszMsg, void *pUser);
+struct _tagIMOSAPI;
+typedef struct _tagIMOSAPI IMOSAPI;
+
+#define IMO2S_FLAG_CURRTIMESTAMP 1 // Use current timestamp on MSG receive
+#define IMO2S_FLAG_ALLOWINTERACT 2 // Allow GUI interaction (CALL)
+
+IMOSAPI *Imo2S_Init(IMO2SCB Callback, void *pUser, int iFlags);
+void Imo2S_Exit (IMOSAPI *pInst);
+void Imo2S_SetLog (IMOSAPI *pInst, FILE *fpLog);
+int Imo2S_Login (IMOSAPI *pInst, char *pszUser, char *pszPass, char **ppszError);
+void Imo2S_Logout(IMOSAPI *pInst);
+int Imo2S_Send (IMOSAPI *pInst, char *pszMsg);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.c
new file mode 100644
index 0000000000..1615d6ac46
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.c
@@ -0,0 +1,78 @@
+/* Module: imo2skypeproxy.c
+ Purpose: Implementation of imo2skype API as Skype proxy (for Miranda Skype plugin)
+ Author: leecher
+ Date: 01.09.2009
+
+ Changelog:
+ 1.00 - 01.09.2009 - Initial release
+ 1.01 - 02.09.2009 - Little bugfix for Onlinestatus, introduced mutex for send thread.
+ 1.02 - 02.09.2009 - Added support for incoming call notifications and expired sessions.
+ 1.03 - 03.09.2009 - As WIN32-port of libcurl is a total mess, Win32-version now uses WinINET.
+ 1.04 - 04.09.2009 - Added support for searching, adding and removing buddies
+ 1.05 - 06.09.2009 - * Mapped "busy" to DND, not NA, as forum user AL|EN proposed.
+ * Mood text will now also be sent on status change of a contact
+ (doesn't really have an effect though)
+ * New Parameter -d (daemonize) to launch proxy in background
+ * Fixed a bug with a crash when encoding umlauts on Win32
+ 1.06 - 25.09.2009 - Added parameter -t for local timestamps.
+ 1.07 - 07.10.2009 - Bugfix: Added parsing of multiple JSON messages
+ Added support for writing to logfile while in daemon mode (-l)
+ 1.08 - 18.10.2009 - Added support for voice calls via imo.im flash on WIN32 (-i)
+ - Limited memory queues to 50 entries to reduce memory usage.
+ 1.09 - 07.11.2009 - Split command line main module and proxy module to make proxy
+ accessible by different layers (i.e. new Miranda Plugin layer)
+ 1.10 - 14.12.2009 - Bug in the cJson library. The authors used the String as second
+ sprintf-Parameter which contains the format string instead of
+ ["%s", StringParam] causing problems sending Messages containt a %
+ - Added some space in the dialog for translations and added Translate()
+ function to some strings in the Wrapper-DLL
+ - More verbose output if you enable logging
+ - Fixes a Bug that caused the plugin to block after going offline
+ and reconnecting back online
+ - Hopefully fixed a severe threading problem: The Send-Mutex was not
+ covering a full transaction, but only 1 send causing the receiver
+ the receive garbled data causing "An existing connection was forcibly
+ closed by the remote host." error.
+ - Imo2S_Exit freed the temporary buffer too early resulting in a crash
+ on exit.
+ 1.12 - 19.04.2010 - POST interface changed from www.imo.im/amy to s.imo.im/amy
+ 1.13 - 19.12.2010 - imo.im modified their interface, so tried to adapt the communication
+ routines at low level to be compatible again. There still may be
+ many bugs. Don't forget to turn off history logging in the options
+ at https://imo.im
+ There also seems to be a nice new feature called "reflection" so that
+ you can login from multiple sessions and messages etc. entered there
+ will be reflected to the current session. This may be addressed in one
+ of the next builds...
+ 1.14 - 02.03.2011 - Added a Skype WIN32-API Emulation Layer for better compatibility with
+ other clients that don't want to implement the socks-protocol, so that
+ we are compatible out-of-the-box.
+ - Added a few features to be compatible with libpurple. i.e. we now support
+ message numbering, even tough this is only supported in PROTOCOL 4.
+ - Added Keepalive packet sending to circumvent imo.im AutoAway.
+ 1.15 - 18.07.2012 - Avatar support
+ - Support for new imo.im protocol, can now be compiled to use old or new
+ protocol, in case there are troubles. New protocol enables participation
+ in groupchats generated with native Skype client with at least 3
+ participants (still a bit experimental)
+ - WININET HTTPS communication layer now uses async calls to try to prevent
+ lockups on connection loss.
+*/
+
+#include <memory.h>
+#include "imo2sproxy.h"
+
+// -----------------------------------------------------------------------------
+// PUBLIC
+// -----------------------------------------------------------------------------
+
+void Imo2sproxy_Defaults (IMO2SPROXY_CFG *pCfg)
+{
+ memset (pCfg, 0, sizeof(IMO2SPROXY_CFG));
+ pCfg->fpLog = stdout;
+ pCfg->logerror = fprintf;
+}
+
+/* Real implementation is now in socksproxy.c for the socket communication method
+ and in w32skypeemu.c for the Window messages Skype emulation
+ */
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.h
new file mode 100644
index 0000000000..dbdbbf1cf7
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2sproxy.h
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include "imo2skypeapi.h"
+#ifndef WIN32
+#define __cdecl
+#endif
+
+typedef struct
+{
+ int bVerbose;
+ FILE *fpLog;
+ int iFlags;
+ int (__cdecl *logerror)( FILE *stream, const char *format, ...);
+// FIXME: user+pass from cmdline, until there is a possibility for
+// a client to authenticate
+ char *pszUser;
+ char *pszPass;
+} IMO2SPROXY_CFG;
+
+typedef struct tag_imo2sproxy IMO2SPROXY;
+
+struct tag_imo2sproxy
+{
+ int (*Open)(IMO2SPROXY*);
+ void (*Loop)(IMO2SPROXY*);
+ void (*Exit)(IMO2SPROXY*);
+};
+
+void Imo2sproxy_Defaults (IMO2SPROXY_CFG *pCfg);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2stest.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2stest.c
new file mode 100644
index 0000000000..3007e3ce06
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/imo2stest.c
@@ -0,0 +1,60 @@
+/* Module: imo2stest.c
+ Purpose: Simple test application for imo2skypeapi
+ Author: leecher
+ Date: 31.08.2009
+*/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "imo2skypeapi.h"
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+static void Recv(char *pszMsg, void *pUser)
+{
+ printf ("< %s\n", pszMsg);
+}
+
+// -----------------------------------------------------------------------------
+// EIP
+// -----------------------------------------------------------------------------
+int main(int argc, char **argv)
+{
+ int iRet = -1;
+ IMOSAPI *pInst;
+ char *pszError = NULL;
+
+ if (argc<3)
+ {
+ printf ("Usage: %s [username] [password]\n", argv[0]);
+ return -1;
+ }
+
+ if (!(pInst = Imo2S_Init(Recv, NULL,0)))
+ {
+ fprintf (stderr, "Failed initialization.\n");
+ return -1;
+ }
+
+ /* Logon */
+ if (Imo2S_Login(pInst, argv[1], argv[2], &pszError) == 1)
+ {
+ /* Dispatch loop */
+ char szLine[4096]={0};
+
+ while (gets(szLine))
+ {
+ Imo2S_Send (pInst, szLine);
+ memset (szLine, 0, sizeof(szLine));
+ }
+ }
+ else
+ {
+ fprintf (stderr, "Login failed: %s\n", pszError);
+ return -1;
+ }
+
+ Imo2S_Exit (pInst);
+ return iRet;
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/main.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/main.c
new file mode 100644
index 0000000000..872509616d
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/main.c
@@ -0,0 +1,197 @@
+/* Module: main.c
+ Purpose: Main commandline dispatcher for imo.im Skypeproxy
+ Author: leecher
+ Date: 07.11.2009
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include "imo2sproxy.h"
+#include "socksproxy.h"
+#ifdef WIN32
+#include "w32skypeemu.h"
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#define Daemonize FreeConsole()
+#ifdef _DEBUG
+#define LOG(_args_) printf _args_
+#ifndef _WIN64
+#include "crash.c"
+#endif
+#endif
+#else
+#define Daemonize daemon(0, 0)
+#endif
+
+// -----------------------------------------------------------------------------
+// EIP
+// -----------------------------------------------------------------------------
+int main(int argc, char **argv)
+{
+ int i, j=0, bDaemon = 0;
+ char cMode='s';
+ IMO2SPROXY_CFG stCfg;
+ SOCKSPROXY_CFG stSocksCfg;
+#ifdef WIN32
+ W32SKYPEEMU_CFG stSypeEmuCfg;
+#endif
+ IMO2SPROXY *pProxy;
+
+#ifdef _DEBUG
+ Crash_Init();
+#endif
+
+ Imo2sproxy_Defaults (&stCfg);
+ SocksProxy_Defaults (&stSocksCfg);
+#ifdef WIN32
+ W32SkypeEmu_Defaults(&stSypeEmuCfg);
+#endif
+ if (argc<3)
+ {
+ printf ("imo.im Skypeproxy V1.15 - (c) by leecher 2009-2012\n\n"
+ "%s [-d] [-v [-l <Logfile>]] [-t] [-i]\n"
+ "[-m<s|a>] [-h <Bind to IP>] [-p <Port>] <Username> <Password>\n\n"
+ "-d\t- Daemonize (detach from console)\n"
+ "-v\t- Verbose mode, log commands to console\n"
+ "-l\t- Set logfile to redirect verbose log to.\n"
+ "-t\t- Ignore server timestamp and use current time for messages\n"
+ "-i\t- Use interactive mode (starts imo.im flash app upon call)\n"
+ "-m\t- Specify connection mode to use:\n"
+ "\t\ts\tSocket mode (SkypeProxy protocol) [default]\n"
+#ifdef WIN32
+ "\t\ta\tSkype API Emulation via Window messages (real Skype API)\n"
+#endif
+ "\tParameters for socket mode:\n"
+ "-h\t- Bind to a specific IP, not to all interfaces (default)\n"
+ "-p\t- Bind to another port (default: 1401)\n"
+ "Default: Bind to any interface, Use Port %d\n", argv[0], stSocksCfg.sPort);
+ return EXIT_FAILURE;
+ }
+
+ for (i=1; i<argc; i++)
+ {
+ if (argv[i][0] == '-')
+ {
+ switch (argv[i][1])
+ {
+ case 'v':
+ stCfg.bVerbose = 1;
+ break;
+ case 'l':
+ if (argc<=i+1)
+ {
+ fprintf (stderr, "Please specify logfile for -l\n");
+ return EXIT_FAILURE;
+ }
+ if (!(stCfg.fpLog = fopen(argv[++i], "a")))
+ {
+ fprintf (stderr, "Cannot open logfile %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ break;
+ case 'd':
+ bDaemon = 1;
+ break;
+ case 'h':
+ if (argc<=i+1)
+ {
+ fprintf (stderr, "Please specify bind IP for -h\n");
+ return EXIT_FAILURE;
+ }
+ stSocksCfg.lAddr = inet_addr(argv[++i]);
+ break;
+ case 'p':
+ if (argc<=i+1)
+ {
+ fprintf (stderr, "Please specify port for -p\n");
+ return EXIT_FAILURE;
+ }
+ stSocksCfg.sPort = atoi(argv[++i]);
+ break;
+ case 't':
+ stCfg.iFlags |= IMO2S_FLAG_CURRTIMESTAMP;
+ break;
+ case 'i':
+ stCfg.iFlags |= IMO2S_FLAG_ALLOWINTERACT;
+ break;
+ case 'm':
+ switch (argv[i][2])
+ {
+ case 'a':
+#ifndef WIN32
+ fprintf (stderr, "This mode is not available on your platform!\n");
+ return EXIT_FAILURE;
+#endif
+ case 's':
+ cMode=argv[i][2];
+ break;
+ default:
+ fprintf (stderr, "Unknown mode: %c\n", argv[i][2]);
+ return EXIT_FAILURE;
+ }
+ break;
+ default:
+ printf ("Unknown parameter: %s\n", argv[i]);
+ break;
+ }
+ }
+ else
+ {
+ switch (j)
+ {
+ case 0: stCfg.pszUser = argv[i]; break;
+ case 1: stCfg.pszPass = argv[i]; break;
+ default: printf ("Unknown extra arg: %s\n", argv[i]); break;
+ }
+ j++;
+ }
+ }
+
+ if (!stCfg.pszUser)
+ {
+ fprintf (stderr, "Please specify Username\n");
+ return EXIT_FAILURE;
+ }
+ if (!stCfg.pszPass)
+ {
+ fprintf (stderr, "Please specify Password\n");
+ return EXIT_FAILURE;
+ }
+ if (bDaemon && stCfg.bVerbose && stCfg.fpLog == stdout)
+ {
+ printf ("Parameters Verbose mode and daemonize cannot be used together, if you don't\n"
+ "specify a logfile, not daemonizing.\n");
+ bDaemon = 0;
+ }
+ if (bDaemon) Daemonize;
+
+ switch (cMode)
+ {
+ case 's':
+ if (!(pProxy = SocksProxy_Init (&stCfg, &stSocksCfg)))
+ return EXIT_FAILURE;
+ break;
+ case 'a':
+#ifdef WIN32
+ if (!(pProxy = W32SkypeEmu_Init (&stCfg, &stSypeEmuCfg)))
+ return EXIT_FAILURE;
+#else
+ fprintf (stderr, "Skype API EMulator is only available in WIN32\n");
+ return EXIT_FAILURE;
+#endif
+ break;
+ }
+
+ if (pProxy->Open(pProxy) == 0)
+ pProxy->Loop(pProxy);
+ pProxy->Exit(pProxy);
+
+ if (stCfg.fpLog && stCfg.fpLog != stdout && stCfg.fpLog != stderr)
+ {
+ fclose(stCfg.fpLog);
+ stCfg.fpLog = NULL;
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/imoproxy.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/imoproxy.c
new file mode 100644
index 0000000000..195f479ea6
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/imoproxy.c
@@ -0,0 +1,882 @@
+/* Module: imoproxy.c
+ Purpose: Proxy-DLL for Miranda IM to load imo2sproxy as plugin
+ Author: leecher
+ Date: 26.10.2009
+*/
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#include <prsht.h>
+#include <commdlg.h>
+#include <stdlib.h>
+#include <io.h>
+#include <fcntl.h>
+#include <process.h>
+#pragma comment (lib, "Ws2_32.lib")
+#include <stdio.h>
+#include "io_layer.h"
+#include "imo2sproxy.h"
+#include "imo_request.h"
+#include "socksproxy.h"
+#include "w32skypeemu.h"
+#include "skypepluginlink.h"
+#include "include/newpluginapi.h"
+#include "include/m_langpack.h"
+#include "include/m_options.h"
+#include "include/m_database.h"
+#include "include/m_system.h"
+#include "sdk/m_updater.h"
+#include "resource.h"
+
+// Crash dumper
+#ifdef _DEBUG
+void CrashLog (const char *pszFormat, ...)
+{
+ static FILE *fpLog = NULL;
+ char szLine[1024];
+ va_list ap;
+
+ if (!fpLog) fpLog=fopen("imoproxy.log", "a");
+ va_start(ap, pszFormat);
+ _vsnprintf(szLine, sizeof(szLine), pszFormat, ap);
+ va_end(ap);
+
+ if (fpLog)
+ {
+ fprintf (fpLog, "%s", szLine);
+ fflush (fpLog);
+ }
+}
+#define LOG(_args_) CrashLog _args_
+#ifndef _WIN64
+#include "crash.c"
+#endif
+#endif
+
+
+PLUGINLINK *pluginLink;
+HINSTANCE m_hInst;
+static HANDLE m_hOptHook=NULL, m_hPreShutdownHook=NULL, m_hHookModulesLoaded=NULL;
+
+#define PROXY_SOCKS 0
+#define PROXY_W32SKYPEEMU 1
+#define PROXY_SKYPEPLUGIN 2
+#define PROXY_MAX 3
+
+static IMO2SPROXY_CFG m_stCfg;
+static SOCKSPROXY_CFG m_stSocksCfg;
+static W32SKYPEEMU_CFG m_stSypeEmuCfg;
+static SKYPEPLUGINLINK_CFG m_stSkypePluginCfg;
+
+static IMO2SPROXY *m_apProxy[PROXY_MAX] = {0};
+static HANDLE m_hThread[PROXY_MAX]={0}, m_hEvent = INVALID_HANDLE_VALUE;
+static BOOL m_bConsole = FALSE;
+
+#define ANY_SIZE 1
+
+typedef struct _MIB_IPADDRROW {
+ DWORD dwAddr;
+ DWORD dwIndex;
+ DWORD dwMask;
+ DWORD dwBCastAddr;
+ DWORD dwReasmSize;
+ unsigned short unused1;
+ unsigned short wType;
+}MIB_IPADDRROW, *PMIB_IPADDRROW;
+
+typedef struct _MIB_IPADDRTABLE {
+ DWORD dwNumEntries;
+ MIB_IPADDRROW table[ANY_SIZE];
+}MIB_IPADDRTABLE, *PMIB_IPADDRTABLE;
+
+
+// Plugin Info
+#define PINFO \
+ "imo2sproxy-Plugin", \
+ PLUGIN_MAKE_VERSION(1,0,0,15), \
+ "Tunnelling Skype traffic via imo.im Web service", \
+ "leecher", \
+ "leecher@dose.0wnz.at", \
+ "© 2010-2012 leecher", \
+ "http://dose.0wnz.at", \
+ 0, \
+ 0 //doesn't replace anything built-in
+
+
+PLUGININFO pluginInfo = {
+ sizeof(PLUGININFO),
+ PINFO
+};
+
+// New plugininfo
+PLUGININFOEX pluginInfoEx = {
+ sizeof (pluginInfoEx),
+ PINFO,
+ { 0x3005c2b1, 0x4278, 0x470c, { 0x94, 0x98, 0x5, 0x95, 0x3d, 0xfa, 0x4d, 0x88 } } // // {3005C2B1-4278-470c-9498-05953DFA4D88}
+};
+
+// Whatever this is...
+// {95061E8D-B18C-4c1c-8E14-686DE967D851}
+#define MIID_IMOPROXY { 0x95061e8d, 0xb18c, 0x4c1c, { 0x8e, 0x14, 0x68, 0x6d, 0xe9, 0x67, 0xd8, 0x51 } }
+static const MUUID interfaces[] = { MIID_IMOPROXY, MIID_LAST };
+
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+
+int ShowError( FILE *stream, const char *format, ...)
+{
+ char szBuf[1024];
+ va_list ap;
+ int iRet;
+
+ va_start(ap, format);
+ iRet = _vsnprintf (szBuf, sizeof(szBuf), format, ap);
+ va_end(ap);
+
+ MessageBox (NULL, szBuf, Translate("IMOPROXY Error"), MB_ICONSTOP | MB_OK);
+ return iRet;
+}
+
+// -----------------------------------------------------------------------------
+
+static void LoadSettings(void)
+{
+ DBVARIANT dbv;
+
+ // General config
+ if (!m_bConsole)
+ {
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Logfile", &dbv)==0)
+ {
+ if ((m_stCfg.bVerbose = DBGetContactSettingByte(NULL, "IMOPROXY", "Verbose", 0)) &&
+ *dbv.pszVal)
+ {
+ if (m_stCfg.fpLog) fclose (m_stCfg.fpLog);
+ if (!(m_stCfg.fpLog = fopen(dbv.pszVal, "a")))
+ {
+ char szMsg[MAX_PATH+64];
+
+ sprintf (szMsg, Translate("Cannot open Logfile %s for writing."), dbv.pszVal);
+ MessageBox(NULL,szMsg,"IMOPROXY", MB_OK | MB_ICONWARNING);
+ m_stCfg.bVerbose = FALSE;
+ }
+ }
+ DBFreeVariant(&dbv);
+ }
+ }
+ m_stCfg.iFlags = DBGetContactSettingDword(NULL, "IMOPROXY", "Flags", 0);
+ if (DBGetContactSetting(NULL, "IMOPROXY", "User", &dbv)==0)
+ {
+ if (m_stCfg.pszUser) free(m_stCfg.pszUser);
+ m_stCfg.pszUser = strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Password", &dbv)==0)
+ {
+ if (m_stCfg.pszPass) free(m_stCfg.pszPass);
+ m_stCfg.pszPass = strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+
+ // Socks Proxy config
+ m_stSocksCfg.sPort = DBGetContactSettingWord(NULL, "IMOPROXY", "Port", 1401);
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Host", &dbv)==0)
+ {
+ m_stSocksCfg.lAddr = inet_addr(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static BOOL CheckSettings(int iMask)
+{
+ DBVARIANT dbv;
+
+ if (iMask & PROXY_SOCKS)
+ {
+ if (DBGetContactSetting(NULL, SKYPE_PROTONAME, "Host", &dbv)==0)
+ {
+ if (DBGetContactSettingByte(NULL, SKYPE_PROTONAME, "UseSkype2Socket", 0) &&
+ (lstrcmp (dbv.pszVal, "127.0.0.1")==0 ||
+ lstrcmp (dbv.pszVal, "localhost")==0) &&
+ DBGetContactSettingWord(NULL, SKYPE_PROTONAME, "Port", 0) ==
+ DBGetContactSettingWord(NULL, "IMOPROXY", "Port", 1401))
+ {
+ DBFreeVariant(&dbv);
+ return TRUE;
+ }
+ DBFreeVariant(&dbv);
+ }
+ }
+ if (DBGetContactSettingByte(NULL, SKYPE_PROTONAME, "FirstRun", 9) == 9)
+ {
+ MessageBox (NULL, Translate("SKYPE plugin may not be installed, this plugin only works together with "
+ "the SKYPE-plugin. Please check if you installed and enabled it."), "IMOPROXY",
+ MB_OK | MB_ICONWARNING);
+ }
+ else
+ {
+
+ if ((iMask & PROXY_SOCKS) && !ServiceExists(SKYPE_PROTONAME PSS_SKYPEAPIMSG) )
+ {
+ if (MessageBox (NULL, Translate("Your Skype plugin currently doesn't seem to be setup to use imo2proxy, "
+ "do you want me to change its settings so that it uses this plugins?"), "IMOPROXY",
+ MB_YESNO | MB_ICONQUESTION) == IDYES)
+ {
+ DBWriteContactSettingByte (NULL, SKYPE_PROTONAME, "UseSkype2Socket", 1);
+ DBWriteContactSettingWord (NULL, SKYPE_PROTONAME, "Port", m_stSocksCfg.sPort);
+ DBWriteContactSettingString (NULL, SKYPE_PROTONAME, "Host", "127.0.0.1");
+ return TRUE;
+ }
+ }
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+static BOOL EnumNetInterfaces (HWND hwndControl)
+{
+ HINSTANCE hLib;
+ BOOL bRet = FALSE;
+
+ if (hLib = LoadLibrary("Iphlpapi.dll"))
+ {
+ PMIB_IPADDRTABLE pTable;
+ ULONG uSize=1;
+ DWORD i;
+ FARPROC GetIpAddrTable;
+
+ if (GetIpAddrTable = (FARPROC)GetProcAddress (hLib, "GetIpAddrTable"))
+ {
+ if ((GetIpAddrTable (&pTable, &uSize, TRUE) == ERROR_INSUFFICIENT_BUFFER) &&
+ (pTable = HeapAlloc (GetProcessHeap(), 0, uSize)))
+ {
+ if (GetIpAddrTable (pTable, &uSize, TRUE) == NO_ERROR)
+ {
+ struct in_addr addr;
+
+ for (i=0; i<pTable->dwNumEntries; i++)
+ {
+ addr.S_un.S_addr = pTable->table[i].dwAddr;
+ SendMessage (hwndControl, CB_ADDSTRING, 0, (LPARAM)inet_ntoa(addr));
+ }
+ bRet = pTable->dwNumEntries > 0;
+ }
+ HeapFree (GetProcessHeap(), 0, pTable);
+ }
+ }
+ FreeLibrary (hLib);
+ }
+ return bRet;
+}
+
+// -----------------------------------------------------------------------------
+
+static DWORD WINAPI ProxyThread(IMO2SPROXY *pProxy)
+{
+ if (pProxy->Open(pProxy)<0) return -1;
+ SetEvent (m_hEvent);
+ pProxy->Loop(pProxy);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+static BYTE GetProxies(void)
+{
+ return DBGetContactSettingByte(NULL, "IMOPROXY", "Proxies",
+ (ServiceExists(SKYPE_PROTONAME PSS_SKYPEAPIMSG)?(1<<PROXY_SKYPEPLUGIN):(1<<PROXY_SOCKS)));
+}
+
+// -----------------------------------------------------------------------------
+
+static BOOL StartProxy (int i)
+{
+ DWORD dwThreadId;
+ BOOL bCreateThread = FALSE, bRet = TRUE;
+ BYTE cEnabled = GetProxies();
+ HANDLE ahEvents[2];
+
+ // Username and Password must me available
+ if (!m_stCfg.pszUser || !*m_stCfg.pszUser ||
+ !m_stCfg.pszPass || !*m_stCfg.pszPass || !(cEnabled&(1<<i)) ) return FALSE;
+
+ // Start the proxy, if enabled
+ switch (i)
+ {
+ case PROXY_SOCKS:
+ if (!(m_apProxy[i]))
+ m_apProxy[i] = SocksProxy_Init (&m_stCfg, &m_stSocksCfg);
+ break;
+ case PROXY_W32SKYPEEMU:
+ if (!(m_apProxy[i]))
+ m_apProxy[i] = W32SkypeEmu_Init (&m_stCfg, &m_stSypeEmuCfg);
+ break;
+ case PROXY_SKYPEPLUGIN:
+ if (!(m_apProxy[i]))
+ m_apProxy[i] = SkypePluginLink_Init (&m_stCfg, &m_stSkypePluginCfg);
+ if (m_apProxy[i]->Open(m_apProxy[i])<0)
+ {
+ m_apProxy[i]->Exit(m_apProxy[i]);
+ return FALSE;
+ }
+ return TRUE;
+ default:
+ return FALSE;
+ }
+ if (!m_apProxy[i]) return FALSE;
+
+ // As for example W32SKYPEEMU runs its own messagepump and the Window is
+ // Registered in the Open-Function (as it can fail), we have to start
+ // our Mainloop-Thread and wait for the Open() part to finish.
+ // If it worked ok, the loop will start to run, otherwise we return
+ // an error. So we need a Mutex for synchronisation.
+ m_hEvent = ahEvents[1] = CreateEvent (NULL, FALSE, FALSE, NULL);
+
+ if (!(m_hThread[i] = ahEvents[0] = (HANDLE)_beginthreadex (NULL, 0, ProxyThread, m_apProxy[i], 0, &dwThreadId)))
+ {
+ MessageBox (NULL, Translate("IMOPROXY Cannot start dispatch thread"), "IMOPROXY", MB_OK | MB_ICONSTOP);
+ CloseHandle (m_hEvent);
+ m_apProxy[i]->Exit(m_apProxy[i]);
+ return FALSE;
+ }
+
+ bRet = WaitForMultipleObjects (2, ahEvents, FALSE, INFINITE)==WAIT_OBJECT_0+1;
+ CloseHandle (m_hEvent);
+ return bRet;
+}
+
+// -----------------------------------------------------------------------------
+
+static void StopProxy (int i)
+{
+ if (m_apProxy[i])
+ {
+ m_apProxy[i]->Exit(m_apProxy[i]);
+ m_apProxy[i] = NULL;
+ }
+
+ if (m_hThread[i])
+ {
+ if (WaitForSingleObject (m_hThread[i], 3000) != WAIT_OBJECT_0)
+ TerminateThread (m_hThread[i], -1);
+ m_hThread[i] = NULL;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static BOOL StartProxies(int iMask)
+{
+ int i;
+ BOOL bRet=TRUE;
+
+ for (i=0; i<PROXY_MAX; i++)
+ if (iMask&(1<<i))
+ bRet &= StartProxy(i);
+ return bRet;
+}
+
+// -----------------------------------------------------------------------------
+
+static void StopProxies(int iMask)
+{
+ int i;
+
+ for (i=0; i<PROXY_MAX; i++)
+ if (iMask&(1<<i))
+ StopProxy(i);
+}
+
+// -----------------------------------------------------------------------------
+
+static void UpdateProxyStatus (HWND hWnd, int iID)
+{
+ struct {
+ UINT uStatus;
+ UINT uStart;
+ UINT uStop;
+ } astStatus[] = {
+ {IDC_STATUSSOCKS, IDC_STARTSOCKS, IDC_STOPSOCKS},
+ {IDC_STATUSCOMM, IDC_STARTCOMM, IDC_STOPCOMM},
+ {IDC_STATUSSKYPEPL, IDC_STARTSKYPEPL, IDC_STOPSKYPEPL}
+ };
+
+ if (m_apProxy[iID])
+ {
+ SetDlgItemText (hWnd, astStatus[iID].uStatus, Translate("Running"));
+ EnableWindow ((HWND)GetDlgItem (hWnd, astStatus[iID].uStart), FALSE);
+ EnableWindow ((HWND)GetDlgItem (hWnd, astStatus[iID].uStop), TRUE);
+ }
+ else
+ {
+ BYTE cEnabled = GetProxies();
+
+ SetDlgItemText (hWnd, astStatus[iID].uStatus, Translate("Stopped"));
+ EnableWindow ((HWND)GetDlgItem (hWnd, astStatus[iID].uStart),
+ ((cEnabled&(1<<iID)) && m_stCfg.pszUser && *m_stCfg.pszUser &&
+ m_stCfg.pszPass && *m_stCfg.pszPass)?TRUE:FALSE);
+ EnableWindow ((HWND)GetDlgItem (hWnd, astStatus[iID].uStop), FALSE);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static int CALLBACK OptionsDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static char szOldHost[64]={0}, szOldLog[MAX_PATH]={0}, szOldUser[64], szOldPass[64];
+ static short sOldPort=0;
+ static BOOL bOldVerbose=FALSE;
+ static int iOldFlags = 0, iOldProxies;
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ {
+ DBVARIANT dbv;
+
+ TranslateDialogDefault(hWnd);
+ EnumNetInterfaces (GetDlgItem (hWnd, IDC_BINDIP));
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Host", &dbv)==0)
+ {
+ lstrcpyn (szOldHost, dbv.pszVal, sizeof(szOldHost));
+ DBFreeVariant(&dbv);
+ } else lstrcpy (szOldHost, "127.0.0.1");
+ SetDlgItemText (hWnd, IDC_BINDIP,szOldHost);
+ SetDlgItemInt (hWnd, IDC_BINDPORT, sOldPort = DBGetContactSettingWord(NULL, "IMOPROXY", "Port", 1401), FALSE);
+ iOldFlags = DBGetContactSettingDword(NULL, "IMOPROXY", "Flags", 0);
+ if (iOldFlags & IMO2S_FLAG_ALLOWINTERACT) CheckDlgButton (hWnd, IDC_INTERACT, BST_CHECKED);
+ if (iOldFlags & IMO2S_FLAG_CURRTIMESTAMP) CheckDlgButton (hWnd, IDC_CURRTIMESTAMP, BST_CHECKED);
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Logfile", &dbv)==0)
+ {
+ lstrcpyn (szOldLog, dbv.pszVal, sizeof(szOldLog));
+ DBFreeVariant(&dbv);
+ }
+ if (CallService (MS_SYSTEM_GETVERSION, 0, 0) >= 0x080000)
+ {
+ EnableWindow (GetDlgItem (hWnd, IDC_USENETLIB), TRUE);
+ if (DBGetContactSettingByte (NULL, "IMOPROXY", "UseNetlib", 0))
+ CheckDlgButton (hWnd, IDC_USENETLIB, BST_CHECKED);
+ }
+ SetDlgItemText (hWnd, IDC_LOGFILE, szOldLog);
+ if (bOldVerbose = DBGetContactSettingByte(NULL, "IMOPROXY", "Verbose", 0))
+ CheckDlgButton (hWnd, IDC_LOG, BST_CHECKED);
+ else
+ {
+ EnableWindow (GetDlgItem (hWnd, IDC_LOGFILE), FALSE);
+ EnableWindow (GetDlgItem (hWnd, IDC_OPEN), FALSE);
+ }
+ if (DBGetContactSetting(NULL, "IMOPROXY", "User", &dbv)==0)
+ {
+ lstrcpyn (szOldUser, dbv.pszVal, sizeof(szOldUser));
+ DBFreeVariant(&dbv);
+ }
+ SetDlgItemText (hWnd, IDC_USERNAME, szOldUser);
+ if (DBGetContactSetting(NULL, "IMOPROXY", "Password", &dbv)==0)
+ {
+ lstrcpyn (szOldPass, dbv.pszVal, sizeof(szOldPass));
+ DBFreeVariant(&dbv);
+ }
+ iOldProxies= GetProxies();
+ CheckDlgButton (hWnd, IDC_USESOCKS, (iOldProxies&(1<<PROXY_SOCKS))?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton (hWnd, IDC_USECOMM, (iOldProxies&(1<<PROXY_W32SKYPEEMU))?BST_CHECKED:BST_UNCHECKED);
+ if (ServiceExists(SKYPE_PROTONAME PSS_SKYPEAPIMSG))
+ {
+ CheckDlgButton (hWnd, IDC_USESKYPEPL, (iOldProxies&(1<<PROXY_SKYPEPLUGIN))?BST_CHECKED:BST_UNCHECKED);
+ UpdateProxyStatus (hWnd, PROXY_SKYPEPLUGIN);
+ }
+ else
+ {
+ EnableWindow (GetDlgItem (hWnd, IDC_USESKYPEPL), FALSE);
+ EnableWindow (GetDlgItem (hWnd, IDC_STARTSKYPEPL), FALSE);
+ }
+ SetDlgItemText (hWnd, IDC_PASSWORD, szOldPass);
+ UpdateProxyStatus (hWnd, PROXY_SOCKS);
+ UpdateProxyStatus (hWnd, PROXY_W32SKYPEEMU);
+#ifdef _DEBUG
+ EnableWindow (GetDlgItem(hWnd, IDC_CONSOLE), TRUE);
+#endif
+ return TRUE;
+ }
+ case WM_NOTIFY:
+ {
+ NMHDR* nmhdr = (NMHDR*)lParam;
+
+ switch (nmhdr->code)
+ {
+ case PSN_APPLY:
+ case PSN_KILLACTIVE:
+ {
+ int iFlags=0, iProxies=0;
+ short sPort;
+ char szHost[64], szLog[MAX_PATH], szUser[64], szPass[64];
+ BOOL bVerbose;
+
+ GetDlgItemText (hWnd, IDC_BINDIP, szHost, sizeof(szHost));
+ DBWriteContactSettingString (NULL, "IMOPROXY", "Host", szHost);
+ DBWriteContactSettingWord (NULL, "IMOPROXY", "Port",
+ (sPort = GetDlgItemInt (hWnd, IDC_BINDPORT, NULL, FALSE)));
+ if (IsDlgButtonChecked (hWnd, IDC_INTERACT)==BST_CHECKED)
+ iFlags|=IMO2S_FLAG_ALLOWINTERACT;
+ if (IsDlgButtonChecked (hWnd, IDC_CURRTIMESTAMP)==BST_CHECKED)
+ iFlags|=IMO2S_FLAG_CURRTIMESTAMP;
+ GetDlgItemText (hWnd, IDC_USERNAME, szUser, sizeof(szUser));
+ DBWriteContactSettingString (NULL, "IMOPROXY", "User", szUser);
+ GetDlgItemText (hWnd, IDC_PASSWORD, szPass, sizeof(szPass));
+ DBWriteContactSettingString (NULL, "IMOPROXY", "Password", szPass);
+ DBWriteContactSettingDword (NULL, "IMOPROXY", "Flags", iFlags);
+ DBWriteContactSettingByte(NULL, "IMOPROXY", "Verbose",
+ (char)(bVerbose = (IsDlgButtonChecked (hWnd, IDC_LOG)==BST_CHECKED)));
+ GetDlgItemText (hWnd, IDC_LOGFILE, szLog, sizeof(szLog));
+ DBWriteContactSettingString (NULL, "IMOPROXY", "Logfile", szLog);
+ if (IsDlgButtonChecked (hWnd, IDC_USESOCKS)==BST_CHECKED)
+ iProxies|=(1<<PROXY_SOCKS);
+ if (IsDlgButtonChecked (hWnd, IDC_USECOMM)==BST_CHECKED)
+ iProxies|=(1<<PROXY_W32SKYPEEMU);
+ if (IsDlgButtonChecked (hWnd, IDC_USESKYPEPL)==BST_CHECKED)
+ iProxies|=(1<<PROXY_SKYPEPLUGIN);
+ DBWriteContactSettingByte(NULL, "IMOPROXY", "UseNetlib",
+ (char)(IsDlgButtonChecked (hWnd, IDC_USENETLIB)==BST_CHECKED));
+ DBWriteContactSettingByte(NULL, "IMOPROXY", "Proxies", (char)iProxies);
+ iProxies^=iOldProxies;
+ if (sPort != sOldPort || lstrcmp (szOldHost, szHost))
+ iProxies|=(1<<PROXY_SOCKS);
+
+ if (lstrcmp (szOldLog, szLog) || bOldVerbose != bVerbose ||
+ lstrcmp (szOldUser, szUser) || lstrcmp(szOldPass, szPass) ||
+ iFlags != iOldFlags)
+ iProxies=(1<<PROXY_MAX)-1;
+
+ /*
+ StopProxies(iProxies);
+ LoadSettings();
+ CheckSettings(iProxies);
+ StartProxies(iProxies);
+ */
+ UpdateProxyStatus (hWnd, PROXY_SOCKS);
+ UpdateProxyStatus (hWnd, PROXY_W32SKYPEEMU);
+ if (ServiceExists(SKYPE_PROTONAME PSS_SKYPEAPIMSG))
+ UpdateProxyStatus (hWnd, PROXY_SKYPEPLUGIN);
+ return TRUE;
+ }
+ }
+ break;
+ }
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDC_LOG:
+ {
+ BOOL bEnable = (SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0)==BST_CHECKED);
+
+ EnableWindow (GetDlgItem (hWnd, IDC_LOGFILE), bEnable);
+ EnableWindow (GetDlgItem (hWnd, IDC_OPEN), bEnable);
+ break;
+ }
+ case IDC_OPEN:
+ {
+ char szFilename[MAX_PATH];
+ OPENFILENAME ofn={0};
+
+ GetDlgItemText (hWnd, IDC_LOGFILE, szFilename, sizeof(szFilename));
+ ofn.lStructSize=sizeof(OPENFILENAME);
+ ofn.hwndOwner=hWnd;
+ ofn.Flags=OFN_HIDEREADONLY;
+ ofn.lpstrTitle=Translate("Select where log file will be created");
+ ofn.lpstrFilter=Translate("All files (*.*)\0*.*\0");
+ ofn.lpstrFile=szFilename;
+ ofn.nMaxFile=sizeof(szFilename)-2;
+ ofn.nMaxFileTitle=sizeof(szFilename);
+ if(GetSaveFileName(&ofn))
+ SetDlgItemText(hWnd, IDC_LOGFILE, szFilename);
+ break;
+ }
+ case IDC_STARTSOCKS:
+ case IDC_STARTCOMM:
+ case IDC_STARTSKYPEPL:
+ {
+ int iID;
+
+ switch (LOWORD(wParam))
+ {
+ case IDC_STARTSOCKS:
+ iID = PROXY_SOCKS;
+ break;
+ case IDC_STARTCOMM:
+ iID = PROXY_W32SKYPEEMU;
+ break;
+ case IDC_STARTSKYPEPL:
+ iID = PROXY_SKYPEPLUGIN;
+ break;
+ }
+ EnableWindow ((HWND)lParam, FALSE);
+ LoadSettings();
+ CheckSettings (1<<iID);
+ StartProxy (iID);
+ UpdateProxyStatus (hWnd, iID);
+ break;
+ }
+ case IDC_STOPSOCKS:
+ case IDC_STOPCOMM:
+ case IDC_STOPSKYPEPL:
+ {
+ int iID;
+
+ switch (LOWORD(wParam))
+ {
+ case IDC_STOPSOCKS:
+ iID = PROXY_SOCKS;
+ break;
+ case IDC_STOPCOMM:
+ iID = PROXY_W32SKYPEEMU;
+ break;
+ case IDC_STOPSKYPEPL:
+ iID = PROXY_SKYPEPLUGIN;
+ break;
+ }
+ EnableWindow ((HWND)lParam, FALSE);
+ StopProxy (iID);
+ UpdateProxyStatus (hWnd, iID);
+ break;
+ }
+ case IDC_CONSOLE:
+ {
+ CONSOLE_SCREEN_BUFFER_INFO coninfo;
+ HANDLE hStdHandle;
+ int hConHandle;
+ HMENU hMenu;
+ FILE *fp;
+ HMODULE hKernel32;
+ HWND (WINAPI *_GetConsoleWindow)(void), hWndCon;
+
+ /* Some dirty hack for a simple console. I know this isn't really
+ proper and that I should use my own console, but it's enough for
+ debugging purposes ;-)
+ */
+ if (HIWORD(wParam)!=BN_CLICKED) break;
+ switch (SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0))
+ {
+ case BST_UNCHECKED:
+ if (m_stCfg.fpLog) fclose(m_stCfg.fpLog);
+ m_stCfg.fpLog = NULL;
+ LoadSettings ();
+ FreeConsole();
+ m_stCfg.bVerbose = bOldVerbose;
+ m_bConsole = FALSE;
+ break;
+ case BST_CHECKED:
+ m_bConsole = AllocConsole();
+ hStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
+ GetConsoleScreenBufferInfo(hStdHandle, &coninfo);
+ coninfo.dwSize.Y = 500;
+ SetConsoleScreenBufferSize(hStdHandle, coninfo.dwSize);
+ hConHandle = _open_osfhandle((long)hStdHandle, _O_TEXT);
+ fp = _fdopen(hConHandle, "w");
+ if (!fp)
+ {
+ FreeConsole();
+ break;
+ }
+ // Only available in Win2k or above
+ // Protect Console form closing, otherwise closing the console
+ // would Shutdown Miranda
+ if ((hKernel32 = GetModuleHandle ("kernel32.dll")) &&
+ (*(FARPROC *)&_GetConsoleWindow =
+ GetProcAddress(hKernel32, "GetConsoleWindow")) &&
+ (hWndCon = _GetConsoleWindow()))
+ {
+ hMenu = GetSystemMenu (hWndCon, FALSE);
+ DeleteMenu (hMenu, SC_CLOSE, MF_BYCOMMAND);
+ }
+ else
+ {
+ fprintf (fp, Translate("WARNING: Only close this console by pushing the Console button "
+ "in the settings dialog, otherwise you sould shutdown Miranda by closing "
+ "the Window!\n"));
+ }
+ setvbuf(fp, NULL, _IONBF, 0 );
+ if (m_stCfg.fpLog && m_stCfg.fpLog != stdout && m_stCfg.fpLog != stderr) fclose(m_stCfg.fpLog);
+ bOldVerbose = m_stCfg.bVerbose;
+ m_stCfg.bVerbose = 1;
+ m_stCfg.fpLog = fp;
+ break;
+ }
+ break;
+ }
+ }
+ SendMessage (GetParent(hWnd), PSM_CHANGED, 0, 0);
+ break;
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+static int RegisterOptions(WPARAM wParam, LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp={0};
+
+ odp.cbSize = sizeof(odp);
+ odp.hInstance = m_hInst;
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS);
+ odp.pszGroup = Translate("Network");
+ odp.pszTitle = "Skype Imoproxy";
+ odp.pfnDlgProc = OptionsDlgProc;
+ odp.flags = ODPF_BOLDGROUPS;
+ CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+void RegisterToUpdate(void)
+{
+ //Use for the Updater plugin
+ if(ServiceExists(MS_UPDATE_REGISTER))
+ {
+ Update update = {0};
+ char szVersion[16];
+
+ update.szComponentName = pluginInfo.shortName;
+ update.pbVersion = (BYTE *)CreateVersionStringPlugin((PLUGININFO *)&pluginInfo, szVersion);
+ update.cpbVersion = strlen((char *)update.pbVersion);
+
+#ifdef _WIN64
+ update.szUpdateURL = "http://dose.0wnz.at/miranda/Skype/imo2sproxy_x64_binonly.zip"; // FIXME!!
+ update.szVersionURL = "http://dose.0wnz.at/miranda/Skype/"; // FIXME
+ update.pbVersionPrefix = (BYTE *)"imo2sproxy version "; //FIXME
+ update.szBetaUpdateURL = "http://dose.0wnz.at/miranda/Skype/imo2sproxy_x64_binonly.zip";
+ update.szBetaVersionURL = "http://dose.0wnz.at/miranda/Skype/";
+ update.pbBetaVersionPrefix = (BYTE *)"imo2sproxy version ";
+#else
+ update.szUpdateURL = "http://addons.miranda-im.org/feed.php?dlfile=4146";
+ update.szVersionURL = "http://addons.miranda-im.org/details.php?action=viewfile&id=4146";
+ update.pbVersionPrefix = (BYTE *)"<span class=\"fileNameHeader\">Skype to imo.im Gateway ";
+ update.szBetaUpdateURL = "http://dose.0wnz.at/miranda/Skype/imo2sproxy_w32_binonly.zip";
+ update.szBetaVersionURL = "http://dose.0wnz.at/miranda/Skype/";
+ update.pbBetaVersionPrefix = (BYTE *)"imo2sproxy version ";
+#endif
+
+ update.cpbVersionPrefix = strlen((char *)update.pbVersionPrefix);
+ update.cpbBetaVersionPrefix = strlen((char *)update.pbBetaVersionPrefix);
+
+ CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
+
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+int PreShutdown(WPARAM wParam, LPARAM lParam)
+{
+ OutputDebugString ("IMOPROXY: PreShutdown");
+ StopProxies (-1);
+ if (m_stCfg.fpLog && m_stCfg.fpLog != stdout && m_stCfg.fpLog != stderr)
+ {
+ fclose(m_stCfg.fpLog);
+ m_stCfg.fpLog = NULL;
+ }
+ if (m_stCfg.pszUser)
+ {
+ free(m_stCfg.pszUser);
+ m_stCfg.pszUser = NULL;
+ }
+ if (m_stCfg.pszPass)
+ {
+ free(m_stCfg.pszPass);
+ m_stCfg.pszPass = NULL;
+ }
+
+ FreeConsole();
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+int OnModulesLoaded(WPARAM wParam, LPARAM lParam)
+{
+ BYTE CheckSkype = DBGetContactSettingByte (NULL, "IMOPROXY", "CheckSkype", 2);
+ if (CheckSkype) CheckSettings(-1);
+ if (CheckSkype == 2) DBWriteContactSettingByte (NULL, "IMOPROXY", "CheckSkype", 0);
+ RegisterToUpdate();
+
+ // On Miranda 0.0.0.8+ NETLIB suppotrs HTTPS, therefore we can use
+ // Netlib there
+ if (CallService (MS_SYSTEM_GETVERSION, 0, 0) >= 0x080000 &&
+ DBGetContactSettingByte (NULL, "IMOPROXY", "UseNetlib", 0))
+ ImoRq_SetIOLayer (IoLayerNETLIB_Init);
+ StartProxies(-1);
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ m_hInst=hinstDLL;
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+
+__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+// -----------------------------------------------------------------------------
+
+// New plugin API
+__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfoEx;
+}
+
+// -----------------------------------------------------------------------------
+
+__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
+{
+ return interfaces;
+}
+
+// -----------------------------------------------------------------------------
+
+int __declspec(dllexport) Load(PLUGINLINK *link)
+{
+
+#ifdef _DEBUG
+ Crash_Init();
+#endif
+ pluginLink = link;
+
+ // Init IMO2S config structures
+ Imo2sproxy_Defaults (&m_stCfg);
+ SocksProxy_Defaults (&m_stSocksCfg);
+ W32SkypeEmu_Defaults(&m_stSypeEmuCfg);
+ SkypePluginLink_Defaults(&m_stSkypePluginCfg);
+ m_stCfg.logerror = ShowError;
+ LoadSettings();
+
+ m_hOptHook = HookEvent(ME_OPT_INITIALISE, RegisterOptions);
+ m_hPreShutdownHook = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
+ m_hHookModulesLoaded = HookEvent( ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+
+ OutputDebugString ("IMOPROXY: Loaded");
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+int __declspec(dllexport) Unload(void)
+{
+ OutputDebugString ("IMOPROXY: Unload");
+ UnhookEvent(m_hOptHook);
+ UnhookEvent(m_hPreShutdownHook);
+ UnhookEvent(m_hHookModulesLoaded);
+ return 0;
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/io_layer_netlib.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/io_layer_netlib.c
new file mode 100644
index 0000000000..378f72e65f
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/io_layer_netlib.c
@@ -0,0 +1,340 @@
+/* Module: io_layer_netlib.c
+ Purpose: IO Layer for Internet communication using Miranda NETLIB
+ Author: leecher
+ Date: 20.04.2011 :=)
+*/
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#include <stdlib.h>
+#include "include/newpluginapi.h"
+#include "include/m_netlib.h"
+#include "fifo.h"
+#include "memlist.h"
+#include "io_layer.h"
+
+#define USER_AGENT "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
+
+typedef struct
+{
+ IOLAYER vtbl;
+ int iRecursion;
+ NETLIBHTTPREQUEST *nlhrReply;
+ LPVOID lpErrorBuf;
+ HANDLE nlc;
+} IOLAYER_INST;
+
+typedef struct
+{
+ HANDLE hNetlib;
+ TYP_LIST *hCookies;
+ TYP_FIFO *hCookieStr;
+ char *pszCookies;
+ LONG lRefCount;
+ CRITICAL_SECTION cs;
+} IOLAYER_SINGLETON;
+
+static IOLAYER_SINGLETON *m_hNL = NULL;
+
+static void IoLayer_Exit (IOLAYER *hPIO);
+static char *IoLayer_Post(IOLAYER *hPIO, char *pszURL, char *pszPostFields, unsigned int cbPostFields, unsigned int *pdwLength);
+static char *IoLayer_Get(IOLAYER *hIO, char *pszURL, unsigned int *pdwLength);
+static void IoLayer_Cancel(IOLAYER *hIO);
+static char *IoLayer_GetLastError(IOLAYER *hIO);
+static char *IoLayer_EscapeString(IOLAYER *hPIO, char *pszData);
+static void IoLayer_FreeEscapeString(char *pszData);
+static void FetchLastError (IOLAYER_INST *hIO);
+static void add_cookies(char *pszCookies);
+static void refresh_cookies();
+static HANDLE *OpenConnection(NETLIBHTTPREQUEST *nlhr);
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+IOLAYER *IoLayerNETLIB_Init(void)
+{
+ IOLAYER_INST *hIO;
+
+ if (CallService (MS_SYSTEM_GETVERSION, 0, 0) < 0x080000 || // Miranda HTTPS support starting with 0.8.0.0
+ !(hIO = calloc(1, sizeof(IOLAYER_INST))))
+ return NULL;
+
+ // NETLIB only works as singleton
+ if (!m_hNL)
+ {
+ NETLIBUSER nlu={0};
+
+ if (!(m_hNL = calloc (1, sizeof(IOLAYER_SINGLETON))))
+ {
+ free (hIO);
+ return NULL;
+ }
+ m_hNL->lRefCount++;
+
+ // Init Netlib
+ nlu.cbSize = sizeof(nlu);
+ nlu.flags = NUF_OUTGOING;
+ nlu.szDescriptiveName = "imo2sproxy connection";
+ nlu.szSettingsModule = "IMOPROXY";
+ nlu.szHttpGatewayUserAgent = USER_AGENT;
+ if (!(m_hNL->hNetlib = (HANDLE)CallService (MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu)) ||
+ !(m_hNL->hCookies = List_Init(0)) ||
+ !(m_hNL->hCookieStr = Fifo_Init(0)))
+ {
+ IoLayer_Exit((IOLAYER*)hIO);
+ return NULL;
+ }
+ m_hNL->pszCookies = "";
+ InitializeCriticalSection (&m_hNL->cs);
+ } else m_hNL->lRefCount++;
+
+ // Init Vtbl
+ hIO->vtbl.Exit = IoLayer_Exit;
+ hIO->vtbl.Post = IoLayer_Post;
+ hIO->vtbl.Get = IoLayer_Get;
+ hIO->vtbl.Cancel = IoLayer_Cancel;
+ hIO->vtbl.GetLastError = IoLayer_GetLastError;
+ hIO->vtbl.EscapeString = IoLayer_EscapeString;
+ hIO->vtbl.FreeEscapeString = IoLayer_FreeEscapeString;
+
+ return (IOLAYER*)hIO;
+}
+// -----------------------------------------------------------------------------
+
+static void IoLayer_Exit (IOLAYER *hPIO)
+{
+ IOLAYER_INST *hIO = (IOLAYER_INST*)hPIO;
+
+ if (hIO->nlhrReply) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)hIO->nlhrReply);
+ if (hIO->lpErrorBuf) LocalFree(hIO->lpErrorBuf);
+ if (InterlockedDecrement(&m_hNL->lRefCount) <= 0)
+ {
+ if (m_hNL->hNetlib) Netlib_CloseHandle (m_hNL->hNetlib);
+ if (m_hNL->hCookies) {
+ List_FreeElements(m_hNL->hCookies);
+ List_Exit (m_hNL->hCookies);
+ }
+ if (m_hNL->hCookieStr) Fifo_Exit(m_hNL->hCookieStr);
+ DeleteCriticalSection (&m_hNL->cs);
+ free (m_hNL);
+ m_hNL = NULL;
+ }
+ free (hIO);
+}
+
+// -----------------------------------------------------------------------------
+
+static char *IoLayer_Post(IOLAYER *hPIO, char *pszURL, char *pszPostFields, unsigned int cbPostFields, unsigned int *pdwLength)
+{
+ IOLAYER_INST *hIO = (IOLAYER_INST*)hPIO;
+ NETLIBHTTPREQUEST nlhr={0};
+ NETLIBHTTPHEADER headers[5];
+ int i;
+ char *pszCookies = NULL;
+
+
+ /*
+ char szDbg[256];
+ sprintf (szDbg, "Thread %d with hIO %08X requests %s\n", GetCurrentThreadId(), hIO, pszURL);
+ OutputDebugString(szDbg);
+ */
+
+ // Build basic request
+ nlhr.cbSize = sizeof(nlhr);
+ nlhr.flags = NLHRF_GENERATEHOST | NLHRF_SMARTREMOVEHOST | NLHRF_REDIRECT;
+ if (!pdwLength) nlhr.flags |= NLHRF_DUMPASTEXT; // pdwLength needed -> Binary data
+ nlhr.requestType = pszPostFields?REQUEST_POST:REQUEST_GET;
+ nlhr.szUrl = pszURL;
+ nlhr.pData = pszPostFields;
+ nlhr.dataLength = cbPostFields;
+ nlhr.headers = headers;
+
+ // Add headers
+ EnterCriticalSection (&m_hNL->cs);
+ if (m_hNL->pszCookies && *m_hNL->pszCookies)
+ {
+ headers[nlhr.headersCount].szName = "Cookie";
+ headers[nlhr.headersCount++].szValue = pszCookies = strdup(m_hNL->pszCookies);
+ }
+ headers[nlhr.headersCount].szName = "User-Agent";
+ headers[nlhr.headersCount++].szValue = USER_AGENT;
+ headers[nlhr.headersCount].szName = "Accept-Encoding";
+ headers[nlhr.headersCount++].szValue = "deflate, gzip";
+ headers[nlhr.headersCount].szName = "Content-Type";
+ headers[nlhr.headersCount++].szValue = "application/x-www-form-urlencoded; charset=UTF-8";
+ headers[nlhr.headersCount].szName = "X-Requested-With";
+ headers[nlhr.headersCount++].szValue = "XMLHttpRequest";
+ LeaveCriticalSection (&m_hNL->cs);
+
+ // Do the transaction
+ nlhr.nlc = hIO->nlc = OpenConnection (&nlhr);
+ if (hIO->nlhrReply) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)hIO->nlhrReply);
+ hIO->nlhrReply = (NETLIBHTTPREQUEST*)CallService (MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNL->hNetlib, (LPARAM)&nlhr);
+ hIO->nlc = NULL;
+
+ if (pszCookies) free (pszCookies);
+ if (!hIO->nlhrReply)
+ {
+ FetchLastError (hIO);
+ return NULL;
+ }
+
+ if (!hIO->nlhrReply || !hIO->nlhrReply->dataLength || !hIO->nlhrReply->pData)
+ {
+ if (hIO->lpErrorBuf) LocalFree(hIO->lpErrorBuf);
+ if (hIO->lpErrorBuf = LocalAlloc (LPTR, 64))
+ strcpy (hIO->lpErrorBuf, "Reply contained no data");
+ return NULL;
+ }
+
+ // Error handling
+ if (hIO->nlhrReply->resultCode < 200 || hIO->nlhrReply->resultCode >= 300)
+ {
+ if (hIO->lpErrorBuf) LocalFree(hIO->lpErrorBuf);
+ if (hIO->lpErrorBuf = LocalAlloc (LPTR, 64))
+ sprintf (hIO->lpErrorBuf, "HTTP transaction returned status %d", hIO->nlhrReply->resultCode);
+ return NULL;
+ }
+
+ // Process headers to collect cookies
+ EnterCriticalSection (&m_hNL->cs);
+ for (i=0; i<hIO->nlhrReply->headersCount; i++)
+ {
+ if (!strnicmp(hIO->nlhrReply->headers[i].szName, "Set-Cookie", 10))
+ add_cookies(hIO->nlhrReply->headers[i].szValue);
+ }
+ LeaveCriticalSection (&m_hNL->cs);
+
+ // Return reply
+ if (pdwLength) *pdwLength = hIO->nlhrReply->dataLength;
+ return hIO->nlhrReply->pData;
+}
+
+// -----------------------------------------------------------------------------
+
+static char *IoLayer_Get(IOLAYER *hIO, char *pszURL, unsigned int *pdwLength)
+{
+ return IoLayer_Post (hIO, pszURL, NULL, 0, pdwLength);
+}
+
+// -----------------------------------------------------------------------------
+
+static void IoLayer_Cancel(IOLAYER *hPIO)
+{
+ IOLAYER_INST *hIO = (IOLAYER_INST*)hPIO;
+
+ if (hIO->nlc && Netlib_CloseHandle(hIO->nlc))
+ hIO->nlc = NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+static char *IoLayer_GetLastError(IOLAYER *hIO)
+{
+ return (char*)((IOLAYER_INST*)hIO)->lpErrorBuf;
+}
+
+// -----------------------------------------------------------------------------
+
+static char *IoLayer_EscapeString(IOLAYER *hPIO, char *pszData)
+{
+ return (char*)CallService (MS_NETLIB_URLENCODE, 0, (LPARAM)pszData);
+}
+
+// -----------------------------------------------------------------------------
+
+static void IoLayer_FreeEscapeString(char *pszData)
+{
+ HeapFree(GetProcessHeap(), 0, pszData);
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+static void FetchLastError (IOLAYER_INST *hIO)
+{
+ if (hIO->lpErrorBuf) LocalFree(hIO->lpErrorBuf);
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
+ GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
+ (LPTSTR)&hIO->lpErrorBuf, 0, NULL);
+}
+
+// -----------------------------------------------------------------------------
+
+static void add_cookies(char *pszCookies)
+{
+ int i, nCount, iLenCmp, iLenCookie;
+ char *p, *pszCookie = NULL;
+
+ if (!(p = strchr(pszCookies, '='))) return;
+ iLenCmp=p-pszCookies+1;
+ if ((p=strchr (p, ';')) || (p=strchr (p, ';'))) iLenCookie = p-pszCookies;
+ else iLenCookie=strlen(pszCookies);
+
+ for (i=0, nCount=List_Count(m_hNL->hCookies); i<nCount; i++)
+ {
+ pszCookie = (char*)List_ElementAt (m_hNL->hCookies, i);
+ if (!strncmp(pszCookie, pszCookies, iLenCmp))
+ break;
+ }
+
+ if (i==nCount) pszCookie = NULL;
+ if (pszCookie = realloc (pszCookie, iLenCookie+1))
+ {
+ strncpy (pszCookie, pszCookies, iLenCookie);
+ pszCookie[iLenCookie]=0;
+ if (i<nCount)
+ List_ReplaceElementAt (m_hNL->hCookies, pszCookie, i);
+ else
+ List_Push (m_hNL->hCookies, pszCookie);
+ }
+ refresh_cookies ();
+}
+
+// -----------------------------------------------------------------------------
+
+static void refresh_cookies()
+{
+ int i, nCount;
+
+ Fifo_Reset (m_hNL->hCookieStr);
+ for (i=0, nCount=List_Count(m_hNL->hCookies); i<nCount; i++)
+ {
+ char *pszCookie = (char*)List_ElementAt (m_hNL->hCookies, i);
+ Fifo_Add (m_hNL->hCookieStr, pszCookie, strlen(pszCookie));
+ Fifo_Add (m_hNL->hCookieStr, "; ", 2);
+ }
+ Fifo_Add (m_hNL->hCookieStr, "", 1);
+ m_hNL->pszCookies = Fifo_Get (m_hNL->hCookieStr, NULL);
+}
+
+// -----------------------------------------------------------------------------
+
+static HANDLE *OpenConnection(NETLIBHTTPREQUEST *nlhr)
+{
+ NETLIBOPENCONNECTION nloc={0};
+ BOOL secur = (nlhr->flags & NLHRF_SSL) || _strnicmp(nlhr->szUrl, "https", 5) == 0;
+ char* phost = strstr(nlhr->szUrl, "://");
+ char *ppath, *pcolon;
+
+ // Poor man's InternetCrackUrl
+ nloc.cbSize = sizeof(NETLIBOPENCONNECTION);
+ if (phost) phost+=3; else phost=nlhr->szUrl;
+ nloc.szHost = _alloca (strlen(phost)+1);
+ strcpy ((char*)nloc.szHost, phost);
+ if (ppath = strchr(nloc.szHost, '/')) *ppath = '\0';
+ if (pcolon = strrchr(nloc.szHost, ':'))
+ {
+ *pcolon = '\0';
+ nloc.wPort = (WORD)strtol(pcolon+1, NULL, 10);
+ }
+ else nloc.wPort = secur ? 443 : 80;
+ nloc.flags = (secur ? NLOCF_SSL : 0) | NLOCF_HTTP;
+ if (secur) nlhr->flags |= NLHRF_SSL; else nlhr->flags &= ~NLHRF_SSL;
+
+ // Open connection
+ return (HANDLE)CallService (MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNL->hNetlib, (LPARAM)&nloc);
+} \ No newline at end of file
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.aps b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.aps
new file mode 100644
index 0000000000..280086f42b
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.aps
Binary files differ
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.rc b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.rc
new file mode 100644
index 0000000000..487426fbfe
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/res.rc
@@ -0,0 +1,145 @@
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Deutsch (Österreich) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEA)
+#ifdef _WIN32
+LANGUAGE LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_OPTIONS DIALOGEX 0, 0, 287, 224
+STYLE WS_CHILD
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Sans Serif"
+BEGIN
+ GROUPBOX "Account information",IDC_STATIC,7,7,273,31
+ LTEXT "Username:",IDC_STATIC,17,20,53,9
+ EDITTEXT IDC_USERNAME,74,18,56,12,ES_AUTOHSCROLL
+ LTEXT "Password:",IDC_STATIC,135,20,47,9
+ EDITTEXT IDC_PASSWORD,185,18,56,12,ES_PASSWORD | ES_AUTOHSCROLL
+ CONTROL "Support for Voicecalls via imo.im Flash in Internet Explorer",
+ IDC_INTERACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,42,
+ 273,9
+ CONTROL "Ignore server timestamp and use current time for messages",
+ IDC_CURRTIMESTAMP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
+ 7,60,273,10
+ CONTROL "Log traffic to file:",IDC_LOG,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,7,71,110,10
+ EDITTEXT IDC_LOGFILE,119,71,128,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_OPEN,248,71,14,12
+ LTEXT "Status:",IDC_STATIC,126,140,29,10
+ LTEXT "Stopped",IDC_STATUSSOCKS,157,140,54,9,SS_SUNKEN
+ GROUPBOX "Socket Proxy",IDC_STATIC,7,129,273,45
+ LTEXT "Bind to address:",IDC_STATIC,17,157,73,9
+ COMBOBOX IDC_BINDIP,95,155,75,12,CBS_DROPDOWN | CBS_SORT |
+ WS_VSCROLL | WS_TABSTOP
+ LTEXT "Port:",IDC_STATIC,179,157,31,9
+ EDITTEXT IDC_BINDPORT,211,155,31,12,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "Use Socket Proxy",IDC_USESOCKS,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,18,140,81,9
+ PUSHBUTTON "Start",IDC_STARTSOCKS,216,137,30,12
+ PUSHBUTTON "Stop",IDC_STOPSOCKS,246,137,30,12,WS_DISABLED
+ GROUPBOX "Skype compatible communication API",IDC_STATIC,7,177,
+ 273,40
+ LTEXT "Caution: Don't use this if you have the Skype application running!",
+ IDC_STATIC,13,188,260,8
+ LTEXT "Status:",IDC_STATIC,126,201,29,10
+ LTEXT "Stopped",IDC_STATUSCOMM,158,201,54,9,SS_SUNKEN
+ CONTROL "Use compatible comm API",IDC_USECOMM,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,18,201,105,9
+ PUSHBUTTON "Start",IDC_STARTCOMM,216,198,30,12
+ PUSHBUTTON "Stop",IDC_STOPCOMM,246,198,30,12,WS_DISABLED
+ CONTROL "Console",IDC_CONSOLE,"Button",BS_AUTOCHECKBOX |
+ BS_PUSHLIKE | WS_TABSTOP,216,87,45,11
+ GROUPBOX "Skype Plugin 0.0.0.46+ internal communication link",
+ IDC_STATIC,7,102,273,25
+ LTEXT "Status:",IDC_STATIC,126,113,29,10
+ LTEXT "Stopped",IDC_STATUSSKYPEPL,158,113,54,9,SS_SUNKEN
+ CONTROL "Use plugin link",IDC_USESKYPEPL,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,18,113,105,9
+ PUSHBUTTON "Start",IDC_STARTSKYPEPL,216,110,30,12
+ PUSHBUTTON "Stop",IDC_STOPSKYPEPL,246,110,30,12,WS_DISABLED
+ CONTROL "Use Netlib instead of WinInet (Experimental)",
+ IDC_USENETLIB,"Button",BS_AUTOCHECKBOX | WS_DISABLED |
+ WS_TABSTOP,7,51,273,9
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO DISCARDABLE
+BEGIN
+ IDD_OPTIONS, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 280
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 217
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // Deutsch (Österreich) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/resource.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/resource.h
new file mode 100644
index 0000000000..e0da6bef1d
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/resource.h
@@ -0,0 +1,39 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by res.rc
+//
+#define IDD_OPTIONS 101
+#define IDC_BINDPORT 1001
+#define IDC_BINDIP 1002
+#define IDC_INTERACT 1003
+#define IDC_CURRTIMESTAMP 1004
+#define IDC_LOG 1005
+#define IDC_LOGFILE 1006
+#define IDC_OPEN 1007
+#define IDC_USERNAME 1008
+#define IDC_PASSWORD 1009
+#define IDC_STATUSSOCKS 1010
+#define IDC_STATUSCOMM 1011
+#define IDC_STATUSSKYPEPL 1012
+#define IDC_USESOCKS 1013
+#define IDC_STARTSOCKS 1014
+#define IDC_STOPSOCKS 1015
+#define IDC_USECOMM 1016
+#define IDC_STARTCOMM 1017
+#define IDC_STOPCOMM 1018
+#define IDC_CONSOLE 1019
+#define IDC_USESKYPEPL 1020
+#define IDC_STARTSKYPEPL 1021
+#define IDC_STOPSKYPEPL 1022
+#define IDC_USENETLIB 1023
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 102
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1020
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/sdk/m_updater.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/sdk/m_updater.h
new file mode 100644
index 0000000000..371b7437a0
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/sdk/m_updater.h
@@ -0,0 +1,146 @@
+#ifndef _M_UPDATER_H
+#define _M_UPDATER_H
+
+// NOTES:
+// - For langpack updates, include a string of the following format in the langpack text file:
+// ";FLID: <file listing name> <version>"
+// version must be four numbers seperated by '.', in the range 0-255 inclusive
+// - Updater will disable plugins that are downloaded but were not active prior to the update (this is so that, if an archive contains e.g. ansi and
+// unicode versions, the correct plugin will be the only one active after the new version is installed)...so if you add a support plugin, you may need
+// to install an ini file to make the plugin activate when miranda restarts after the update
+// - Updater will replace all dlls that have the same internal shortName as a downloaded update dll (this is so that msn1.dll and msn2.dll, for example,
+// will both be updated) - so if you have a unicode and a non-unicode version of a plugin in your archive, you should make the internal names different (which will break automatic
+// updates from the file listing if there is only one file listing entry for both versions, unless you use the 'MS_UPDATE_REGISTER' service below)
+// - Updater will install all files in the root of the archive into the plugins folder, except for langpack files that contain the FLID string which go into the root folder (same
+// folder as miranda32.exe)...all folders in the archive will also be copied to miranda's root folder, and their contents transferred into the new folders. The only exception is a
+// special folder called 'root_files' - if there is a folder by that name in the archive, it's contents will also be copied into miranda's root folder - this is intended to be used
+// to install additional dlls etc that a plugin may require)
+
+// if you set Update.szUpdateURL to the following value when registering, as well as setting your beta site and version data,
+// Updater will ignore szVersionURL and pbVersionPrefix, and attempt to find the file listing URL's from the backend XML data.
+// for this to work, the plugin name in pluginInfo.shortName must match the file listing exactly (except for case)
+#define UPDATER_AUTOREGISTER "UpdaterAUTOREGISTER"
+// Updater will also use the backend xml data if you provide URL's that reference the miranda file listing for updates (so you can use that method
+// if e.g. your plugin shortName does not match the file listing) - it will grab the file listing id from the end of these URLs
+
+typedef struct Update_tag {
+ int cbSize;
+ char *szComponentName; // component name as it will appear in the UI (will be translated before displaying)
+
+ char *szVersionURL; // URL where the current version can be found (NULL to disable)
+ BYTE *pbVersionPrefix; // bytes occuring in VersionURL before the version, used to locate the version information within the URL data
+ // (note that this URL could point at a binary file - dunno why, but it could :)
+ int cpbVersionPrefix; // number of bytes pointed to by pbVersionPrefix
+ char *szUpdateURL; // URL where dll/zip is located
+ // set to UPDATER_AUTOREGISTER if you want Updater to find the file listing URLs (ensure plugin shortName matches file listing!)
+
+ char *szBetaVersionURL; // URL where the beta version can be found (NULL to disable betas)
+ BYTE *pbBetaVersionPrefix; // bytes occuring in VersionURL before the version, used to locate the version information within the URL data
+ int cpbBetaVersionPrefix; // number of bytes pointed to by pbVersionPrefix
+ char *szBetaUpdateURL; // URL where dll/zip is located
+
+ BYTE *pbVersion; // bytes of current version, used for comparison with those in VersionURL
+ int cpbVersion; // number of bytes pointed to by pbVersion
+
+ char *szBetaChangelogURL; // url for displaying changelog for beta versions
+} Update;
+
+// register a comonent with Updater
+//
+// wparam = 0
+// lparam = (LPARAM)&Update
+#define MS_UPDATE_REGISTER "Update/Register"
+
+// utility functions to create a version string from a DWORD or from pluginInfo
+// point buf at a buffer at least 16 chars wide - but note the version string returned may be shorter
+//
+__inline static char *CreateVersionString(DWORD version, char *buf) {
+ mir_snprintf(buf, 16, "%d.%d.%d.%d", (version >> 24) & 0xFF, (version >> 16) & 0xFF, (version >> 8) & 0xFF, version & 0xFF);
+ return buf;
+}
+
+__inline static char *CreateVersionStringPlugin(PLUGININFO *pluginInfo, char *buf) {
+ return CreateVersionString(pluginInfo->version, buf);
+}
+
+
+// register the 'easy' way - use this method if you have no beta URL and the plugin is on the miranda file listing
+// NOTE: the plugin version string on the file listing must be the string version of the version in pluginInfo (i.e. 0.0.0.1,
+// four numbers between 0 and 255 inclusivem, so no letters, brackets, etc.)
+//
+// wParam = (int)fileID - this is the file ID from the file listing (i.e. the number at the end of the download link)
+// lParam = (PLUGININFO*)&pluginInfo
+#define MS_UPDATE_REGISTERFL "Update/RegisterFL"
+
+// this function can be used to 'unregister' components - useful for plugins that register non-plugin/langpack components and
+// may need to change those components on the fly
+// lParam = (char *)szComponentName
+#define MS_UPDATE_UNREGISTER "Update/Unregister"
+
+// this event is fired when the startup process is complete, but NOT if a restart is imminent
+// it is designed for status managment plugins to use as a trigger for beggining their own startup process
+// wParam = lParam = 0 (unused)
+// (added in version 0.1.6.0)
+#define ME_UPDATE_STARTUPDONE "Update/StartupDone"
+
+// this service can be used to enable/disable Updater's global status control
+// it can be called from the StartupDone event handler
+// wParam = (BOOL)enable
+// lParam = 0
+// (added in version 0.1.6.0)
+#define MS_UPDATE_ENABLESTATUSCONTROL "Update/EnableStatusControl"
+
+// An description of usage of the above service and event:
+// Say you are a status control plugin that normally sets protocol or global statuses in your ModulesLoaded event handler.
+// In order to make yourself 'Updater compatible', you would move the status control code from ModulesLoaded to another function,
+// say DoStartup. Then, in ModulesLoaded you would check for the existence of the MS_UPDATE_ENABLESTATUSCONTROL service.
+// If it does not exist, call DoStartup. If it does exist, hook the ME_UPDATE_STARTUPDONE event and call DoStartup from there. You may
+// also wish to call MS_UPDATE_ENABLESTATUSCONTROL with wParam == FALSE at this time, to disable Updater's own status control feature.
+
+// this service can be used to determine whether updates are possible for a component with the given name
+// wParam = 0
+// lParam = (char *)szComponentName
+// returns TRUE if updates are supported, FALSE otherwise
+#define MS_UPDATE_ISUPDATESUPPORTED "Update/IsUpdateSupported"
+
+#endif
+
+
+/////////////// Usage Example ///////////////
+
+#ifdef EXAMPLE_CODE
+
+// you need to #include "m_updater.h" and HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded) in your Load function...
+
+int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {
+
+ Update update = {0}; // for c you'd use memset or ZeroMemory...
+ char szVersion[16];
+
+ update.cbSize = sizeof(Update);
+
+ update.szComponentName = pluginInfo.shortName;
+ update.pbVersion = (BYTE *)CreateVersionString(&pluginInfo, szVersion);
+ update.cpbVersion = strlen((char *)update.pbVersion);
+
+ // these are the three lines that matter - the archive, the page containing the version string, and the text (or data)
+ // before the version that we use to locate it on the page
+ // (note that if the update URL and the version URL point to standard file listing entries, the backend xml
+ // data will be used to check for updates rather than the actual web page - this is not true for beta urls)
+ update.szUpdateURL = "http://scottellis.com.au:81/test/updater.zip";
+ update.szVersionURL = "http://scottellis.com.au:81/test/updater_test.html";
+ update.pbVersionPrefix = (BYTE *)"Updater version ";
+
+ update.cpbVersionPrefix = strlen((char *)update.pbVersionPrefix);
+
+ // do the same for the beta versions of the above struct members if you wish to allow beta updates from another URL
+
+ CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
+
+ // Alternatively, to register a plugin with e.g. file ID 2254 on the file listing...
+ // CallService(MS_UPDATE_REGISTERFL, (WPARAM)2254, (LPARAM)&pluginInfo);
+
+ return 0;
+}
+
+#endif
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.c
new file mode 100644
index 0000000000..0109bd6ede
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.c
@@ -0,0 +1,233 @@
+#include "imo2sproxy.h"
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdlib.h>
+#include "skypepluginlink.h"
+#include "include/newpluginapi.h"
+#include "include/m_system.h"
+
+#define LockMutex(x) EnterCriticalSection (&x)
+#define UnlockMutex(x) LeaveCriticalSection(&x)
+#define InitMutex(x) InitializeCriticalSection(&x)
+#define ExitMutex(x) DeleteCriticalSection(&x)
+#define mutex_t CRITICAL_SECTION
+
+
+// -----------------------------------------------------------------------------
+
+struct tag_proxyInst;
+typedef struct tag_proxyInst IMO2SPROXY_INST;
+
+typedef struct
+{
+ IMOSAPI *hInst;
+ IMO2SPROXY_INST *hProxy;
+ mutex_t sendmutex;
+ mutex_t rcvmutex;
+ int iConnectionStat;
+} CONNINST;
+
+struct tag_proxyInst
+{
+ IMO2SPROXY vtbl; // Must be first!
+ IMO2SPROXY_CFG *pCfg;
+ SKYPEPLUGINLINK_CFG *pMyCfg;
+ HANDLE hService;
+ CONNINST stClient; // Currently only 1 connection
+};
+
+
+static CONNINST *m_pConn = NULL;
+
+// -----------------------------------------------------------------------------
+
+static void EventHandler(char *pszMsg, void *pUser);
+static int InitProxy(IMO2SPROXY_INST *hProxy);
+
+static int Imo2sproxy_Open(IMO2SPROXY *hInst);
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst);
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst);
+
+// -----------------------------------------------------------------------------
+static void EventHandler(char *pszMsg, void *pUser)
+{
+ CONNINST *pInst = (CONNINST*)pUser;
+ COPYDATASTRUCT cds;
+ DWORD dwRes = 0;
+
+ //LockMutex (pInst->sendmutex);
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "> %s\n", pszMsg);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ cds.dwData = 0;
+ cds.cbData = strlen(pszMsg)+1;
+ cds.lpData = pszMsg;
+ CallService (SKYPE_PROTONAME PSS_SKYPEAPIMSG, 0, (LPARAM)&cds);
+ //UnlockMutex (pInst->sendmutex);
+}
+
+// -----------------------------------------------------------------------------
+
+INT_PTR CallIn(WPARAM wParam,LPARAM lParam)
+{
+ CONNINST *pInst = (CONNINST*)m_pConn;
+ PCOPYDATASTRUCT pCopyData = (PCOPYDATASTRUCT)lParam;
+
+ if (!pInst) return -1;
+
+ if (pInst->hProxy->pMyCfg->bDelayLogin && pInst->iConnectionStat < 1)
+ {
+ LockMutex (pInst->rcvmutex);
+ if (InitProxy(pInst->hProxy)<0)
+ {
+ UnlockMutex(pInst->rcvmutex);
+ return -1;
+ }
+ UnlockMutex(pInst->rcvmutex);
+ }
+
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "< [%s]\n", pCopyData->lpData);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ Imo2S_Send (pInst->hInst, pCopyData->lpData);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+static void FreeConnection (CONNINST *pInst)
+{
+ if (!pInst || !pInst->hProxy) return;
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "SkypePluginLink: Closed connection\n");
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+
+ if (pInst->hProxy->hService)
+ {
+ DestroyServiceFunction(pInst->hProxy->hService);
+ pInst->hProxy->hService = NULL;
+ CallService (SKYPE_PROTONAME SKYPE_REGPROXY, 0, 0);
+ }
+ ExitMutex(pInst->sendmutex);
+ ExitMutex(pInst->rcvmutex);
+ if (pInst->hInst)
+ {
+ IMOSAPI *hInst = pInst->hInst;
+ pInst->hInst = NULL;
+ Imo2S_Exit(hInst);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static int InitProxy(IMO2SPROXY_INST *hProxy)
+{
+ char *pszError;
+
+ if (!hProxy->stClient.hInst)
+ {
+ if (!(hProxy->stClient.hInst = Imo2S_Init(EventHandler, &hProxy->stClient, hProxy->pCfg->iFlags)))
+ {
+ hProxy->pCfg->logerror (stderr, "SkypePluginLink: Cannot start Imo2Skype instance.\n");
+ return -1;
+ }
+ }
+
+ // FIXME: We should enable logging dependent on a loglevel rather than just enabling it
+ Imo2S_SetLog (hProxy->stClient.hInst, hProxy->pCfg->fpLog);
+
+ if (hProxy->stClient.iConnectionStat == 0 ||
+ (hProxy->stClient.iConnectionStat = Imo2S_Login (hProxy->stClient.hInst,
+ hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1)
+ {
+ hProxy->pCfg->logerror (stderr, "SkypePluginLink: Cannot login with (%s/****): %s\n",
+ hProxy->pCfg->pszUser, pszError);
+ return -1;
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+// PUBLIC
+// -----------------------------------------------------------------------------
+
+void SkypePluginLink_Defaults (SKYPEPLUGINLINK_CFG *pMyCfg)
+{
+ memset (pMyCfg, 0, sizeof(SKYPEPLUGINLINK_CFG));
+ pMyCfg->bDelayLogin = TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+IMO2SPROXY *SkypePluginLink_Init (IMO2SPROXY_CFG *pCfg, SKYPEPLUGINLINK_CFG *pMyCfg)
+{
+ IMO2SPROXY_INST *pstInst = calloc(sizeof(IMO2SPROXY_INST), 1);
+
+ pstInst->vtbl.Open = Imo2sproxy_Open;
+ pstInst->vtbl.Loop = Imo2sproxy_Loop;
+ pstInst->vtbl.Exit = Imo2sproxy_Exit;
+ pstInst->pCfg = pCfg;
+ pstInst->pMyCfg = pMyCfg;
+ return (IMO2SPROXY*)pstInst;
+}
+
+// -----------------------------------------------------------------------------
+// IMPLEMENTATION
+// -----------------------------------------------------------------------------
+static int Imo2sproxy_Open(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+ WNDCLASS WndClass ={0};
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "SkypePluginLink:Open(Start)\n");
+
+ // Only 1 connection instance, so we can init it right here
+ InitMutex(hProxy->stClient.sendmutex);
+ InitMutex(hProxy->stClient.rcvmutex);
+ hProxy->stClient.hProxy = hProxy;
+ m_pConn = &hProxy->stClient;
+
+ // Register with Skype Plugin
+ hProxy->hService = CreateServiceFunction("IMO2SPROXY" PSS_SKYPEAPIMSG, CallIn);
+ CallService (SKYPE_PROTONAME SKYPE_REGPROXY, 0, (LPARAM)"IMO2SPROXY" PSS_SKYPEAPIMSG);
+ hProxy->stClient.iConnectionStat = -1;
+
+ if (!hProxy->pMyCfg->bDelayLogin)
+ {
+ if (InitProxy(hProxy)<0)
+ {
+ FreeConnection(&hProxy->stClient);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst)
+{
+ // No loop needed for call-in
+}
+
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "SkypePluginLink:Exit()\n");
+
+ FreeConnection (&hProxy->stClient);
+ free (hProxy);
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.h
new file mode 100644
index 0000000000..ecc520ff1e
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/miranda/skypepluginlink.h
@@ -0,0 +1,10 @@
+typedef struct {
+ int bDelayLogin;
+} SKYPEPLUGINLINK_CFG;
+
+#define SKYPE_PROTONAME "SKYPE"
+#define PSS_SKYPEAPIMSG "/SendSkypeAPIMsg"
+#define SKYPE_REGPROXY "/RegisterProxySvc"
+
+void SkypePluginLink_Defaults (SKYPEPLUGINLINK_CFG *pMyCfg);
+IMO2SPROXY *SkypePluginLink_Init (IMO2SPROXY_CFG *pCfg, SKYPEPLUGINLINK_CFG *pMyCfg);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.c
new file mode 100644
index 0000000000..7f1db504e9
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.c
@@ -0,0 +1,158 @@
+/* Module: msgqueue.c
+ Purpose: Message queue for incoming messages
+ Author: leecher
+ Date: 30.08.2009
+
+ Fixme: Sort on insert, do a binary search instead of iterating list.
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "msgqueue.h"
+#include "buddylist.h"
+
+static volatile unsigned int m_uMsgNr=0;
+static void FreeEntry(void *pEntry);
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+TYP_LIST *MsgQueue_Init(void)
+{
+ TYP_LIST *hList = List_Init(16);
+
+ return hList;
+}
+
+// -----------------------------------------------------------------------------
+
+void MsgQueue_Exit(TYP_LIST *hList)
+{
+ Queue_Exit(hList, FreeEntry);
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_Insert(TYP_LIST *hList, cJSON *pNick)
+{
+ MSGENTRY *pEntry;
+ cJSON *pVal;
+
+ if (!(pEntry = Queue_InsertEntry(hList, sizeof(MSGENTRY), ++m_uMsgNr,
+ FreeEntry))) return NULL;
+ pEntry->pszUser = strdup(cJSON_GetObjectItem(pNick, "buid")->valuestring);
+ pEntry->pszAlias = strdup(cJSON_GetObjectItem(pNick, "alias")->valuestring);
+ pEntry->pszMessage = strdup(cJSON_GetObjectItem(pNick, "msg")->valuestring);
+ pEntry->timestamp = cJSON_GetObjectItem(pNick, "timestamp")->valueint;
+ if (pVal = cJSON_GetObjectItem(pNick, "author")) pEntry->pszAuthor=strdup(pVal->valuestring);
+ strcpy (pEntry->szStatus, "RECEIVED");
+ strcpy (pEntry->szType, "TEXT");
+ // imo.im somehow sets group topic via recv_im??
+ if (strcmp(pEntry->pszAlias, pEntry->pszMessage) == 0) strcpy (pEntry->szType, "SETTOPIC");
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_AddReflect(TYP_LIST *hList, cJSON *pNick, TYP_LIST *hBuddyList)
+{
+ MSGENTRY *pEntry;
+ cJSON *pVal;
+
+ if (!(pEntry = Queue_InsertEntry(hList, sizeof(MSGENTRY), ++m_uMsgNr,
+ FreeEntry))) return NULL;
+ pEntry->pszUser = strdup(cJSON_GetObjectItem(pNick, "buid")->valuestring);
+
+ // Usually no alias in Reflection, so query buddy list, if available
+ if (pVal = cJSON_GetObjectItem(pNick, "alias"))
+ pEntry->pszAlias = strdup(pVal->valuestring);
+ else
+ {
+ NICKENTRY *pBuddy = hBuddyList?BuddyList_Find (hBuddyList, pEntry->pszUser):NULL;
+ pEntry->pszAlias = strdup (pBuddy?pBuddy->pszAlias:pEntry->pszUser);
+ }
+
+ pEntry->pszMessage = strdup(cJSON_GetObjectItem(pNick, "msg")->valuestring);
+ pEntry->timestamp = cJSON_GetObjectItem(pNick, "timestamp")->valueint;
+ strcpy (pEntry->szStatus, "SENT");
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_AddSent(TYP_LIST *hList, char *pszUser, char *pszAlias, char *pszMessage, unsigned int *puMsgId)
+{
+ MSGENTRY *pEntry;
+
+ if (!(pEntry = Queue_InsertEntry(hList, sizeof(MSGENTRY), ++m_uMsgNr,
+ FreeEntry))) return NULL;
+ pEntry->pszUser = strdup(pszUser);
+ pEntry->pszAlias = strdup(pszAlias);
+ pEntry->pszMessage = strdup(pszMessage);
+ time (&pEntry->timestamp);
+ strcpy (pEntry->szStatus, "SENDING");
+ if (puMsgId) *puMsgId = pEntry->hdr.uMsgNr;
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_AddEvent(TYP_LIST *hList, char *pszUser, char *pszType)
+{
+ MSGENTRY *pEntry;
+
+ if (!(pEntry = Queue_InsertEntry(hList, sizeof(MSGENTRY), ++m_uMsgNr,
+ FreeEntry))) return NULL;
+ pEntry->pszUser = strdup(pszUser);
+ time (&pEntry->timestamp);
+ strcpy (pEntry->szStatus, "RECEIVED");
+ strcpy (pEntry->szType, pszType);
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL MsgQueue_Remove(TYP_LIST *hList, unsigned int uMsgNr)
+{
+ return Queue_Remove(hList, uMsgNr, FreeEntry);
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_Find(TYP_LIST *hList, unsigned int uMsgNr)
+{
+ return (MSGENTRY*)Queue_Find(hList, uMsgNr);
+}
+
+// -----------------------------------------------------------------------------
+
+MSGENTRY *MsgQueue_FindByRqId(TYP_LIST *hList, unsigned int uRqId)
+{
+ unsigned int i;
+ MSGENTRY *pEntry;
+
+ for (i=List_Count(hList)-1; (int)i!=-1; i--)
+ {
+ pEntry = (MSGENTRY*)List_ElementAt (hList, i);
+ if (pEntry->uRqId == uRqId)
+ return pEntry;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+// Static
+// -----------------------------------------------------------------------------
+
+static void FreeEntry(void *pPEntry)
+{
+ MSGENTRY *pEntry = (MSGENTRY*)pPEntry;
+
+ if (pEntry->pszAlias) free (pEntry->pszAlias);
+ free (pEntry->pszUser);
+ if (pEntry->pszMessage) free (pEntry->pszMessage);
+ if (pEntry->pszAuthor) free (pEntry->pszAuthor);
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.h
new file mode 100644
index 0000000000..ac8ce1cf8d
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/msgqueue.h
@@ -0,0 +1,28 @@
+#include "cJSON.h"
+#include "queue.h"
+#include <time.h>
+
+typedef struct
+{
+ QUEUEHDR hdr;
+ char *pszUser;
+ char *pszAuthor; // In case of groupchat, pszUser is the Groupchat ID and pszAuthor is the user sending it, if not a GC message, pszAuthor is NULL
+ char *pszAlias;
+ char *pszMessage;
+ time_t timestamp;
+ char szStatus[16];
+ char szFailure[256];
+ char szType[20]; // TEXT, SETTOPIC, ADDEDMEMBERS, CREATEDCHATWITH, LEFT, KICKED, ...
+ unsigned int uRqId;
+} MSGENTRY;
+
+TYP_LIST *MsgQueue_Init(void);
+void MsgQueue_Exit(TYP_LIST *hList);
+
+MSGENTRY *MsgQueue_Insert(TYP_LIST *hList, cJSON *pNick);
+MSGENTRY *MsgQueue_AddReflect(TYP_LIST *hList, cJSON *pNick, TYP_LIST *hBuddyList);
+MSGENTRY *MsgQueue_AddSent(TYP_LIST *hList, char *pszUser, char *pszAlias, char *pszMessage, unsigned int *puMsgId);
+MSGENTRY *MsgQueue_AddEvent(TYP_LIST *hList, char *pszUser, char *pszType);
+BOOL MsgQueue_Remove(TYP_LIST *hList, unsigned int uMsgNr);
+MSGENTRY *MsgQueue_Find(TYP_LIST *hList, unsigned int uMsgNr);
+MSGENTRY *MsgQueue_FindByRqId(TYP_LIST *hList, unsigned int uRqId);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.c
new file mode 100644
index 0000000000..a163314c8e
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.c
@@ -0,0 +1,94 @@
+/* Module: queue.c
+ Purpose: Queue management
+ Author: leecher
+ Date: 02.09.2009
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "memlist.h"
+#include "queue.h"
+
+// Maximum threshold for queues (So that we don't leak memory)
+#define THRESHOLD 50
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+void Queue_Exit(TYP_LIST *hList, void (*fpFree)(void *pEntry))
+{
+ void *pEntry;
+
+ while (pEntry=List_Pop(hList))
+ {
+ if (fpFree) fpFree(pEntry);
+ free (pEntry);
+ }
+ List_Exit(hList);
+}
+
+// -----------------------------------------------------------------------------
+
+void* Queue_InsertEntry (TYP_LIST *hList, unsigned int cbSize, unsigned int uMsgNr,
+ void (*fpFree)(void *pEntry))
+{
+ void *pEntry;
+
+ if (!(pEntry = calloc (1, cbSize))) return NULL;
+ if (!List_Push(hList, pEntry))
+ {
+ free (pEntry);
+ return NULL;
+ } else ((QUEUEHDR*)pEntry)->uMsgNr = uMsgNr;
+#ifdef THRESHOLD
+ if (List_Count(hList)>THRESHOLD)
+ {
+ void *pEntry = List_RemoveElementAt(hList, 0);
+
+ if (pEntry) fpFree (pEntry);
+ free (pEntry);
+ }
+#endif
+ return pEntry;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL Queue_Remove(TYP_LIST *hList, unsigned int uMsgNr, void (*fpFree)(void *pEntry))
+{
+ QUEUEHDR *pListEntry;
+ unsigned int i;
+
+ for (i=List_Count(hList)-1; (int)i!=-1; i--)
+ {
+ pListEntry = List_ElementAt (hList, i);
+ if (pListEntry->uMsgNr == uMsgNr)
+ {
+ if (fpFree) fpFree (pListEntry);
+ List_RemoveElementAt(hList, i);
+ free (pListEntry);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+// -----------------------------------------------------------------------------
+
+void *Queue_Find(TYP_LIST *hList, unsigned int uMsgNr)
+{
+ unsigned int i;
+ QUEUEHDR *pEntry;
+
+ for (i=List_Count(hList)-1; (int)i!=-1; i--)
+ {
+ pEntry = (QUEUEHDR*)List_ElementAt (hList, i);
+ if (pEntry->uMsgNr == uMsgNr)
+ return pEntry;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.h
new file mode 100644
index 0000000000..4f42a3b42f
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/queue.h
@@ -0,0 +1,17 @@
+#ifndef __QUEUE_H__
+#define __QUEUE_H__
+
+#include "memlist.h"
+
+typedef struct
+{
+ unsigned int uMsgNr;
+} QUEUEHDR;
+
+void Queue_Exit(TYP_LIST *hList, void (*fpFree)(void *pEntry));
+void* Queue_InsertEntry (TYP_LIST *hList, unsigned int cbSize, unsigned int uMsgNr,
+ void (*fpFree)(void *pEntry));
+BOOL Queue_Remove(TYP_LIST *hList, unsigned int uMsgNr, void (*fpFree)(void *pEntry));
+void *Queue_Find(TYP_LIST *hList, unsigned int uMsgNr);
+
+#endif
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.c
new file mode 100644
index 0000000000..20c56a7a66
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.c
@@ -0,0 +1,565 @@
+/* Module: imo2skypeproxy.c
+ Purpose: Implementation of imo2skype API as Skype proxy (for Miranda Skype plugin)
+ Author: leecher
+ Date: 01.09.2009
+
+ Changelog:
+ 1.00 - 01.09.2009 - Initial release
+ 1.01 - 02.09.2009 - Little bugfix for Onlinestatus, introduced mutex for send thread.
+ 1.02 - 02.09.2009 - Added support for incoming call notifications and expired sessions.
+ 1.03 - 03.09.2009 - As WIN32-port of libcurl is a total mess, Win32-version now uses WinINET.
+ 1.04 - 04.09.2009 - Added support for searching, adding and removing buddies
+ 1.05 - 06.09.2009 - * Mapped "busy" to DND, not NA, as forum user AL|EN proposed.
+ * Mood text will now also be sent on status change of a contact
+ (doesn't really have an effect though)
+ * New Parameter -d (daemonize) to launch proxy in background
+ * Fixed a bug with a crash when encoding umlauts on Win32
+ 1.06 - 25.09.2009 - Added parameter -t for local timestamps.
+ 1.07 - 07.10.2009 - Bugfix: Added parsing of multiple JSON messages
+ Added support for writing to logfile while in daemon mode (-l)
+ 1.08 - 18.10.2009 - Added support for voice calls via imo.im flash on WIN32 (-i)
+ - Limited memory queues to 50 entries to reduce memory usage.
+ 1.09 - 07.11.2009 - Split command line main module and proxy module to make proxy
+ accessible by different layers (i.e. new Miranda Plugin layer)
+ 1.10 - 14.12.2009 - Bug in the cJson library. The authors used the String as second
+ sprintf-Parameter which contains the format string instead of
+ ["%s", StringParam] causing problems sending Messages containt a %
+ - Added some space in the dialog for translations and added Translate()
+ function to some strings in the Wrapper-DLL
+ - More verbose output if you enable logging
+ - Fixes a Bug that caused the plugin to block after going offline
+ and reconnecting back online
+ - Hopefully fixed a severe threading problem: The Send-Mutex was not
+ covering a full transaction, but only 1 send causing the receiver
+ the receive garbled data causing "An existing connection was forcibly
+ closed by the remote host." error.
+ - Imo2S_Exit freed the temporary buffer too early resulting in a crash
+ on exit.
+ 1.12 - 19.04.2010 - POST interface changed from www.imo.im/amy to s.imo.im/amy
+ 1.13 - 19.12.2010 - imo.im modified their interface, so tried to adapt the communication
+ routines at low level to be compatible again. There still may be
+ many bugs. Don't forget to turn off history logging in the options
+ at https://imo.im
+ There also seems to be a nice new feature called "reflection" so that
+ you can login from multiple sessions and messages etc. entered there
+ will be reflected to the current session. This may be addressed in one
+ of the next builds...
+*/
+
+#include <stdio.h>
+#include "imo2sproxy.h"
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winsock2.h>
+#include <process.h>
+#define thread_t HANDLE
+#define LockMutex(x) EnterCriticalSection (&x)
+#define UnlockMutex(x) LeaveCriticalSection(&x)
+#define InitMutex(x) InitializeCriticalSection(&x)
+#define ExitMutex(x) DeleteCriticalSection(&x)
+#define strcasecmp stricmp
+#define strncasecmp stricmpn
+#define mutex_t CRITICAL_SECTION
+#define SHUT_RD SD_RECEIVE
+#define SHUT_WR SD_SEND
+#define SHUT_RDWR SD_BOTH
+#else
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <pthread.h>
+#include <errno.h>
+#include <unistd.h>
+#include <pthread.h>
+#define SOCKET int
+#define thread_t pthread_t
+#define mutex_t pthread_mutex_t
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR INVALID_SOCKET
+#define closesocket close
+#define LockMutex(x) pthread_mutex_lock(&x)
+#define UnlockMutex(x) pthread_mutex_unlock(&x)
+#define InitMutex(x) pthread_mutex_init(&x, NULL);
+#define ExitMutex(x)
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include "memlist.h"
+#include "socksproxy.h"
+
+// -----------------------------------------------------------------------------
+
+#define AUTHENTICATE 0x01
+#define CAPABILITIES 0x02
+#define USE_AUTHENTICATION 0x01
+
+typedef struct
+{
+ IMO2SPROXY vtbl; // Must be first!
+ IMO2SPROXY_CFG *pCfg;
+ SOCKSPROXY_CFG *pMyCfg;
+
+ SOCKET listen_fd;
+ volatile int iRunning;
+ mutex_t loopmutex;
+} IMO2SPROXY_INST;
+
+typedef struct
+{
+ SOCKET hSock;
+ thread_t hThread;
+ IMOSAPI *hInst;
+ int iConnectionStat;
+ mutex_t connected;
+ mutex_t sendmutex;
+ IMO2SPROXY_INST *hProxy;
+} CONNINST;
+
+
+// -----------------------------------------------------------------------------
+
+static void EventHandler(char *pszMsg, void *pUser);
+static void DispatcherThread(void *pUser);
+static int Dispatcher_Start(CONNINST *pInst);
+static int Dispatcher_Stop(CONNINST *pInst);
+static char *GetError(void);
+static int RcvPacket (CONNINST *pInst, void *buf, int len);
+static int SendPacket (CONNINST *pInst, void *buf, int len);
+static void FreeConnection (CONNINST *pInst);
+static void CleanConnections (TYP_LIST *hList);
+static SOCKET Init(unsigned long int lHost, short sPort, int iMaxConn);
+static void Loop(SOCKET listen_fd);
+static void Exit(SOCKET listen_fd);
+
+static int Imo2sproxy_Open(IMO2SPROXY *hInst);
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst);
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst);
+
+// -----------------------------------------------------------------------------
+static void EventHandler(char *pszMsg, void *pUser)
+{
+ CONNINST *pInst = (CONNINST*)pUser;
+ unsigned int uiLen = strlen (pszMsg);
+ static BOOL bFirstLogin = TRUE;
+
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "%03d> %s\n", pInst->hSock, pszMsg);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ if (bFirstLogin && strncmp (pszMsg, "CONNSTATUS", 10) == 0 &&
+ strcmp(pszMsg+11, "CONNECTING"))
+ {
+ pInst->iConnectionStat = (strcmp(pszMsg+11, "ONLINE")==0);
+ UnlockMutex (pInst->connected);
+ bFirstLogin = FALSE;
+ }
+ LockMutex(pInst->sendmutex);
+ if (!(SendPacket (pInst, &uiLen, sizeof(uiLen)) && SendPacket (pInst, pszMsg, uiLen)))
+ {
+ //Dispatcher_Stop(pInst);
+ //FreeConnection (pInst);
+ }
+ UnlockMutex(pInst->sendmutex);
+}
+
+// -----------------------------------------------------------------------------
+
+static void DispatcherThread(void *pUser)
+{
+ CONNINST *pInst = (CONNINST*)pUser;
+ char *pszUser, *pszPass, *pszError, *pszMsgBuf=NULL;
+ unsigned int uiLength, cbMsgBuf=0, bAuthenticated = 0, iConnected=0, iLogin=1;
+ char command=0, reply=0;
+
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ fprintf (pInst->hProxy->pCfg->fpLog, "Imo2sproxy::DispatcherThread()\n");
+
+ if (!(pInst->hInst = Imo2S_Init(EventHandler, pInst, pInst->hProxy->pCfg->iFlags)))
+ {
+ pInst->hProxy->pCfg->logerror (stderr, "Connection %d: Cannot start Imo2Skype instance.\n", pInst->hSock);
+ FreeConnection (pInst);
+ return;
+ }
+
+ // FIXME: Static user+pass from cmdline, until there is a possibility for
+ // a client to authenticate
+ pszUser = pInst->hProxy->pCfg->pszUser;
+ pszPass = pInst->hProxy->pCfg->pszPass;
+
+ // FIXME: We should enable logging dependent on a loglevel rather than just enabling it
+ if (pInst->hProxy->pCfg->bVerbose)
+ Imo2S_SetLog (pInst->hInst, pInst->hProxy->pCfg->fpLog);
+
+
+ while (pInst->hProxy->iRunning)
+ {
+ if (RcvPacket(pInst, &uiLength, sizeof(uiLength))<=0) break;
+ LockMutex(pInst->sendmutex);
+
+ if (uiLength == 0)
+ {
+ if (RcvPacket(pInst, &command, 1)<=0)
+ {
+ UnlockMutex(pInst->sendmutex);
+ break;
+ }
+ switch (command)
+ {
+ case AUTHENTICATE:
+ if (pInst->hProxy->pMyCfg->pszAuthPass) reply=1;
+ break;
+ case CAPABILITIES:
+ if (pInst->hProxy->pMyCfg->pszAuthPass) reply=USE_AUTHENTICATION;
+ break;
+ }
+ if (SendPacket (pInst, &reply, 1)<=0)
+ {
+ UnlockMutex(pInst->sendmutex);
+ break;
+ }
+ UnlockMutex(pInst->sendmutex);
+ continue;
+ }
+
+ if (uiLength >= cbMsgBuf)
+ {
+ pszMsgBuf = realloc (pszMsgBuf, uiLength+1);
+ if (!pszMsgBuf)
+ {
+ UnlockMutex(pInst->sendmutex);
+ break;
+ }
+ cbMsgBuf=uiLength+1;
+ }
+
+ if (RcvPacket(pInst, pszMsgBuf, uiLength)<=0)
+ {
+ UnlockMutex(pInst->sendmutex);
+ break;
+ }
+
+ if (command)
+ {
+ if (command == AUTHENTICATE)
+ {
+ bAuthenticated = pInst->hProxy->pMyCfg->pszAuthPass && strcmp(pInst->hProxy->pMyCfg->pszAuthPass, pszMsgBuf) == 0;
+ if (SendPacket (pInst, &bAuthenticated, 1)<=0)
+ {
+ UnlockMutex(pInst->sendmutex);
+ break;
+ }
+ }
+ command = 0;
+ }
+ UnlockMutex(pInst->sendmutex);
+
+ if (iLogin)
+ {
+ if (Imo2S_Login (pInst->hInst, pszUser, pszPass, &pszError) != 1)
+ {
+ pInst->hProxy->pCfg->logerror (stderr, "Connection %d: Cannot login with (%s/****): %s\n",
+ pInst->hSock, pszUser, pszError);
+ FreeConnection (pInst);
+ return;
+ }
+ iLogin = 0;
+ }
+
+ if (pInst->hProxy->pMyCfg->pszAuthPass && !bAuthenticated)continue;
+ pszMsgBuf[uiLength]=0;
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "%03d< [%s]\n", pInst->hSock, pszMsgBuf);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ if (!iConnected)
+ {
+ LockMutex (pInst->connected);
+ iConnected = pInst->iConnectionStat;
+ if (!iConnected)
+ {
+ pInst->hProxy->pCfg->logerror(stderr, "Invalid username / password");
+ }
+ }
+ Imo2S_Send (pInst->hInst, pszMsgBuf);
+ }
+
+ FreeConnection (pInst);
+ if (pszMsgBuf) free (pszMsgBuf);
+ return;
+}
+
+// -----------------------------------------------------------------------------
+
+#ifdef WIN32
+static int Dispatcher_Start(CONNINST *pInst)
+{
+ DWORD ThreadID;
+
+ return (pInst->hThread=(thread_t)_beginthreadex(NULL, 0,
+ (unsigned(__stdcall *)(void*))DispatcherThread, pInst, 0, &ThreadID))!=0;
+
+}
+
+static int Dispatcher_Stop(CONNINST *pInst)
+{
+ return pInst->hThread?TerminateThread (pInst->hThread, 0):1;
+}
+
+static char *GetError(void)
+{
+ static char szMessage[1024];
+ DWORD dwErr = WSAGetLastError();
+
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErr, 0, szMessage, sizeof(szMessage), NULL);
+ return szMessage;
+}
+
+#else
+static int Dispatcher_Start(CONNINST *pInst)
+{
+ return pthread_create(&pInst->hThread, NULL, DispatcherThread, pInst)==0;
+}
+
+static int Dispatcher_Stop(CONNINST *pInst)
+{
+ if (!pInst->hThread || pthread_cancel(pInst->hThread))
+ {
+ pInst->hThread=0;
+ return 1;
+ }
+ return 0;
+}
+
+static char *GetError(void)
+{
+ return strerror (errno);
+}
+
+#endif
+
+// -----------------------------------------------------------------------------
+
+static int RcvPacket (CONNINST *pInst, void *buf, int len)
+{
+ int iReceived = recv (pInst->hSock, buf, len, 0);
+ if (iReceived <= 0)
+ pInst->hProxy->pCfg->logerror(stderr, "Connection %d (Receive): %s", pInst->hSock, GetError());
+ return iReceived;
+}
+
+// -----------------------------------------------------------------------------
+
+static int SendPacket (CONNINST *pInst, void *buf, int len)
+{
+ int iSent;
+
+ iSent = send (pInst->hSock, buf, len, 0);
+ if (iSent <= 0)
+ pInst->hProxy->pCfg->logerror (stderr, "Connection %d (Send): %s", pInst->hSock, GetError());
+ return iSent;
+}
+// -----------------------------------------------------------------------------
+
+static void FreeConnection (CONNINST *pInst)
+{
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "Closed connection %d\n", pInst->hSock);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ if (pInst->hSock != INVALID_SOCKET)
+ closesocket(pInst->hSock);
+ pInst->hSock = INVALID_SOCKET;
+ pInst->hThread = 0;
+ ExitMutex (pInst->connected);
+ ExitMutex (pInst->sendmutex);
+ if (pInst->hInst)
+ {
+ IMOSAPI *hInst = pInst->hInst;
+ pInst->hInst = NULL;
+ Imo2S_Exit(hInst);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static void CleanConnections (TYP_LIST *hList)
+{
+ unsigned int i;
+ CONNINST *hInst;
+
+ for (i=0; i<List_Count(hList); i++)
+ {
+ hInst = List_ElementAt (hList, i);
+ if (hInst->hThread == 0)
+ {
+ free (List_RemoveElementAt(hList, i));
+ i--;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+// PUBLIC
+// -----------------------------------------------------------------------------
+
+void SocksProxy_Defaults (SOCKSPROXY_CFG *pMyCfg)
+{
+ memset (pMyCfg, 0, sizeof(SOCKSPROXY_CFG));
+ pMyCfg->lAddr = htonl(INADDR_ANY);
+ pMyCfg->sPort = 1401;
+ pMyCfg->iMaxConn = SOMAXCONN;
+}
+
+// -----------------------------------------------------------------------------
+
+IMO2SPROXY *SocksProxy_Init (IMO2SPROXY_CFG *pCfg, SOCKSPROXY_CFG *pMyCfg)
+{
+ IMO2SPROXY_INST *pstInst = calloc(sizeof(IMO2SPROXY_INST), 1);
+
+ pstInst->vtbl.Open = Imo2sproxy_Open;
+ pstInst->vtbl.Loop = Imo2sproxy_Loop;
+ pstInst->vtbl.Exit = Imo2sproxy_Exit;
+ pstInst->pCfg = pCfg;
+ pstInst->pMyCfg = pMyCfg;
+ InitMutex(pstInst->loopmutex);
+ return (IMO2SPROXY*)pstInst;
+}
+
+// -----------------------------------------------------------------------------
+// IMPLEMENTATION
+// -----------------------------------------------------------------------------
+static int Imo2sproxy_Open(IMO2SPROXY *hInst)
+{
+ struct sockaddr_in sock={0};
+ int yes = 1;
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+
+#ifdef WIN32
+ WSADATA wsaData;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
+ {
+ hProxy->pCfg->logerror (stderr, "WSAStartup failed");
+ return INVALID_SOCKET;
+ }
+#endif
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(Start)\n");
+ hProxy->listen_fd = socket(PF_INET, SOCK_STREAM, 0);
+ if(hProxy->listen_fd == INVALID_SOCKET) return -1;
+ if (setsockopt(hProxy->listen_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof(int))<0)
+ {
+ hProxy->pCfg->logerror (stderr, "Cannot set socket options to SO_REUSEADDR");
+ closesocket(hProxy->listen_fd);
+ return -1;
+ }
+ sock.sin_family = AF_INET;
+ sock.sin_addr.s_addr = hProxy->pMyCfg->lAddr;
+ sock.sin_port = htons(hProxy->pMyCfg->sPort);
+
+ if (bind(hProxy->listen_fd, (struct sockaddr *) &sock, sizeof(sock)) != 0)
+ {
+ hProxy->pCfg->logerror (stderr, "Cannot bind socket");
+ closesocket(hProxy->listen_fd);
+ return -1;
+ }
+
+ if (listen(hProxy->listen_fd, hProxy->pMyCfg->iMaxConn) < 0)
+ {
+ hProxy->pCfg->logerror (stderr, "Cannot listen on socket");
+ closesocket(hProxy->listen_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst)
+{
+ struct sockaddr_in sock;
+ int socklen;
+ SOCKET new_fd;
+ TYP_LIST *hConns = List_Init(32);
+ CONNINST *pInst;
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+ fd_set fdListen;
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(Start)\n");
+ hProxy->iRunning = 1;
+ LockMutex(hProxy->loopmutex);
+ while (hProxy->iRunning)
+ {
+ FD_ZERO(&fdListen);
+ FD_SET(hProxy->listen_fd, &fdListen);
+ socklen = sizeof(sock);
+ if (select (0, &fdListen, NULL, NULL, NULL) != SOCKET_ERROR && FD_ISSET(hProxy->listen_fd, &fdListen))
+ {
+ new_fd = accept(hProxy->listen_fd, (struct sockaddr *) &sock, &socklen);
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ {
+ fprintf (hProxy->pCfg->fpLog, "Connection from %s:%d -> Connection: %d\n", inet_ntoa(sock.sin_addr),
+ ntohs(sock.sin_port), new_fd);
+ fflush (hProxy->pCfg->fpLog);
+ }
+ if (new_fd != INVALID_SOCKET && (pInst = calloc (1, sizeof(CONNINST))))
+ {
+ CleanConnections (hConns);
+ List_Push(hConns, pInst);
+ pInst->hSock = new_fd;
+ pInst->hProxy = hProxy;
+ InitMutex(pInst->connected);
+ LockMutex(pInst->connected);
+ InitMutex(pInst->sendmutex);
+ Dispatcher_Start(pInst);
+ }
+ }
+ }
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(End)\n");
+
+ CleanConnections (hConns);
+ while (pInst=List_Pop(hConns))
+ {
+ Dispatcher_Stop(pInst);
+ FreeConnection(pInst);
+ free (pInst);
+ }
+ List_Exit(hConns);
+ UnlockMutex(hProxy->loopmutex);
+}
+
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "Socksproxy:Exit()\n");
+
+ hProxy->iRunning = 0;
+ shutdown (hProxy->listen_fd, SHUT_RDWR);
+ closesocket (hProxy->listen_fd);
+ LockMutex(hProxy->loopmutex);
+
+/*
+#ifdef WIN32
+ WSACleanup();
+#endif
+*/
+ UnlockMutex(hProxy->loopmutex);
+ ExitMutex(hProxy->loopmutex);
+ free (hProxy);
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.h
new file mode 100644
index 0000000000..6010e749f1
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/socksproxy.h
@@ -0,0 +1,11 @@
+typedef struct
+{
+ char *pszAuthPass;
+ unsigned long int lAddr;
+ short sPort;
+ int iMaxConn;
+} SOCKSPROXY_CFG;
+
+
+void SocksProxy_Defaults (SOCKSPROXY_CFG *pMyCfg);
+IMO2SPROXY *SocksProxy_Init (IMO2SPROXY_CFG *pCfg, SOCKSPROXY_CFG *pMyCfg);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.c
new file mode 100644
index 0000000000..8053a3c16d
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.c
@@ -0,0 +1,1143 @@
+/* Module: win32_browsewnd.c
+ Purpose: Displays a window with an embedded browser in order to display the Voicechat
+ flash from imo.im
+ This example is bsaed on the work of Jeff Glatt (http://www.codeproject.com/KB/COM/cwebpage.aspx?msg=2852721)
+ Author: leecher, credits go to Jeff Glatt for his excellent work.
+ Date: 18.10.2009
+*/
+
+#include <windows.h>
+#include <exdisp.h>
+#include <mshtml.h>
+#include <mshtmhst.h>
+#include <process.h>
+#include "memlist.h"
+#include "w32browser.h"
+
+#ifndef _WIN64
+#if WINVER<0x0500
+#define SetWindowLongPtr SetWindowLong
+#define GetWindowLongPtr GetWindowLong
+#endif
+#ifndef LONG_PTR
+#define LONG_PTR LONG
+#endif
+#ifndef GWLP_USERDATA
+#define GWLP_USERDATA GWL_USERDATA
+#endif
+#endif
+
+static const SAFEARRAYBOUND ArrayBound = {1, 0};
+static TYP_LIST *m_hWindows = NULL;
+static DWORD m_dwThread = 0;
+static HANDLE m_hThread = NULL, m_hEvent = NULL;
+
+
+HRESULT STDMETHODCALLTYPE Frame_QueryInterface(IOleInPlaceFrame FAR* This, REFIID riid, LPVOID FAR* ppvObj);
+HRESULT STDMETHODCALLTYPE Frame_AddRef(IOleInPlaceFrame FAR* This);
+HRESULT STDMETHODCALLTYPE Frame_Release(IOleInPlaceFrame FAR* This);
+HRESULT STDMETHODCALLTYPE Frame_GetWindow(IOleInPlaceFrame FAR* This, HWND FAR* lphwnd);
+HRESULT STDMETHODCALLTYPE Frame_ContextSensitiveHelp(IOleInPlaceFrame FAR* This, BOOL fEnterMode);
+HRESULT STDMETHODCALLTYPE Frame_GetBorder(IOleInPlaceFrame FAR* This, LPRECT lprectBorder);
+HRESULT STDMETHODCALLTYPE Frame_RequestBorderSpace(IOleInPlaceFrame FAR* This, LPCBORDERWIDTHS pborderwidths);
+HRESULT STDMETHODCALLTYPE Frame_SetBorderSpace(IOleInPlaceFrame FAR* This, LPCBORDERWIDTHS pborderwidths);
+HRESULT STDMETHODCALLTYPE Frame_SetActiveObject(IOleInPlaceFrame FAR* This, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName);
+HRESULT STDMETHODCALLTYPE Frame_InsertMenus(IOleInPlaceFrame FAR* This, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
+HRESULT STDMETHODCALLTYPE Frame_SetMenu(IOleInPlaceFrame FAR* This, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
+HRESULT STDMETHODCALLTYPE Frame_RemoveMenus(IOleInPlaceFrame FAR* This, HMENU hmenuShared);
+HRESULT STDMETHODCALLTYPE Frame_SetStatusText(IOleInPlaceFrame FAR* This, LPCOLESTR pszStatusText);
+HRESULT STDMETHODCALLTYPE Frame_EnableModeless(IOleInPlaceFrame FAR* This, BOOL fEnable);
+HRESULT STDMETHODCALLTYPE Frame_TranslateAccelerator(IOleInPlaceFrame FAR* This, LPMSG lpmsg, WORD wID);
+
+IOleInPlaceFrameVtbl MyIOleInPlaceFrameTable = {Frame_QueryInterface,
+Frame_AddRef,
+Frame_Release,
+Frame_GetWindow,
+Frame_ContextSensitiveHelp,
+Frame_GetBorder,
+Frame_RequestBorderSpace,
+Frame_SetBorderSpace,
+Frame_SetActiveObject,
+Frame_InsertMenus,
+Frame_SetMenu,
+Frame_RemoveMenus,
+Frame_SetStatusText,
+Frame_EnableModeless,
+Frame_TranslateAccelerator};
+
+typedef struct {
+ IOleInPlaceFrame frame;
+ HWND window;
+} _IOleInPlaceFrameEx;
+
+HRESULT STDMETHODCALLTYPE Site_QueryInterface(IOleClientSite FAR* This, REFIID riid, void ** ppvObject);
+HRESULT STDMETHODCALLTYPE Site_AddRef(IOleClientSite FAR* This);
+HRESULT STDMETHODCALLTYPE Site_Release(IOleClientSite FAR* This);
+HRESULT STDMETHODCALLTYPE Site_SaveObject(IOleClientSite FAR* This);
+HRESULT STDMETHODCALLTYPE Site_GetMoniker(IOleClientSite FAR* This, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk);
+HRESULT STDMETHODCALLTYPE Site_GetContainer(IOleClientSite FAR* This, LPOLECONTAINER FAR* ppContainer);
+HRESULT STDMETHODCALLTYPE Site_ShowObject(IOleClientSite FAR* This);
+HRESULT STDMETHODCALLTYPE Site_OnShowWindow(IOleClientSite FAR* This, BOOL fShow);
+HRESULT STDMETHODCALLTYPE Site_RequestNewObjectLayout(IOleClientSite FAR* This);
+
+IOleClientSiteVtbl MyIOleClientSiteTable = {Site_QueryInterface,
+Site_AddRef,
+Site_Release,
+Site_SaveObject,
+Site_GetMoniker,
+Site_GetContainer,
+Site_ShowObject,
+Site_OnShowWindow,
+Site_RequestNewObjectLayout};
+
+HRESULT STDMETHODCALLTYPE UI_QueryInterface(IDocHostUIHandler FAR* This, REFIID riid, void ** ppvObject);
+HRESULT STDMETHODCALLTYPE UI_AddRef(IDocHostUIHandler FAR* This);
+HRESULT STDMETHODCALLTYPE UI_Release(IDocHostUIHandler FAR* This);
+HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler FAR* This, DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved);
+HRESULT STDMETHODCALLTYPE UI_GetHostInfo(IDocHostUIHandler FAR* This, DOCHOSTUIINFO __RPC_FAR *pInfo);
+HRESULT STDMETHODCALLTYPE UI_ShowUI(IDocHostUIHandler FAR* This, DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc);
+HRESULT STDMETHODCALLTYPE UI_HideUI(IDocHostUIHandler FAR* This);
+HRESULT STDMETHODCALLTYPE UI_UpdateUI(IDocHostUIHandler FAR* This);
+HRESULT STDMETHODCALLTYPE UI_EnableModeless(IDocHostUIHandler FAR* This, BOOL fEnable);
+HRESULT STDMETHODCALLTYPE UI_OnDocWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate);
+HRESULT STDMETHODCALLTYPE UI_OnFrameWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate);
+HRESULT STDMETHODCALLTYPE UI_ResizeBorder(IDocHostUIHandler FAR* This, LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow);
+HRESULT STDMETHODCALLTYPE UI_TranslateAccelerator(IDocHostUIHandler FAR* This, LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID);
+HRESULT STDMETHODCALLTYPE UI_GetOptionKeyPath(IDocHostUIHandler FAR* This, LPOLESTR __RPC_FAR *pchKey, DWORD dw);
+HRESULT STDMETHODCALLTYPE UI_GetDropTarget(IDocHostUIHandler FAR* This, IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget);
+HRESULT STDMETHODCALLTYPE UI_GetExternal(IDocHostUIHandler FAR* This, IDispatch __RPC_FAR *__RPC_FAR *ppDispatch);
+HRESULT STDMETHODCALLTYPE UI_TranslateUrl(IDocHostUIHandler FAR* This, DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut);
+HRESULT STDMETHODCALLTYPE UI_FilterDataObject(IDocHostUIHandler FAR* This, IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet);
+
+IDocHostUIHandlerVtbl MyIDocHostUIHandlerTable = {UI_QueryInterface,
+UI_AddRef,
+UI_Release,
+UI_ShowContextMenu,
+UI_GetHostInfo,
+UI_ShowUI,
+UI_HideUI,
+UI_UpdateUI,
+UI_EnableModeless,
+UI_OnDocWindowActivate,
+UI_OnFrameWindowActivate,
+UI_ResizeBorder,
+UI_TranslateAccelerator,
+UI_GetOptionKeyPath,
+UI_GetDropTarget,
+UI_GetExternal,
+UI_TranslateUrl,
+UI_FilterDataObject};
+
+HRESULT STDMETHODCALLTYPE InPlace_QueryInterface(IOleInPlaceSite FAR* This, REFIID riid, void ** ppvObject);
+HRESULT STDMETHODCALLTYPE InPlace_AddRef(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_Release(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_GetWindow(IOleInPlaceSite FAR* This, HWND FAR* lphwnd);
+HRESULT STDMETHODCALLTYPE InPlace_ContextSensitiveHelp(IOleInPlaceSite FAR* This, BOOL fEnterMode);
+HRESULT STDMETHODCALLTYPE InPlace_CanInPlaceActivate(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceActivate(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_OnUIActivate(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_GetWindowContext(IOleInPlaceSite FAR* This, LPOLEINPLACEFRAME FAR* lplpFrame,LPOLEINPLACEUIWINDOW FAR* lplpDoc,LPRECT lprcPosRect,LPRECT lprcClipRect,LPOLEINPLACEFRAMEINFO lpFrameInfo);
+HRESULT STDMETHODCALLTYPE InPlace_Scroll(IOleInPlaceSite FAR* This, SIZE scrollExtent);
+HRESULT STDMETHODCALLTYPE InPlace_OnUIDeactivate(IOleInPlaceSite FAR* This, BOOL fUndoable);
+HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceDeactivate(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_DiscardUndoState(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_DeactivateAndUndo(IOleInPlaceSite FAR* This);
+HRESULT STDMETHODCALLTYPE InPlace_OnPosRectChange(IOleInPlaceSite FAR* This, LPCRECT lprcPosRect);
+
+IOleInPlaceSiteVtbl MyIOleInPlaceSiteTable = {InPlace_QueryInterface,
+InPlace_AddRef,
+InPlace_Release,
+InPlace_GetWindow,
+InPlace_ContextSensitiveHelp,
+InPlace_CanInPlaceActivate,
+InPlace_OnInPlaceActivate,
+InPlace_OnUIActivate,
+InPlace_GetWindowContext,
+InPlace_Scroll,
+InPlace_OnUIDeactivate,
+InPlace_OnInPlaceDeactivate,
+InPlace_DiscardUndoState,
+InPlace_DeactivateAndUndo,
+InPlace_OnPosRectChange};
+
+typedef struct {
+ IOleInPlaceSite inplace;
+ _IOleInPlaceFrameEx frame;
+} _IOleInPlaceSiteEx;
+
+typedef struct {
+ IDocHostUIHandler ui;
+} _IDocHostUIHandlerEx;
+
+typedef struct {
+ IOleClientSite client;
+ _IOleInPlaceSiteEx inplace;
+ _IDocHostUIHandlerEx ui;
+} _IOleClientSiteEx;
+
+#define NOTIMPLEMENTED return(E_NOTIMPL)
+
+typedef struct
+{
+ char *pszHTML;
+ char *pszTitle;
+ int width;
+ int height;
+ HWND hWnd; // out
+} ShowIEWndParam;
+
+
+//////////////////////////////////// My IDocHostUIHandler functions //////////////////////////////////////
+//
+HRESULT STDMETHODCALLTYPE UI_QueryInterface(IDocHostUIHandler FAR* This, REFIID riid, LPVOID FAR* ppvObj)
+{
+ return(Site_QueryInterface((IOleClientSite *)((char *)This - sizeof(IOleClientSite) - sizeof(_IOleInPlaceSiteEx)), riid, ppvObj));
+}
+
+HRESULT STDMETHODCALLTYPE UI_AddRef(IDocHostUIHandler FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE UI_Release(IDocHostUIHandler FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler FAR* This, DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_GetHostInfo(IDocHostUIHandler FAR* This, DOCHOSTUIINFO __RPC_FAR *pInfo)
+{
+ pInfo->cbSize = sizeof(DOCHOSTUIINFO);
+ pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER;
+ pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_ShowUI(IDocHostUIHandler FAR* This, DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_HideUI(IDocHostUIHandler FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_UpdateUI(IDocHostUIHandler FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_EnableModeless(IDocHostUIHandler FAR* This, BOOL fEnable)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_OnDocWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_OnFrameWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_ResizeBorder(IDocHostUIHandler FAR* This, LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE UI_TranslateAccelerator(IDocHostUIHandler FAR* This, LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID)
+{
+ return(S_FALSE);
+}
+
+HRESULT STDMETHODCALLTYPE UI_GetOptionKeyPath(IDocHostUIHandler FAR* This, LPOLESTR __RPC_FAR *pchKey, DWORD dw)
+{
+ return(S_FALSE);
+}
+
+HRESULT STDMETHODCALLTYPE UI_GetDropTarget(IDocHostUIHandler FAR* This, IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)
+{
+ return(S_FALSE);
+}
+
+HRESULT STDMETHODCALLTYPE UI_GetExternal(IDocHostUIHandler FAR* This, IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
+{
+ *ppDispatch = 0;
+ return(S_FALSE);
+}
+
+HRESULT STDMETHODCALLTYPE UI_TranslateUrl(IDocHostUIHandler FAR* This, DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
+{
+ *ppchURLOut = 0;
+ return(S_FALSE);
+}
+
+HRESULT STDMETHODCALLTYPE UI_FilterDataObject(IDocHostUIHandler FAR* This, IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet)
+{
+ *ppDORet = 0;
+ return(S_FALSE);
+}
+
+////////////////////////////////////// My IOleClientSite functions /////////////////////////////////////
+//
+
+HRESULT STDMETHODCALLTYPE Site_QueryInterface(IOleClientSite FAR* This, REFIID riid, void ** ppvObject)
+{
+ if (!memcmp(riid, &IID_IUnknown, sizeof(GUID)) || !memcmp(riid, &IID_IOleClientSite, sizeof(GUID)))
+ *ppvObject = &((_IOleClientSiteEx *)This)->client;
+ else if (!memcmp(riid, &IID_IOleInPlaceSite, sizeof(GUID)))
+ *ppvObject = &((_IOleClientSiteEx *)This)->inplace;
+ else if (!memcmp(riid, &IID_IDocHostUIHandler, sizeof(GUID)))
+ *ppvObject = &((_IOleClientSiteEx *)This)->ui;
+ else
+ {
+ *ppvObject = 0;
+ return(E_NOINTERFACE);
+ }
+
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Site_AddRef(IOleClientSite FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE Site_Release(IOleClientSite FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE Site_SaveObject(IOleClientSite FAR* This)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Site_GetMoniker(IOleClientSite FAR* This, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Site_GetContainer(IOleClientSite FAR* This, LPOLECONTAINER FAR* ppContainer)
+{
+ *ppContainer = 0;
+
+ return(E_NOINTERFACE);
+}
+
+HRESULT STDMETHODCALLTYPE Site_ShowObject(IOleClientSite FAR* This)
+{
+ return(NOERROR);
+}
+
+HRESULT STDMETHODCALLTYPE Site_OnShowWindow(IOleClientSite FAR* This, BOOL fShow)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Site_RequestNewObjectLayout(IOleClientSite FAR* This)
+{
+ NOTIMPLEMENTED;
+}
+
+
+////////////////////////////////////// My IOleInPlaceSite functions /////////////////////////////////////
+//
+HRESULT STDMETHODCALLTYPE InPlace_QueryInterface(IOleInPlaceSite FAR* This, REFIID riid, LPVOID FAR* ppvObj)
+{
+ return(Site_QueryInterface((IOleClientSite *)((char *)This - sizeof(IOleClientSite)), riid, ppvObj));
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_AddRef(IOleInPlaceSite FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_Release(IOleInPlaceSite FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_GetWindow(IOleInPlaceSite FAR* This, HWND FAR* lphwnd)
+{
+ *lphwnd = ((_IOleInPlaceSiteEx FAR*)This)->frame.window;
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_ContextSensitiveHelp(IOleInPlaceSite FAR* This, BOOL fEnterMode)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_CanInPlaceActivate(IOleInPlaceSite FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceActivate(IOleInPlaceSite FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_OnUIActivate(IOleInPlaceSite FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_GetWindowContext(IOleInPlaceSite FAR* This, LPOLEINPLACEFRAME FAR* lplpFrame, LPOLEINPLACEUIWINDOW FAR* lplpDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
+{
+ *lplpFrame = (LPOLEINPLACEFRAME)&((_IOleInPlaceSiteEx *)This)->frame;
+ *lplpDoc = 0;
+
+ lpFrameInfo->fMDIApp = FALSE;
+ lpFrameInfo->hwndFrame = ((_IOleInPlaceFrameEx *)*lplpFrame)->window;
+ lpFrameInfo->haccel = 0;
+ lpFrameInfo->cAccelEntries = 0;
+
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_Scroll(IOleInPlaceSite FAR* This, SIZE scrollExtent)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_OnUIDeactivate(IOleInPlaceSite FAR* This, BOOL fUndoable)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceDeactivate(IOleInPlaceSite FAR* This)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_DiscardUndoState(IOleInPlaceSite FAR* This)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_DeactivateAndUndo(IOleInPlaceSite FAR* This)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE InPlace_OnPosRectChange(IOleInPlaceSite FAR* This, LPCRECT lprcPosRect)
+{
+ IOleObject *browserObject;
+ IOleInPlaceObject *inplace;
+
+ browserObject = *((IOleObject **)((char *)This - sizeof(IOleObject *) - sizeof(IOleClientSite)));
+ if (!browserObject->lpVtbl->QueryInterface(browserObject, &IID_IOleInPlaceObject, (void**)&inplace))
+ {
+ inplace->lpVtbl->SetObjectRects(inplace, lprcPosRect, lprcPosRect);
+ inplace->lpVtbl->Release(inplace);
+ }
+
+ return(S_OK);
+}
+
+
+
+////////////////////////////////////// My IOleInPlaceFrame functions /////////////////////////////////////////
+//
+HRESULT STDMETHODCALLTYPE Frame_QueryInterface(IOleInPlaceFrame FAR* This, REFIID riid, LPVOID FAR* ppvObj)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_AddRef(IOleInPlaceFrame FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_Release(IOleInPlaceFrame FAR* This)
+{
+ return(1);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_GetWindow(IOleInPlaceFrame FAR* This, HWND FAR* lphwnd)
+{
+ *lphwnd = ((_IOleInPlaceFrameEx *)This)->window;
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_ContextSensitiveHelp(IOleInPlaceFrame FAR* This, BOOL fEnterMode)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_GetBorder(IOleInPlaceFrame FAR* This, LPRECT lprectBorder)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_RequestBorderSpace(IOleInPlaceFrame FAR* This, LPCBORDERWIDTHS pborderwidths)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_SetBorderSpace(IOleInPlaceFrame FAR* This, LPCBORDERWIDTHS pborderwidths)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_SetActiveObject(IOleInPlaceFrame FAR* This, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_InsertMenus(IOleInPlaceFrame FAR* This, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_SetMenu(IOleInPlaceFrame FAR* This, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_RemoveMenus(IOleInPlaceFrame FAR* This, HMENU hmenuShared)
+{
+ NOTIMPLEMENTED;
+}
+
+HRESULT STDMETHODCALLTYPE Frame_SetStatusText(IOleInPlaceFrame FAR* This, LPCOLESTR pszStatusText)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_EnableModeless(IOleInPlaceFrame FAR* This, BOOL fEnable)
+{
+ return(S_OK);
+}
+
+HRESULT STDMETHODCALLTYPE Frame_TranslateAccelerator(IOleInPlaceFrame FAR* This, LPMSG lpmsg, WORD wID)
+{
+ NOTIMPLEMENTED;
+}
+
+
+
+
+/*************************** UnEmbedBrowserObject() ************************
+ * Called to detach the browser object from our host window, and free its
+ * resources, right before we destroy our window.
+ *
+ * hwnd = Handle to the window hosting the browser object.
+ *
+ * NOTE: The pointer to the browser object must have been stored in the
+ * window's USERDATA field. In other words, don't call UnEmbedBrowserObject().
+ * with a HWND that wasn't successfully passed to EmbedBrowserObject().
+ */
+
+void UnEmbedBrowserObject(HWND hwnd)
+{
+ IOleObject **browserHandle;
+ IOleObject *browserObject;
+
+ // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+ // we initially attached the browser object to this window.
+ if ((browserHandle = (IOleObject **)GetWindowLongPtr(hwnd, GWLP_USERDATA)))
+ {
+ // Unembed the browser object, and release its resources.
+ browserObject = *browserHandle;
+ browserObject->lpVtbl->Close(browserObject, OLECLOSE_NOSAVE);
+ browserObject->lpVtbl->Release(browserObject);
+
+ GlobalFree(browserHandle);
+
+ return;
+ }
+}
+
+
+/******************************* DisplayHTMLStr() ****************************
+ * Takes a string containing some HTML BODY, and displays it in the specified
+ * window. For example, perhaps you want to display the HTML text of...
+ *
+ * <P>This is a picture.<P><IMG src="mypic.jpg">
+ *
+ * hwnd = Handle to the window hosting the browser object.
+ * string = Pointer to nul-terminated string containing the HTML BODY.
+ * (NOTE: No <BODY></BODY> tags are required in the string).
+ *
+ * RETURNS: 0 if success, or non-zero if an error.
+ *
+ * NOTE: EmbedBrowserObject() must have been successfully called once with the
+ * specified window, prior to calling this function. You need call
+ * EmbedBrowserObject() once only, and then you can make multiple calls to
+ * this function to display numerous pages in the specified window.
+ */
+
+long DisplayHTMLStr(HWND hwnd, LPCTSTR string)
+{
+ IWebBrowser2 *webBrowser2;
+ LPDISPATCH lpDispatch;
+ IHTMLDocument2 *htmlDoc2;
+ IOleObject *browserObject;
+ SAFEARRAY *sfArray;
+ VARIANT myURL;
+ VARIANT *pVar;
+ BSTR bstr;
+
+ // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+ // we initially attached the browser object to this window.
+ browserObject = *((IOleObject **)GetWindowLongPtr(hwnd, GWLP_USERDATA));
+
+ // Assume an error.
+ bstr = 0;
+
+ // We want to get the base address (ie, a pointer) to the IWebBrowser2 object embedded within the browser
+ // object, so we can call some of the functions in the former's table.
+ if (!browserObject->lpVtbl->QueryInterface(browserObject, &IID_IWebBrowser2, (void**)&webBrowser2))
+ {
+ // Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is
+ // webBrowser2->lpVtbl.
+
+ // Before we can get_Document(), we actually need to have some HTML page loaded in the browser. So,
+ // let's load an empty HTML page. Then, once we have that empty page, we can get_Document() and
+ // write() to stuff our HTML string into it.
+ VariantInit(&myURL);
+ myURL.vt = VT_BSTR;
+ myURL.bstrVal = SysAllocString(L"about:blank");
+
+ // Call the Navigate2() function to actually display the page.
+ webBrowser2->lpVtbl->Navigate2(webBrowser2, &myURL, 0, 0, 0, 0);
+
+ // Free any resources (including the BSTR).
+ VariantClear(&myURL);
+
+ // Call the IWebBrowser2 object's get_Document so we can get its DISPATCH object. I don't know why you
+ // don't get the DISPATCH object via the browser object's QueryInterface(), but you don't.
+ if (!webBrowser2->lpVtbl->get_Document(webBrowser2, &lpDispatch))
+ {
+ // We want to get a pointer to the IHTMLDocument2 object embedded within the DISPATCH
+ // object, so we can call some of the functions in the former's table.
+ if (!lpDispatch->lpVtbl->QueryInterface(lpDispatch, &IID_IHTMLDocument2, (void**)&htmlDoc2))
+ {
+ // Ok, now the pointer to our IHTMLDocument2 object is in 'htmlDoc2', and so its VTable is
+ // htmlDoc2->lpVtbl.
+
+ // Our HTML must be in the form of a BSTR. And it must be passed to write() in an
+ // array of "VARIENT" structs. So let's create all that.
+ if ((sfArray = SafeArrayCreate(VT_VARIANT, 1, (SAFEARRAYBOUND *)&ArrayBound)))
+ {
+ if (!SafeArrayAccessData(sfArray, (void**)&pVar))
+ {
+ pVar->vt = VT_BSTR;
+#ifndef UNICODE
+ {
+ wchar_t *buffer;
+ DWORD size;
+
+ size = MultiByteToWideChar(CP_ACP, 0, string, -1, 0, 0);
+ if (!(buffer = (wchar_t *)GlobalAlloc(GMEM_FIXED, sizeof(wchar_t) * size))) goto bad;
+ MultiByteToWideChar(CP_ACP, 0, string, -1, buffer, size);
+ bstr = SysAllocString(buffer);
+ GlobalFree(buffer);
+ }
+#else
+ bstr = SysAllocString(string);
+#endif
+ // Store our BSTR pointer in the VARIENT.
+ if ((pVar->bstrVal = bstr))
+ {
+ htmlDoc2->lpVtbl->clear(htmlDoc2);
+ // Pass the VARIENT with its BSTR to write() in order to shove our desired HTML string
+ // into the body of that empty page we created above.
+ htmlDoc2->lpVtbl->write(htmlDoc2, sfArray);
+
+ // Close the document. If we don't do this, subsequent calls to DisplayHTMLStr
+ // would append to the current contents of the page
+ htmlDoc2->lpVtbl->close(htmlDoc2);
+
+ // Normally, we'd need to free our BSTR, but SafeArrayDestroy() does it for us
+// SysFreeString(bstr);
+ }
+ }
+
+ // Free the array. This also frees the VARIENT that SafeArrayAccessData created for us,
+ // and even frees the BSTR we allocated with SysAllocString
+ SafeArrayDestroy(sfArray);
+ }
+
+ // Release the IHTMLDocument2 object.
+bad: htmlDoc2->lpVtbl->Release(htmlDoc2);
+ }
+
+ // Release the DISPATCH object.
+ lpDispatch->lpVtbl->Release(lpDispatch);
+ }
+
+ // Release the IWebBrowser2 object.
+ webBrowser2->lpVtbl->Release(webBrowser2);
+ }
+
+ // No error?
+ if (bstr) return(0);
+
+ // An error
+ return(-1);
+}
+
+
+
+/******************************* ResizeBrowser() ****************************
+ * Resizes the browser object for the specified window to the specified
+ * width and height.
+ *
+ * hwnd = Handle to the window hosting the browser object.
+ * width = Width.
+ * height = Height.
+ *
+ * NOTE: EmbedBrowserObject() must have been successfully called once with the
+ * specified window, prior to calling this function. You need call
+ * EmbedBrowserObject() once only, and then you can make multiple calls to
+ * this function to resize the browser object.
+ */
+
+void ResizeBrowser(HWND hwnd, DWORD width, DWORD height)
+{
+ IWebBrowser2 *webBrowser2;
+ IOleObject *browserObject;
+
+ // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+ // we initially attached the browser object to this window.
+ browserObject = *((IOleObject **)GetWindowLongPtr(hwnd, GWLP_USERDATA));
+
+ // We want to get the base address (ie, a pointer) to the IWebBrowser2 object embedded within the browser
+ // object, so we can call some of the functions in the former's table.
+ if (!browserObject->lpVtbl->QueryInterface(browserObject, &IID_IWebBrowser2, (void**)&webBrowser2))
+ {
+ // Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is
+ // webBrowser2->lpVtbl.
+
+ // Call are put_Width() and put_Height() to set the new width/height.
+ webBrowser2->lpVtbl->put_Width(webBrowser2, width);
+ webBrowser2->lpVtbl->put_Height(webBrowser2, height);
+
+ // We no longer need the IWebBrowser2 object (ie, we don't plan to call any more functions in it,
+ // so we can release our hold on it). Note that we'll still maintain our hold on the browser
+ // object.
+ webBrowser2->lpVtbl->Release(webBrowser2);
+ }
+}
+
+
+
+
+
+/***************************** EmbedBrowserObject() **************************
+ * Puts the browser object inside our host window, and save a pointer to this
+ * window's browser object in the window's GWL_USERDATA field.
+ *
+ * hwnd = Handle of our window into which we embed the browser object.
+ *
+ * RETURNS: 0 if success, or non-zero if an error.
+ *
+ * NOTE: We tell the browser object to occupy the entire client area of the
+ * window.
+ *
+ * NOTE: No HTML page will be displayed here. We can do that with a subsequent
+ * call to either DisplayHTMLPage() or DisplayHTMLStr(). This is merely once-only
+ * initialization for using the browser object. In a nutshell, what we do
+ * here is get a pointer to the browser object in our window's GWL_USERDATA
+ * so we can access that object's functions whenever we want, and we also pass
+ * the browser a pointer to our IOleClientSite struct so that the browser can
+ * call our functions in our struct's VTable.
+ */
+
+long EmbedBrowserObject(HWND hwnd)
+{
+ LPCLASSFACTORY pClassFactory;
+ IOleObject *browserObject;
+ IWebBrowser2 *webBrowser2;
+ RECT rect;
+ char *ptr;
+ _IOleClientSiteEx *_iOleClientSiteEx;
+
+ // Our IOleClientSite, IOleInPlaceSite, and IOleInPlaceFrame functions need to get our window handle. We
+ // could store that in some global. But then, that would mean that our functions would work with only that
+ // one window. If we want to create multiple windows, each hosting its own browser object (to display its
+ // own web page), then we need to create unique IOleClientSite, IOleInPlaceSite, and IOleInPlaceFrame
+ // structs for each window. And we'll put an extra field at the end of those structs to store our extra
+ // data such as a window handle. So, our functions won't have to touch global data, and can therefore be
+ // re-entrant and work with multiple objects/windows.
+ //
+ // Remember that a pointer to our IOleClientSite we create here will be passed as the first arg to every
+ // one of our IOleClientSite functions. Ditto with the IOleInPlaceFrame object we create here, and the
+ // IOleInPlaceFrame functions. So, our functions are able to retrieve the window handle we'll store here,
+ // and then, they'll work with all such windows containing a browser control.
+ //
+ // Furthermore, since the browser will be calling our IOleClientSite's QueryInterface to get a pointer to
+ // our IOleInPlaceSite and IDocHostUIHandler objects, that means that our IOleClientSite QueryInterface
+ // must have an easy way to grab those pointers. Probably the easiest thing to do is just embed our
+ // IOleInPlaceSite and IDocHostUIHandler objects inside of an extended IOleClientSite which we'll call
+ // a _IOleClientSiteEx. As long as they come after the pointer to the IOleClientSite VTable, then we're
+ // ok.
+ //
+ // Of course, we need to GlobalAlloc the above structs now. We'll just get all 4 with a single call to
+ // GlobalAlloc, especially since 3 of them are all contained inside of our _IOleClientSiteEx anyway.
+ //
+ // So, we're not actually allocating separate IOleClientSite, IOleInPlaceSite, IOleInPlaceFrame and
+ // IDocHostUIHandler structs.
+ //
+ // One final thing. We're going to allocate extra room to store the pointer to the browser object.
+ if (!(ptr = (char *)GlobalAlloc(GMEM_FIXED, sizeof(_IOleClientSiteEx) + sizeof(IOleObject *))))
+ return(-1);
+
+ // Initialize our IOleClientSite object with a pointer to our IOleClientSite VTable.
+ _iOleClientSiteEx = (_IOleClientSiteEx *)(ptr + sizeof(IOleObject *));
+ _iOleClientSiteEx->client.lpVtbl = &MyIOleClientSiteTable;
+
+ // Initialize our IOleInPlaceSite object with a pointer to our IOleInPlaceSite VTable.
+ _iOleClientSiteEx->inplace.inplace.lpVtbl = &MyIOleInPlaceSiteTable;
+
+ // Initialize our IOleInPlaceFrame object with a pointer to our IOleInPlaceFrame VTable.
+ _iOleClientSiteEx->inplace.frame.frame.lpVtbl = &MyIOleInPlaceFrameTable;
+
+ // Save our HWND (in the IOleInPlaceFrame object) so our IOleInPlaceFrame functions can retrieve it.
+ _iOleClientSiteEx->inplace.frame.window = hwnd;
+
+ // Initialize our IDocHostUIHandler object with a pointer to our IDocHostUIHandler VTable.
+ _iOleClientSiteEx->ui.ui.lpVtbl = &MyIDocHostUIHandlerTable;
+
+ // Get a pointer to the browser object and lock it down (so it doesn't "disappear" while we're using
+ // it in this program). We do this by calling the OS function CoGetClassObject().
+ //
+ // NOTE: We need this pointer to interact with and control the browser. With normal WIN32 controls such as a
+ // Static, Edit, Combobox, etc, you obtain an HWND and send messages to it with SendMessage(). Not so with
+ // the browser object. You need to get a pointer to its "base structure" (as returned by CoGetClassObject()). This
+ // structure contains an array of pointers to functions you can call within the browser object. Actually, the
+ // base structure contains a 'lpVtbl' field that is a pointer to that array. We'll call the array a 'VTable'.
+ //
+ // For example, the browser object happens to have a SetHostNames() function we want to call. So, after we
+ // retrieve the pointer to the browser object (in a local we'll name 'browserObject'), then we can call that
+ // function, and pass it args, as so:
+ //
+ // browserObject->lpVtbl->SetHostNames(browserObject, SomeString, SomeString);
+ //
+ // There's our pointer to the browser object in 'browserObject'. And there's the pointer to the browser object's
+ // VTable in 'browserObject->lpVtbl'. And the pointer to the SetHostNames function happens to be stored in an
+ // field named 'SetHostNames' within the VTable. So we are actually indirectly calling SetHostNames by using
+ // a pointer to it. That's how you use a VTable.
+ //
+ // NOTE: We pass our _IOleClientSiteEx struct and lie -- saying that it's a IOleClientSite. It's ok. A
+ // _IOleClientSiteEx struct starts with an embedded IOleClientSite. So the browser won't care, and we want
+ // this extended struct passed to our IOleClientSite functions.
+
+ // Get a pointer to the browser object's IClassFactory object via CoGetClassObject()
+ pClassFactory = 0;
+ if (!CoGetClassObject(&CLSID_WebBrowser, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, NULL, &IID_IClassFactory, (void **)&pClassFactory) && pClassFactory)
+ {
+ // Call the IClassFactory's CreateInstance() to create a browser object
+ if (!pClassFactory->lpVtbl->CreateInstance(pClassFactory, 0, &IID_IOleObject, &browserObject))
+ {
+ // Free the IClassFactory. We need it only to create a browser object instance
+ pClassFactory->lpVtbl->Release(pClassFactory);
+
+ // Ok, we now have the pointer to the browser object in 'browserObject'. Let's save this in the
+ // memory block we allocated above, and then save the pointer to that whole thing in our window's
+ // USERDATA field. That way, if we need multiple windows each hosting its own browser object, we can
+ // call EmbedBrowserObject() for each one, and easily associate the appropriate browser object with
+ // its matching window and its own objects containing per-window data.
+ *((IOleObject **)ptr) = browserObject;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ptr);
+
+ // Give the browser a pointer to my IOleClientSite object
+ if (!browserObject->lpVtbl->SetClientSite(browserObject, (IOleClientSite *)_iOleClientSiteEx))
+ {
+ // We can now call the browser object's SetHostNames function. SetHostNames lets the browser object know our
+ // application's name and the name of the document in which we're embedding the browser. (Since we have no
+ // document name, we'll pass a 0 for the latter). When the browser object is opened for editing, it displays
+ // these names in its titlebar.
+ //
+ // We are passing 3 args to SetHostNames. You'll note that the first arg to SetHostNames is the base
+ // address of our browser control. This is something that you always have to remember when working in C
+ // (as opposed to C++). When calling a VTable function, the first arg to that function must always be the
+ // structure which contains the VTable. (In this case, that's the browser control itself). Why? That's
+ // because that function is always assumed to be written in C++. And the first argument to any C++ function
+ // must be its 'this' pointer (ie, the base address of its class, which in this case is our browser object
+ // pointer). In C++, you don't have to pass this first arg, because the C++ compiler is smart enough to
+ // produce an executable that always adds this first arg. In fact, the C++ compiler is smart enough to
+ // know to fetch the function pointer from the VTable, so you don't even need to reference that. In other
+ // words, the C++ equivalent code would be:
+ //
+ // browserObject->SetHostNames(L"My Host Name", 0);
+ //
+ // So, when you're trying to convert C++ code to C, always remember to add this first arg whenever you're
+ // dealing with a VTable (ie, the field is usually named 'lpVtbl') in the standard objects, and also add
+ // the reference to the VTable itself.
+ //
+ // Oh yeah, the L is because we need UNICODE strings. And BTW, the host and document names can be anything
+ // you want.
+ browserObject->lpVtbl->SetHostNames(browserObject, L"My Host Name", 0);
+
+ GetClientRect(hwnd, &rect);
+
+ // Let browser object know that it is embedded in an OLE container.
+ if (!OleSetContainedObject((struct IUnknown *)browserObject, TRUE) &&
+
+ // Set the display area of our browser control the same as our window's size
+ // and actually put the browser object into our window.
+ !browserObject->lpVtbl->DoVerb(browserObject, OLEIVERB_SHOW, NULL, (IOleClientSite *)_iOleClientSiteEx, -1, hwnd, &rect) &&
+
+ // Ok, now things may seem to get even trickier, One of those function pointers in the browser's VTable is
+ // to the QueryInterface() function. What does this function do? It lets us grab the base address of any
+ // other object that may be embedded within the browser object. And this other object has its own VTable
+ // containing pointers to more functions we can call for that object.
+ //
+ // We want to get the base address (ie, a pointer) to the IWebBrowser2 object embedded within the browser
+ // object, so we can call some of the functions in the former's table. For example, one IWebBrowser2 function
+ // we intend to call below will be Navigate2(). So we call the browser object's QueryInterface to get our
+ // pointer to the IWebBrowser2 object.
+ !browserObject->lpVtbl->QueryInterface(browserObject, &IID_IWebBrowser2, (void**)&webBrowser2))
+ {
+ // Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is
+ // webBrowser2->lpVtbl.
+
+ // Let's call several functions in the IWebBrowser2 object to position the browser display area
+ // in our window. The functions we call are put_Left(), put_Top(), put_Width(), and put_Height().
+ // Note that we reference the IWebBrowser2 object's VTable to get pointers to those functions. And
+ // also note that the first arg we pass to each is the pointer to the IWebBrowser2 object.
+ webBrowser2->lpVtbl->put_Left(webBrowser2, 0);
+ webBrowser2->lpVtbl->put_Top(webBrowser2, 0);
+ webBrowser2->lpVtbl->put_Width(webBrowser2, rect.right);
+ webBrowser2->lpVtbl->put_Height(webBrowser2, rect.bottom);
+
+ // We no longer need the IWebBrowser2 object (ie, we don't plan to call any more functions in it
+ // right now, so we can release our hold on it). Note that we'll still maintain our hold on the
+ // browser object until we're done with that object.
+ webBrowser2->lpVtbl->Release(webBrowser2);
+
+ // Success
+ return(0);
+ }
+ }
+
+ // Something went wrong setting up the browser!
+ UnEmbedBrowserObject(hwnd);
+ return(-4);
+ }
+
+ pClassFactory->lpVtbl->Release(pClassFactory);
+ GlobalFree(ptr);
+
+ // Can't create an instance of the browser!
+ return(-3);
+ }
+
+ GlobalFree(ptr);
+
+ // Can't get the web browser's IClassFactory!
+ return(-2);
+}
+
+
+
+
+
+/****************************** WindowProc() ***************************
+ * Our message handler for our window to host the browser.
+ */
+
+LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_SIZE:
+ {
+ // Resize the browser object to fit the window
+ ResizeBrowser(hwnd, LOWORD(lParam), HIWORD(lParam));
+ return(0);
+ }
+
+ case WM_CREATE:
+ {
+ // Embed the browser object into our host window. We need do this only
+ // once. Note that the browser object will start calling some of our
+ // IOleInPlaceFrame and IOleClientSite functions as soon as we start
+ // calling browser object functions in EmbedBrowserObject().
+ if (EmbedBrowserObject(hwnd)) return(-1);
+
+ // Success
+ return(0);
+ }
+
+ case WM_DESTROY:
+ {
+ int i, nCount;
+
+ // Detach the browser object from this window, and free resources.
+ UnEmbedBrowserObject(hwnd);
+
+ // If all the windows are now closed, quit this app
+ if (m_hWindows)
+ {
+ for (i=0, nCount=List_Count(m_hWindows); i<nCount; i++)
+ {
+ if (List_ElementAt (m_hWindows, i)==hwnd)
+ {
+ List_RemoveElementAt (m_hWindows, i);
+ break;
+ }
+ }
+ }
+
+ return(TRUE);
+ }
+
+
+ }
+
+ return(DefWindowProc(hwnd, uMsg, wParam, lParam));
+}
+
+// -----------------------------------------------------------------------------
+
+
+static DWORD WINAPI ShowIEWndFunc(PVOID pLoadWnd)
+{
+ MSG msg;
+ WNDCLASSEX wc={0};
+ HWND hWndCache = NULL;
+ static const TCHAR ClassName[] = "imo.im Voicechat wnd";
+
+ if (CoInitialize(NULL) != S_OK) return -1;
+
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.cbWndExtra = 2*sizeof(PVOID); // Extra to be used by caller, as we already make use of GWL_USERDATA
+ wc.hInstance = (HINSTANCE)GetModuleHandle(NULL);
+ wc.lpfnWndProc = WindowProc;
+ wc.lpszClassName = &ClassName[0];
+ RegisterClassEx(&wc);
+
+ m_hWindows = List_Init(0);
+
+ if (pLoadWnd)
+ {
+ // Create an invisible window with IE Control so that the appropriate libraries get loaded
+ // and a new window can be shown more quickly
+ hWndCache = CreateWindowEx(0, wc.lpszClassName, "dummy", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
+ HWND_DESKTOP, NULL, wc.hInstance, 0);
+ List_Push (m_hWindows, hWndCache);
+ DisplayHTMLStr(hWndCache, "");
+ }
+
+ while (GetMessage(&msg, 0, 0, 0) == 1)
+ {
+ switch (msg.message)
+ {
+ case WM_USER:
+ {
+ ShowIEWndParam *Param = (ShowIEWndParam *)msg.lParam;
+ if ((Param->hWnd = CreateWindowEx(0, wc.lpszClassName, Param->pszTitle, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, Param->width, Param->height,
+ HWND_DESKTOP, NULL, wc.hInstance, 0)))
+ {
+ List_Push (m_hWindows, Param->hWnd);
+ DisplayHTMLStr(Param->hWnd, Param->pszHTML);
+ ShowWindow(Param->hWnd, SW_SHOWNORMAL);
+ SetForegroundWindow (Param->hWnd);
+ UpdateWindow(Param->hWnd);
+ }
+ SetEvent (m_hEvent);
+ break;
+ }
+ case WM_USER+1:
+ {
+ DestroyWindow ((HWND)msg.lParam);
+ break;
+ }
+ }
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ UnregisterClass (wc.lpszClassName, wc.hInstance);
+ CoUninitialize();
+ if (m_hWindows) List_Exit (m_hWindows);
+ ExitThread (0);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+// bInitBrowser - Tries to initialize a dummy window on start so that subsequent
+// calls are faster as all libraries are already present in
+// memory. Drawback: Higher memory consumption
+int W32Browser_Init(BOOL bInitBrowser)
+{
+ if (m_hThread) W32Browser_Exit();
+ m_hThread = (HANDLE)_beginthreadex(NULL, 0, ShowIEWndFunc, (LPVOID)bInitBrowser, 0, &m_dwThread);
+ if (!m_hThread) return -1;
+ if (!(m_hEvent = CreateEvent (NULL, FALSE, FALSE, NULL)))
+ {
+ TerminateThread (m_hThread, -1);
+ CloseHandle (m_hThread);
+ return -1;
+ }
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+void W32Browser_Exit(void)
+{
+ if (m_hWindows)
+ {
+ HWND hWnd;
+
+ while (hWnd = List_Pop(m_hWindows))
+ W32Browser_CloseWindow (hWnd);
+ m_hWindows = NULL;
+ }
+ if (m_hThread)
+ {
+ PostThreadMessage (m_dwThread, WM_QUIT, 0, 0);
+ if (WaitForSingleObject (m_hThread, 2000) == WAIT_TIMEOUT)
+ TerminateThread (m_hThread, -1);
+ CloseHandle (m_hThread);
+ m_hThread = NULL;
+ }
+ if (m_hEvent)
+ {
+ CloseHandle (m_hEvent);
+ m_hEvent = NULL;
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+void *W32Browser_ShowHTMLStr(char *pszHTMLStr, int width, int height, char *pszTitle)
+{
+ // Window gets its own thread to not block the Mainthread
+ static ShowIEWndParam Param;
+
+ Param.width = width;
+ Param.height = height;
+ Param.pszHTML = pszHTMLStr;
+ Param.pszTitle = pszTitle;
+ Param.hWnd = 0;
+ PostThreadMessage (m_dwThread, WM_USER, 0, (LPARAM)&Param);
+ WaitForSingleObject (m_hEvent, INFINITE);
+ return (void*)Param.hWnd;
+}
+
+// -----------------------------------------------------------------------------
+
+void W32Browser_CloseWindow (void *pWnd)
+{
+ PostThreadMessage (m_dwThread, WM_USER+1, 0, (LPARAM)pWnd);
+}
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.h
new file mode 100644
index 0000000000..effc86998d
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32browser.h
@@ -0,0 +1,5 @@
+int W32Browser_Init(int bInitBrowser);
+void W32Browser_Exit(void);
+
+void *W32Browser_ShowHTMLStr(char *pszHTMLStr, int width, int height, char *pszTitle);
+void W32Browser_CloseWindow (void *pWnd);
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.c b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.c
new file mode 100644
index 0000000000..f9cc734cd1
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.c
@@ -0,0 +1,387 @@
+#include <stdio.h>
+#include "imo2sproxy.h"
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#define LockMutex(x) EnterCriticalSection (&x)
+#define UnlockMutex(x) LeaveCriticalSection(&x)
+#define InitMutex(x) InitializeCriticalSection(&x)
+#define ExitMutex(x) DeleteCriticalSection(&x)
+#define strcasecmp stricmp
+#define strncasecmp stricmpn
+#define mutex_t CRITICAL_SECTION
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include "memlist.h"
+#include "w32skypeemu.h"
+
+#ifndef _WIN64
+#if WINVER<0x0500
+#define SetWindowLongPtr SetWindowLong
+#define GetWindowLongPtr GetWindowLong
+#endif
+#ifndef LONG_PTR
+#define LONG_PTR LONG
+#endif
+#ifndef GWLP_USERDATA
+#define GWLP_USERDATA GWL_USERDATA
+#endif
+#endif
+
+// Skype API defines
+#define SKYPECONTROLAPI_ATTACH_SUCCESS 0
+#define SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION 1
+#define SKYPECONTROLAPI_ATTACH_REFUSED 2
+#define SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE 3
+#define SKYPECONTROLAPI_ATTACH_API_AVAILABLE 0x8001
+
+// -----------------------------------------------------------------------------
+
+typedef struct
+{
+ IMO2SPROXY vtbl; // Must be first!
+ IMO2SPROXY_CFG *pCfg;
+ W32SKYPEEMU_CFG *pMyCfg;
+ HWND hWndDispatch;
+ TYP_LIST *hClients;
+ mutex_t loopmutex;
+ DWORD dwThreadID;
+} IMO2SPROXY_INST;
+
+typedef struct
+{
+ HWND hWnd;
+ IMOSAPI *hInst;
+ IMO2SPROXY_INST *hProxy;
+ mutex_t sendmutex;
+ int iConnectionStat;
+} CONNINST;
+
+static UINT m_ControlAPIAttach = 0;
+static UINT m_ControlAPIDiscover = 0;
+
+// -----------------------------------------------------------------------------
+
+static void EventHandler(char *pszMsg, void *pUser);
+static CONNINST *FindClient(IMO2SPROXY_INST *hProxy, HWND hWnd);
+static void CleanConnections (TYP_LIST *hList);
+static void FreeConnection (CONNINST *pInst);
+static LONG APIENTRY WndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam);
+
+static int Imo2sproxy_Open(IMO2SPROXY *hInst);
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst);
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst);
+
+// -----------------------------------------------------------------------------
+static void EventHandler(char *pszMsg, void *pUser)
+{
+ CONNINST *pInst = (CONNINST*)pUser;
+ COPYDATASTRUCT cds;
+ DWORD dwRes = 0;
+
+ LockMutex(pInst->sendmutex);
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "%08X> %s\n", pInst->hWnd, pszMsg);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ cds.dwData = 0;
+ cds.cbData = strlen(pszMsg)+1;
+ cds.lpData = pszMsg;
+ SendMessageTimeout (pInst->hWnd, WM_COPYDATA, (WPARAM)pInst->hProxy->hWndDispatch, (LPARAM)&cds, SMTO_NORMAL, 1000, &dwRes);
+ UnlockMutex(pInst->sendmutex);
+}
+
+// -----------------------------------------------------------------------------
+
+static CONNINST *FindClient(IMO2SPROXY_INST *hProxy, HWND hWnd)
+{
+ int i, nCount;
+ CONNINST *pConn;
+
+ for (i=0, nCount=List_Count(hProxy->hClients); i<nCount; i++)
+ {
+ if ((pConn=(CONNINST*)List_ElementAt (hProxy->hClients, i))->hWnd == hWnd)
+ return pConn;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+static void CleanConnections (TYP_LIST *hList)
+{
+ unsigned int i;
+ CONNINST *pInst;
+
+ for (i=0; i<List_Count(hList); i++)
+ {
+ pInst = List_ElementAt (hList, i);
+ if (!IsWindow (pInst->hWnd))
+ {
+ if (pInst->hInst) FreeConnection(pInst);
+ free (List_RemoveElementAt(hList, i));
+ i--;
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static void FreeConnection (CONNINST *pInst)
+{
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "Closed connection %08X\n", pInst->hWnd);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ ExitMutex (pInst->sendmutex);
+ if (pInst->hInst)
+ {
+ IMOSAPI *hInst = pInst->hInst;
+ pInst->hInst = NULL;
+ Imo2S_Exit(hInst);
+ }
+}
+
+// -----------------------------------------------------------------------------
+
+static LONG APIENTRY WndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam)
+{
+ switch (message)
+ {
+ case WM_CREATE:
+ {
+ LPCREATESTRUCT lpCr = (LPCREATESTRUCT)lParam;
+
+ SetWindowLongPtr (hWnd, GWLP_USERDATA, (LONG_PTR)lpCr->lpCreateParams);
+ SetTimer (hWnd, 0, 60000, NULL);
+ break;
+ }
+ case WM_COPYDATA:
+ {
+ PCOPYDATASTRUCT pCopyData = (PCOPYDATASTRUCT)lParam;
+ CONNINST *pInst;
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+
+ if (pInst = FindClient (hProxy, (HWND)wParam))
+ {
+ if (pInst->hProxy->pMyCfg->bDelayLogin && pInst->iConnectionStat < 1)
+ {
+ char *pszError;
+
+ if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1)
+ {
+ pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n",
+ pInst->hWnd, hProxy->pCfg->pszUser, pszError);
+ FreeConnection(pInst);
+ free (List_Pop(hProxy->hClients));
+ PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
+ return 0;
+ }
+ }
+ LockMutex(pInst->sendmutex);
+ if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
+ {
+ fprintf (pInst->hProxy->pCfg->fpLog, "%08X< [%s]\n", pInst->hWnd, pCopyData->lpData);
+ fflush (pInst->hProxy->pCfg->fpLog);
+ }
+ Imo2S_Send (pInst->hInst, pCopyData->lpData);
+ UnlockMutex(pInst->sendmutex);
+ }
+ return 1;
+ }
+ case WM_TIMER:
+ // Housekeeping timer
+ CleanConnections (((IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA))->hClients);
+ break;
+ case WM_DESTROY:
+ KillTimer (hWnd, 0);
+ break;
+ default:
+ if (message == m_ControlAPIDiscover)
+ {
+ CONNINST *pInst;
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ char *pszError;
+
+ if (!(pInst = FindClient (hProxy, (HWND)wParam)))
+ {
+ pInst = (CONNINST*)calloc (1, sizeof(CONNINST));
+ if (!pInst) break;
+ List_Push(hProxy->hClients, pInst);
+ pInst->hProxy = hProxy;
+ pInst->hWnd = (HWND)wParam;
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "Imo2sproxy::SkypeControlAPIDiscover\n");
+
+ if (!(pInst->hInst = Imo2S_Init(EventHandler, pInst, hProxy->pCfg->iFlags)))
+ {
+ hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot start Imo2Skype instance.\n", pInst->hWnd);
+ free (List_Pop(hProxy->hClients));
+ PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
+ return 0;
+ }
+
+ // FIXME: We should enable logging dependent on a loglevel rather than just enabling it
+ if (hProxy->pCfg->bVerbose)
+ Imo2S_SetLog (pInst->hInst, hProxy->pCfg->fpLog);
+
+ InitMutex(pInst->sendmutex);
+
+ if (!pInst->hProxy->pMyCfg->bDelayLogin)
+ {
+ PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE);
+ if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1)
+ {
+ pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n",
+ pInst->hWnd, hProxy->pCfg->pszUser, pszError);
+ FreeConnection(pInst);
+ free (List_Pop(hProxy->hClients));
+ PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
+ return 0;
+ }
+ PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_API_AVAILABLE);
+ }
+ else
+ {
+ SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS);
+ }
+ return 0;
+ }
+ else
+ SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS);
+ return 0;
+ }
+ break;
+ }
+ return (DefWindowProc(hWnd, message, wParam, lParam));
+}
+
+
+
+// -----------------------------------------------------------------------------
+// PUBLIC
+// -----------------------------------------------------------------------------
+
+void W32SkypeEmu_Defaults (W32SKYPEEMU_CFG *pMyCfg)
+{
+ memset (pMyCfg, 0, sizeof(W32SKYPEEMU_CFG));
+ // Login on first command from Client, immediately send SKYPECONTROLAPI_ATTACH_SUCCESS
+ // This is necessary for some broken plugins, i.e. current SVN build of Miranda
+ // Skype plugin, which doesn't correctly poll again if SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE
+ // is sent.
+ pMyCfg->bDelayLogin = TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+IMO2SPROXY *W32SkypeEmu_Init (IMO2SPROXY_CFG *pCfg, W32SKYPEEMU_CFG *pMyCfg)
+{
+ IMO2SPROXY_INST *pstInst = calloc(sizeof(IMO2SPROXY_INST), 1);
+
+ pstInst->vtbl.Open = Imo2sproxy_Open;
+ pstInst->vtbl.Loop = Imo2sproxy_Loop;
+ pstInst->vtbl.Exit = Imo2sproxy_Exit;
+ pstInst->pCfg = pCfg;
+ pstInst->pMyCfg = pMyCfg;
+ InitMutex(pstInst->loopmutex);
+ return (IMO2SPROXY*)pstInst;
+}
+
+// -----------------------------------------------------------------------------
+// IMPLEMENTATION
+// -----------------------------------------------------------------------------
+static int Imo2sproxy_Open(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+ WNDCLASS WndClass ={0};
+
+ // Start Skype connection
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "W32SkypeEmu:Open(Start)\n");
+ if ((!m_ControlAPIAttach && !(m_ControlAPIAttach=RegisterWindowMessage("SkypeControlAPIAttach"))) ||
+ (!m_ControlAPIDiscover && !(m_ControlAPIDiscover=RegisterWindowMessage("SkypeControlAPIDiscover"))))
+ {
+ hProxy->pCfg->logerror (stderr, "Cannot register Window messages!");
+ return -1;
+ }
+
+ // Create window class
+ WndClass.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
+ WndClass.lpfnWndProc = (WNDPROC)WndProc;
+ WndClass.hInstance = GetModuleHandle(NULL);
+ WndClass.lpszClassName = "Imo2SProxyDispatchWindow";
+ RegisterClass(&WndClass);
+
+ if (!(hProxy->hWndDispatch=CreateWindowEx( WS_EX_APPWINDOW|WS_EX_WINDOWEDGE,
+ WndClass.lpszClassName, "", WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX,
+ CW_USEDEFAULT, CW_USEDEFAULT, 128, 128, NULL, 0, (HINSTANCE)WndClass.hInstance, (LPVOID)hProxy)))
+ {
+ hProxy->pCfg->logerror (stderr, "Unable to create dispatch window!");
+ UnregisterClass (WndClass.lpszClassName, WndClass.hInstance);
+ return -1;
+ }
+
+ hProxy->hClients = List_Init(32);
+ return 0;
+}
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Loop(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+ MSG Message;
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "W32SkypeEmu:Loop(Start)\n");
+
+ // Pump da messages
+ hProxy->dwThreadID = GetCurrentThreadId();
+ LockMutex(hProxy->loopmutex);
+ while (GetMessage(&Message, NULL, 0, 0))
+ {
+ TranslateMessage(&Message);
+ DispatchMessage(&Message);
+ }
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "W32SkypeEmu:Loop(End)\n");
+ UnlockMutex(hProxy->loopmutex);
+}
+
+
+// -----------------------------------------------------------------------------
+
+static void Imo2sproxy_Exit(IMO2SPROXY *hInst)
+{
+ IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
+ CONNINST *pInst;
+
+ if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
+ fprintf (hProxy->pCfg->fpLog, "W32SkypeEmu:Exit()\n");
+
+ if (hProxy->hWndDispatch) DestroyWindow (hProxy->hWndDispatch);
+ if (hProxy->dwThreadID) PostThreadMessage (hProxy->dwThreadID, WM_QUIT, 0, 0);
+ LockMutex(hProxy->loopmutex);
+
+ // Kill 'em all!
+ if (hProxy->hClients)
+ {
+ while (pInst=List_Pop(hProxy->hClients))
+ {
+ FreeConnection(pInst);
+ free (pInst);
+ }
+ List_Exit (hProxy->hClients);
+ }
+
+ UnregisterClass ("Imo2SProxyDispatchWindow", GetModuleHandle(NULL));
+
+ UnlockMutex(hProxy->loopmutex);
+ ExitMutex(hProxy->loopmutex);
+
+ free (hProxy);
+}
+
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.h b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.h
new file mode 100644
index 0000000000..a8291f3357
--- /dev/null
+++ b/plugins/!NotAdopted/IMO2sProxy/src/imo2skype/w32skypeemu.h
@@ -0,0 +1,6 @@
+typedef struct {
+ int bDelayLogin;
+} W32SKYPEEMU_CFG;
+
+void W32SkypeEmu_Defaults (W32SKYPEEMU_CFG *pMyCfg);
+IMO2SPROXY *W32SkypeEmu_Init (IMO2SPROXY_CFG *pCfg, W32SKYPEEMU_CFG *pMyCfg);