diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-08 12:14:56 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-08 12:14:56 +0000 |
commit | ac13aa1584ca595da727308406c87ec1bd9f5a21 (patch) | |
tree | 2cbda67ad0e66eec4614643c6b0a91f2584c4484 /plugins/FavContacts/src/http_api.cpp | |
parent | abebf2658d6cb4c879f0952b77a576733494c96f (diff) |
FavContacts:
- broken group functionality restored;
- metacontacts support (patch by bio);
- built-in http server wiped out;
- optimized memory usage;
- version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@9730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/FavContacts/src/http_api.cpp')
-rw-r--r-- | plugins/FavContacts/src/http_api.cpp | 161 |
1 files changed, 0 insertions, 161 deletions
diff --git a/plugins/FavContacts/src/http_api.cpp b/plugins/FavContacts/src/http_api.cpp deleted file mode 100644 index 38705d3927..0000000000 --- a/plugins/FavContacts/src/http_api.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "headers.h"
-
-#define MS_FAVCONTACTS_OPEN_CONTACT "FavContacts/OpenContact"
-
-class CHttpProcessor: public IConnectionProcessor
-{
-private:
- CSocket *m_socket;
-
- char *FetchURL(char *s)
- {
- char *p;
- if (p = strstr(s, "\r\n")) *p = 0;
- if (p = strrchr(s, ' ')) *p = 0;
- if (p = strchr(s, ' ')) while (*p && *p == ' ') p++;
- return mir_strdup(p);
- }
-
-public:
- CHttpProcessor(CSocket *s): m_socket(s) {}
-
- void ProcessConnection()
- {
- char buf[1024];
- int n = m_socket->Recv(buf, sizeof(buf));
- buf[n] = 0;
-
- char *s = FetchURL(buf);
-
- if (!strncmp(s, "/fav/list/", 10))
- {
- SendList();
- } else
- if (!strncmp(s, "/fav/open/", 10))
- {
- OpenContact(s);
- }
-
- mir_free(s);
- m_socket->Close();
- }
-
- void OpenContact(char *s)
- {
- m_socket->Send("HTTP 200 OK\r\n\r\n");
-
- int hContact;
- sscanf(s, "/fav/open/%d", &hContact);
- if (CallService(MS_DB_CONTACT_IS, hContact, 0))
- CallServiceSync(MS_FAVCONTACTS_OPEN_CONTACT, hContact, 0);
- }
-
- void SendList()
- {
- TFavContacts favList;
- favList.build();
-
- m_socket->Send(
- "HTTP 200 OK\r\n"
- "Content-Type: text/javascript\r\n"
- "\r\n");
-
- Send("try {\r\n");
- Send("SetContactCount(");
- Send(favList.getCount());
- Send(");\r\n");
-
- for (int i = 0; i < favList.getCount(); ++i)
- {
- MCONTACT hContact = favList[i]->getHandle();
- TCHAR *name = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR);
- AVATARCACHEENTRY *avatar = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, hContact, 0);
- int status = db_get_w(hContact, GetContactProto(hContact), "Status", ID_STATUS_OFFLINE);
-
- Send("SetContact(");
- Send(i);
- Send(", ");
- Send((int)hContact);
- Send(", '");
- SendQuoted(name);
- Send("', ");
- Send(status);
- Send(", '");
- SendQuoted(avatar ? avatar->szFilename : _T(""));
- Send("');\r\n");
- }
- Send("} catch(e) {}\r\n");
- }
-
- void Send(char *s)
- {
- m_socket->Send(s);
- }
-
-
- void Send(WCHAR *ws)
- {
- char *s = mir_utf8encodeW(ws);
- m_socket->Send(s);
- mir_free(s);
- }
-
-
- void Send(int i)
- {
- char buf[32];
- mir_snprintf(buf, SIZEOF(buf), "%d", i);
- Send(buf);
- }
-
- template<class XCHAR>
- void SendQuoted(const XCHAR *s)
- {
- int length = 0;
- const XCHAR *p;
- for (p = s; *p; p++)
- {
- if (*p == '\'' || *p == '\\' || *p == '\"')
- length++;
- length++;
- }
- XCHAR *buf = (XCHAR *)mir_alloc(sizeof(XCHAR) * (length + 1));
- XCHAR *q = buf;
- for (p = s; *p; p++)
- {
- if (*p == '\'' || *p == '\\' || *p == '\"')
- {
- *q = '\\';
- q++;
- }
- *q = *p;
- q++;
- }
- *q = 0;
- Send(buf);
- mir_free(buf);
- }
-};
-
-class CHttpProcessorFactory: public IConnectionProcessorFactory
-{
-public:
- IConnectionProcessor *Create(CSocket *s)
- {
- return new CHttpProcessor(s);
- }
-};
-
-static CHttpProcessorFactory g_httpProcessorFactory;
-static CServer g_httpServer;
-
-void LoadHttpApi()
-{
- g_httpServer.Start(60888, &g_httpProcessorFactory, true);
-}
-
-int UnloadHttpApi(WPARAM, LPARAM)
-{
- g_httpServer.Stop();
- return 0;
-}
|