adium: fix some #import paths
[siplcs.git] / src / miranda / miranda-utils.c
blob8f4eff100e47c62ff573745abcad2a94f066efb4
1 /**
2 * @file miranda-utils.c
4 * pidgin-sipe
6 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <windows.h>
25 #include "miranda-version.h"
26 #include "newpluginapi.h"
27 #include "m_protosvc.h"
28 #include "m_protoint.h"
29 #include "m_database.h"
30 #include "m_netlib.h"
31 #include "m_langpack.h"
32 #include "m_protomod.h"
34 #include "glib.h"
35 #include "sipe-backend.h"
36 #include "sipe-core.h"
37 #include "miranda-private.h"
40 * Table to hold HTML entities we want to convert
42 static GHashTable *entities = NULL;
45 /**
46 * Various shortcut functions to get database values
48 gchar*
49 sipe_miranda_getGlobalString(const gchar* name)
51 return DBGetString( NULL, SIPSIMPLE_PROTOCOL_NAME, name );
54 gchar*
55 sipe_miranda_getContactString(const SIPPROTO *pr, HANDLE hContact, const gchar* name)
57 return DBGetString( hContact, pr->proto.m_szModuleName, name );
60 gchar*
61 sipe_miranda_getString(const SIPPROTO *pr, const gchar* name)
63 return sipe_miranda_getContactString( pr, NULL, name );
66 DWORD
67 sipe_miranda_getDword(const SIPPROTO *pr, HANDLE hContact, const gchar* name, DWORD* rv)
69 DBVARIANT dbv;
70 DBCONTACTGETSETTING cgs;
72 cgs.szModule = pr->proto.m_szModuleName;
73 cgs.szSetting = name;
74 cgs.pValue=&dbv;
75 if(CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)hContact,(LPARAM)&cgs))
76 return 0;
78 if (rv) {
79 *rv = dbv.dVal;
80 return 1;
81 } else {
82 return dbv.dVal;
87 WORD
88 sipe_miranda_getGlobalWord(const gchar* name, WORD* rv)
90 DBVARIANT dbv;
91 DBCONTACTGETSETTING cgs;
93 cgs.szModule = SIPSIMPLE_PROTOCOL_NAME;
94 cgs.szSetting = name;
95 cgs.pValue=&dbv;
96 if(CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)NULL,(LPARAM)&cgs))
97 return 0;
99 if (rv) {
100 *rv = dbv.wVal;
101 return 1;
102 } else {
103 return dbv.wVal;
108 WORD
109 sipe_miranda_getWord(const SIPPROTO *pr, HANDLE hContact, const gchar* name, WORD* rv)
111 DBVARIANT dbv;
112 DBCONTACTGETSETTING cgs;
114 cgs.szModule = pr->proto.m_szModuleName;
115 cgs.szSetting = name;
116 cgs.pValue=&dbv;
117 if(CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)hContact,(LPARAM)&cgs))
118 return 0;
120 if (rv) {
121 *rv = dbv.wVal;
122 return 1;
123 } else {
124 return dbv.wVal;
129 gboolean
130 sipe_miranda_getBool(const SIPPROTO *pr, const gchar *name, gboolean defval)
132 WORD ret;
134 if (sipe_miranda_getWord( pr, NULL, name, &ret ))
135 return ret?TRUE:FALSE;
137 return defval;
141 sipe_miranda_getStaticString(const SIPPROTO *pr, HANDLE hContact, const gchar* valueName, gchar* dest, unsigned dest_len)
143 DBVARIANT dbv;
144 DBCONTACTGETSETTING sVal;
146 dbv.pszVal = dest;
147 dbv.cchVal = (WORD)dest_len;
148 dbv.type = DBVT_ASCIIZ;
150 sVal.pValue = &dbv;
151 sVal.szModule = pr->proto.m_szModuleName;
152 sVal.szSetting = valueName;
153 if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal) != 0)
154 return 1;
156 return (dbv.type != DBVT_ASCIIZ);
160 * Various shortcut functions to set database values
162 void
163 sipe_miranda_setGlobalString(const gchar* name, const gchar* value)
165 DBWriteContactSettingString(NULL, SIPSIMPLE_PROTOCOL_NAME, name, value);
168 void
169 sipe_miranda_setGlobalStringUtf(const gchar* valueName, const gchar* parValue )
171 DBWriteContactSettingStringUtf( NULL, SIPSIMPLE_PROTOCOL_NAME, valueName, parValue );
174 void
175 sipe_miranda_setContactString(const SIPPROTO *pr, HANDLE hContact, const gchar* name, const gchar* value)
177 DBWriteContactSettingString(hContact, pr->proto.m_szModuleName, name, value);
180 void
181 sipe_miranda_setContactStringUtf(const SIPPROTO *pr, HANDLE hContact, const gchar* valueName, const gchar* parValue )
183 DBWriteContactSettingStringUtf( hContact, pr->proto.m_szModuleName, valueName, parValue );
186 void
187 sipe_miranda_setString(const SIPPROTO *pr, const gchar* name, const gchar* value)
189 sipe_miranda_setContactString( pr, NULL, name, value );
192 void
193 sipe_miranda_setStringUtf(const SIPPROTO *pr, const gchar* name, const gchar* value)
195 sipe_miranda_setContactStringUtf( pr, NULL, name, value );
199 sipe_miranda_setGlobalWord(const gchar* szSetting, WORD wValue)
201 return DBWriteContactSettingWord(NULL, SIPSIMPLE_PROTOCOL_NAME, szSetting, wValue);
205 sipe_miranda_setWord(const SIPPROTO *pr, HANDLE hContact, const gchar* szSetting, WORD wValue)
207 return DBWriteContactSettingWord(hContact, pr->proto.m_szModuleName, szSetting, wValue);
211 sipe_miranda_setBool(const SIPPROTO *pr, const gchar *name, gboolean value)
213 return DBWriteContactSettingWord(NULL, pr->proto.m_szModuleName, name, value?1:0);
217 * Initialize our table of HTML entities
219 #define ADDENT(a,b) g_hash_table_insert(entities, a, b)
220 static void
221 initEntities(void)
223 entities = g_hash_table_new(g_str_hash, g_str_equal);
225 ADDENT("nbsp"," ");
226 ADDENT("quot","\"");
227 ADDENT("lt","<");
228 ADDENT("gt",">");
229 ADDENT("apos","'");
233 * WARNING: Returns miranda-allocated string, not glib one
235 gchar*
236 sipe_miranda_eliminate_html(const gchar *string, int len)
238 gchar *tmp = (char*)mir_alloc(len + 1);
239 int i,j;
240 BOOL tag = FALSE;
241 gchar *res;
243 if (!entities)
244 initEntities();
246 for (i=0,j=0;i<len;i++)
248 if (!tag && string[i] == '<')
250 if ((i + 4 <= len) && (!_strnicmp(string + i, "<br>", 4) || !_strnicmp(string + i, "<br/>", 5)))
251 { // insert newline
252 tmp[j] = '\r';
253 j++;
254 tmp[j] = '\n';
255 j++;
257 tag = TRUE;
259 else if (tag && string[i] == '>')
261 tag = FALSE;
263 else if (!tag)
265 char *tkend;
267 if ((string[i] == '&') && (tkend = strstr((char*)&string[i], ";")))
269 gchar *rep;
270 gchar c = *tkend;
271 *tkend = '\0';
273 rep = (char*)g_hash_table_lookup(entities, &string[i+1]);
275 if (rep)
277 strcpy(&tmp[j], rep);
278 j += strlen(rep);
279 i += strlen(&string[i]);
280 *tkend = c;
282 else
284 *tkend = c;
285 tmp[j] = string[i];
286 j++;
290 else
292 tmp[j] = string[i];
293 j++;
296 tmp[j] = '\0';
298 res = tmp;
300 return res;
303 unsigned short
304 sipe_miranda_network_get_port_from_fd( HANDLE fd )
306 SOCKET sock = CallService(MS_NETLIB_GETSOCKET, (WPARAM)fd, (LPARAM)0);
308 struct sockaddr_in sockbuf;
309 int namelen = sizeof(sockbuf);
310 getsockname(sock, (struct sockaddr *)&sockbuf, &namelen);
311 SIPE_DEBUG_INFO("<%x> <%x><%x><%s>", namelen, sockbuf.sin_family, sockbuf.sin_port, inet_ntoa(sockbuf.sin_addr) );
313 return sockbuf.sin_port;
316 /* Misc functions */
317 TCHAR _tcharbuf[32768];
318 TCHAR* CHAR2TCHAR( const char *chr ) {
319 #ifdef UNICODE
320 if (!chr) return NULL;
321 mbstowcs( _tcharbuf, chr, strlen(chr)+1 );
322 return _tcharbuf;
323 #else
324 return chr;
325 #endif
328 char _charbuf[32768];
329 char* TCHAR2CHAR( const TCHAR *tchr ) {
330 #ifdef UNICODE
331 if (!tchr) return NULL;
332 wcstombs( _charbuf, tchr, wcslen(tchr)+1 );
333 return _charbuf;
334 #else
335 return tchr;
336 #endif
339 HANDLE
340 sipe_miranda_AddEvent(const SIPPROTO *pr, HANDLE hContact, WORD wType, DWORD dwTime, DWORD flags, DWORD cbBlob, PBYTE pBlob)
342 DBEVENTINFO dbei = {0};
344 dbei.cbSize = sizeof(dbei);
345 dbei.szModule = pr->proto.m_szModuleName;
346 dbei.timestamp = dwTime;
347 dbei.flags = flags;
348 dbei.eventType = wType;
349 dbei.cbBlob = cbBlob;
350 dbei.pBlob = pBlob;
352 return (HANDLE)CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei);
355 struct msgboxinfo {
356 TCHAR *msg;
357 TCHAR *caption;
360 static unsigned __stdcall
361 msgboxThread(void* arg)
363 struct msgboxinfo *err = (struct msgboxinfo*)arg;
364 if (!err)
365 return 0;
367 MessageBox(NULL, err->msg, err->caption, MB_OK);
368 mir_free(err->msg);
369 mir_free(err->caption);
370 g_free(err);
371 return 0;
374 void
375 sipe_miranda_msgbox(const char *msg, const char *caption)
377 struct msgboxinfo *info = g_new(struct msgboxinfo,1);
379 info->msg = mir_a2t(msg);
380 info->caption = mir_a2t(caption);
382 CloseHandle((HANDLE) mir_forkthreadex( msgboxThread, info, 8192, NULL ));
385 char* sipe_miranda_acktype_strings[] = {
386 "ACKTYPE_MESSAGE", "ACKTYPE_URL", "ACKTYPE_FILE",
387 "ACKTYPE_CHAT", "ACKTYPE_AWAYMSG", "ACKTYPE_AUTHREQ",
388 "ACKTYPE_ADDED", "ACKTYPE_GETINFO", "ACKTYPE_SETINFO",
389 "ACKTYPE_LOGIN", "ACKTYPE_SEARCH", "ACKTYPE_NEWUSER",
390 "ACKTYPE_STATUS", "ACKTYPE_CONTACTS", "ACKTYPE_AVATAR",
391 "ACKTYPE_EMAIL" };
393 char* sipe_miranda_ackresult_strings[] = {
394 "ACKRESULT_SUCCESS", "ACKRESULT_FAILED", "ACKRESULT_CONNECTING",
395 "ACKRESULT_CONNECTED", "ACKRESULT_INITIALISING", "ACKRESULT_SENTREQUEST",
396 "ACKRESULT_DATA", "ACKRESULT_NEXTFILE", "ACKRESULT_FILERESUME",
397 "ACKRESULT_DENIED", "ACKRESULT_STATUS", "ACKRESULT_LISTENING",
398 "ACKRESULT_CONNECTPROXY", "ACKRESULT_SEARCHRESULT" };
401 sipe_miranda_SendBroadcast(SIPPROTO *pr, HANDLE hContact,int type,int result,HANDLE hProcess,LPARAM lParam)
403 ACKDATA ack = {0};
405 ack.cbSize = sizeof(ACKDATA);
406 ack.szModule = pr->proto.m_szModuleName;
407 ack.hContact = hContact;
408 ack.type = type;
409 ack.result = result;
410 ack.hProcess = hProcess;
411 ack.lParam = lParam;
413 SIPE_DEBUG_INFO("broadcasting contact <%08x> type <%d:%s> result <%d:%s> par1 <%08x> par2 <%08x>",
414 hContact,
415 type, sipe_miranda_acktype_strings[type],
416 result, sipe_miranda_ackresult_strings[result>99 ? result-98 : result],
417 hProcess, lParam);
419 return CallServiceSync(MS_PROTO_BROADCASTACK,0,(LPARAM)&ack);
422 struct sipe_miranda_connection_info {
423 SIPPROTO *pr;
424 gchar *server_name;
425 int server_port;
426 int timeout;
427 gboolean tls;
428 void (*callback)(HANDLE fd, void *data, const gchar *reason);
429 void *data;
431 /* Private. For locking only */
432 HANDLE hDoneEvent;
433 HANDLE fd;
434 const gchar *reason;
437 static void __stdcall
438 connection_cb_async(void *data)
440 struct sipe_miranda_connection_info *entry = (struct sipe_miranda_connection_info*)data;
441 SIPE_DEBUG_INFO("[C:%08x] Calling real connected function", entry);
442 entry->callback(entry->fd, entry->data, entry->reason);
443 SetEvent(entry->hDoneEvent);
446 static unsigned __stdcall
447 sipe_miranda_connected_callback(void* data)
449 struct sipe_miranda_connection_info *info = (struct sipe_miranda_connection_info*)data;
450 SIPPROTO *pr = info->pr;
451 NETLIBOPENCONNECTION ncon = {0};
453 ncon.cbSize = sizeof(ncon);
454 ncon.flags = NLOCF_V2;
455 ncon.szHost = info->server_name;
456 ncon.wPort = info->server_port;
457 ncon.timeout = info->timeout;
459 info->fd = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)pr->m_hServerNetlibUser, (LPARAM)&ncon);
460 if (info->fd == NULL) {
461 SIPE_DEBUG_INFO("[C:%08x] Connection to <%s:%d> failed", info, info->server_name, info->server_port);
462 info->reason = "Connection failed";
464 } else {
465 SIPE_DEBUG_INFO("[C:%08x] connected <%d>", info, (int)info->fd);
467 if (info->tls)
469 if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)info->fd, 0))
471 Netlib_CloseHandle(info->fd);
472 info->fd = NULL;
473 info->reason = "Failed to enabled SSL";
474 } else {
475 SIPE_DEBUG_INFO("[C:%08x] SSL enabled", info);
477 } else {
478 info->reason = NULL;
482 info->hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
483 CallFunctionAsync(connection_cb_async, info);
484 WaitForSingleObject(info->hDoneEvent, INFINITE);
485 CloseHandle(info->hDoneEvent);
487 g_free(info->server_name);
488 g_free(info);
489 return 0;
492 struct sipe_miranda_connection_info *
493 sipe_miranda_connect(SIPPROTO *pr,
494 const gchar *host,
495 int port,
496 gboolean tls,
497 int timeout,
498 void (*callback)(HANDLE fd, void *data, const gchar *reason),
499 void *data)
501 struct sipe_miranda_connection_info *info = g_new0(struct sipe_miranda_connection_info, 1);
502 SIPE_DEBUG_INFO("[C:%08x] Connecting to <%s:%d> tls <%d> timeout <%d>", info, host, port, tls, timeout);
504 info->pr = pr;
505 info->server_name = g_strdup(host);
506 info->server_port = port;
507 info->timeout = timeout;
508 info->tls = tls;
509 info->callback = callback;
510 info->data = data;
512 CloseHandle((HANDLE) mir_forkthreadex( sipe_miranda_connected_callback, info, 65536, NULL ));
514 return info;
517 struct sipe_miranda_ack_args
519 HANDLE hContact;
520 int nAckType;
521 int nAckResult;
522 HANDLE hSequence;
523 gchar *pszMessage;
524 const gchar *modname;
527 static unsigned __stdcall
528 ProtocolAckThread(struct sipe_miranda_ack_args* args)
530 ProtoBroadcastAck(args->modname, args->hContact, args->nAckType, args->nAckResult, args->hSequence, (LPARAM)args->pszMessage);
532 if (args->nAckResult == ACKRESULT_SUCCESS)
533 SIPE_DEBUG_INFO_NOFORMAT("ProtocolAckThread: Sent ACK");
534 else if (args->nAckResult == ACKRESULT_FAILED)
535 SIPE_DEBUG_INFO_NOFORMAT("ProtocolAckThread: Sent NACK");
537 g_free(args->pszMessage);
538 g_free(args);
539 return 0;
542 void
543 sipe_miranda_SendProtoAck( SIPPROTO *pr, HANDLE hContact, DWORD dwCookie, int nAckResult, int nAckType, const char* pszMessage)
545 struct sipe_miranda_ack_args* pArgs = g_new0(struct sipe_miranda_ack_args, 1);
547 pArgs->hContact = hContact;
548 pArgs->hSequence = (HANDLE)dwCookie;
549 pArgs->nAckResult = nAckResult;
550 pArgs->nAckType = nAckType;
551 pArgs->pszMessage = g_strdup(pszMessage);
552 pArgs->modname = pr->proto.m_szModuleName;
554 CloseHandle((HANDLE) mir_forkthreadex(ProtocolAckThread, pArgs, 65536, NULL));
557 gboolean
558 sipe_miranda_cmd(gchar *cmd, gchar *buf, DWORD *maxlen)
560 STARTUPINFOA si = {0};
561 PROCESS_INFORMATION pi = {0};
562 SECURITY_ATTRIBUTES sa = {0};
563 HANDLE rd,wr;
565 sa.nLength = sizeof(sa);
566 sa.bInheritHandle = TRUE;
568 if (!CreatePipe(&rd, &wr, &sa, 0))
570 SIPE_DEBUG_INFO_NOFORMAT("Could not create pipe");
571 return FALSE;
574 SetHandleInformation(rd, HANDLE_FLAG_INHERIT, 0);
576 si.cb = sizeof(si);
577 si.dwFlags = STARTF_USESTDHANDLES;
578 si.hStdOutput = wr;
579 si.hStdError = wr;
580 si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
582 if (!CreateProcessA(NULL, cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
584 SIPE_DEBUG_INFO("Could not run child program <%s> (%d)", cmd, GetLastError());
585 return FALSE;
588 CloseHandle(pi.hThread);
589 CloseHandle(pi.hProcess);
591 if (!ReadFile(rd, buf, *maxlen, maxlen, NULL))
593 SIPE_DEBUG_INFO("Could not read from child program <%s>", cmd);
594 return FALSE;
597 return TRUE;
600 gchar*
601 sipe_miranda_html2rtf(const gchar *text)
603 const gchar *intro = "{\\rtf1\\ansi";
604 const gchar *link1 = "{\\field{\\*\\fldinst{HYPERLINK \"";
605 const gchar *link2 = "}}{\\fldrslt {\\ul\\cf2 ";
606 gchar *tmp = g_malloc(strlen(text)+1);
607 int maxlen = strlen(text);
608 const gchar *i = text;
609 int j = 0;
610 gboolean skiptag = FALSE;
611 gboolean escape = FALSE;
612 gboolean copystring = FALSE;
613 gboolean link_stage2 = FALSE;
615 strncpy(tmp+j, intro, maxlen-j);
616 j += strlen(intro);
618 while (*i)
620 if (j+100>=maxlen) /* 100 is max substitution size */
622 maxlen += 128;
623 tmp = g_realloc(tmp, maxlen);
625 if (skiptag && !escape && *i != '>') {
626 i++;
627 } else if (skiptag && !escape) {
628 i++;
629 skiptag = FALSE;
630 } else if (copystring) {
631 if (!escape && *i == '"') copystring = FALSE;
632 if (escape) escape = FALSE;
633 else if (*i == '\\') escape = TRUE;
634 *(tmp+j) = *i;
635 j++;
636 i++;
637 } else if (link_stage2) {
638 strcpy(tmp+j, link2);
639 j += strlen(link2);
640 link_stage2 = FALSE;
641 skiptag = TRUE;
642 } else if (g_str_has_prefix(i,"<br/>")) {
643 strcpy(tmp+j, "\\par\n");
644 j += 5;
645 i += 5;
646 } else if (g_str_has_prefix(i,"<b>")) {
647 strcpy(tmp+j, "\\b");
648 j += 2;
649 i += 3;
650 } else if (g_str_has_prefix(i,"</b>")) {
651 strcpy(tmp+j, "\\b0");
652 j += 3;
653 i += 4;
654 } else if (g_str_has_prefix(i,"<font size=\"")) {
655 strcpy(tmp+j, "\\fs36");
656 j += 5;
657 i += 12;
658 skiptag = TRUE;
659 } else if (g_str_has_prefix(i,"</font>")) {
660 strcpy(tmp+j, "\\fs20");
661 j += 5;
662 i += 7;
663 } else if (g_str_has_prefix(i,"<a href=\"")) {
664 strcpy(tmp+j, link1);
665 j += strlen(link1);
666 link_stage2 = TRUE;
667 copystring = TRUE;
668 i += 9;
669 } else if (g_str_has_prefix(i,"</a>")) {
670 strcpy(tmp+j, "}}}\\cf0 ");
671 j += 7;
672 i += 4;
673 } else if (*i == '<') {
674 skiptag = TRUE;
675 } else {
676 if (escape) {
677 escape = FALSE;
678 } else if (*i == '\\') {
679 escape = TRUE;
681 if (!skiptag)
683 *(tmp+j) = *i;
684 j++;
686 i++;
689 *(tmp+j++) = '}';
690 *(tmp+j++) = '\0';
691 tmp = g_realloc(tmp, j);
692 return tmp;
695 int SipeStatusToMiranda(guint activity) {
697 switch (activity)
699 case SIPE_ACTIVITY_OFFLINE:
700 return ID_STATUS_OFFLINE;
701 case SIPE_ACTIVITY_AVAILABLE:
702 return ID_STATUS_ONLINE;
703 case SIPE_ACTIVITY_ON_PHONE:
704 return ID_STATUS_ONTHEPHONE;
705 case SIPE_ACTIVITY_DND:
706 case SIPE_ACTIVITY_URGENT_ONLY:
707 return ID_STATUS_DND;
708 case SIPE_ACTIVITY_AWAY:
709 case SIPE_ACTIVITY_OOF:
710 return ID_STATUS_NA;
711 case SIPE_ACTIVITY_LUNCH:
712 return ID_STATUS_OUTTOLUNCH;
713 case SIPE_ACTIVITY_BUSY:
714 case SIPE_ACTIVITY_IN_MEETING:
715 case SIPE_ACTIVITY_IN_CONF:
716 return ID_STATUS_OCCUPIED;
717 case SIPE_ACTIVITY_INVISIBLE:
718 return ID_STATUS_INVISIBLE;
719 case SIPE_ACTIVITY_BRB:
720 return ID_STATUS_AWAY;
721 case SIPE_ACTIVITY_UNSET:
722 return ID_STATUS_OFFLINE;
723 case SIPE_ACTIVITY_INACTIVE:
724 case SIPE_ACTIVITY_ONLINE:
725 case SIPE_ACTIVITY_BUSYIDLE:
726 return ID_STATUS_ONLINE;
727 default:
728 /* None of those? We'll have to guess. Online seems ok. */
729 return ID_STATUS_ONLINE;
732 /* Don't have SIPE equivalent of these:
733 - ID_STATUS_FREECHAT
738 guint MirandaStatusToSipe(int status) {
740 switch (status)
742 case ID_STATUS_OFFLINE:
743 return SIPE_ACTIVITY_OFFLINE;
745 case ID_STATUS_ONLINE:
746 case ID_STATUS_FREECHAT:
747 return SIPE_ACTIVITY_AVAILABLE;
749 case ID_STATUS_ONTHEPHONE:
750 return SIPE_ACTIVITY_ON_PHONE;
752 case ID_STATUS_DND:
753 return SIPE_ACTIVITY_DND;
755 case ID_STATUS_NA:
756 return SIPE_ACTIVITY_AWAY;
758 case ID_STATUS_AWAY:
759 return SIPE_ACTIVITY_BRB;
761 case ID_STATUS_OUTTOLUNCH:
762 return SIPE_ACTIVITY_LUNCH;
764 case ID_STATUS_OCCUPIED:
765 return SIPE_ACTIVITY_BUSY;
767 case ID_STATUS_INVISIBLE:
768 return SIPE_ACTIVITY_INVISIBLE;
770 default:
771 return SIPE_ACTIVITY_UNSET;
776 gchar *sipe_miranda_uri_self(SIPPROTO *pr) {
777 gchar *username = sipe_miranda_getString(pr, "username");
778 gchar *uri = g_strdup_printf("sip:%s", username);
779 mir_free(username);
780 return uri;
784 Local Variables:
785 mode: c
786 c-file-style: "bsd"
787 indent-tabs-mode: t
788 tab-width: 8
789 End: