public
Description: MSN Messenger library in C
Homepage: http://code.google.com/p/msn-pecan/
Clone URL: git://github.com/felipec/msn-pecan.git
ceyusa (author)
Sun Sep 14 14:48:47 -0700 2008
felipec (committer)
Sun Sep 14 14:48:47 -0700 2008
msn-pecan / fix_purple.c
100644 218 lines (180 sloc) 4.82 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Copyright (C) 2007-2008 Felipe Contreras
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
 
#include "msn.h"
#include "fix_purple.h"
 
#include <string.h> /* for strcmp. */
 
/* libpurple stuff. */
#include "fix_purple_win32.h"
#include <connection.h>
 
#if !GLIB_CHECK_VERSION(2,16,0)
int
g_strcmp0 (const char *str1,
           const char *str2)
{
    if (!str1)
        return -(str1 != str2);
    if (!str2)
        return str1 != str2;
    return strcmp (str1, str2);
}
#endif /* !GLIB_CHECK_VERSION(2,16,0) */
 
/*
* Copyright 2004 Tor Lillqvist
*
* This code is licenced under LGPLv2+
*/
#if !GLIB_CHECK_VERSION(2,6,0)
 
#define G_STDIO_NO_WRAP_ON_UNIX
 
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
 
#ifdef G_OS_WIN32
#include <windows.h>
#include <errno.h>
#include <wchar.h>
#include <direct.h>
#include <io.h>
#endif
 
#include <glib/gstdio.h>
 
int
g_open (const gchar *filename,
        int flags,
        int mode)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;
 
    if (wfilename == NULL)
    {
        errno = EINVAL;
        return -1;
    }
 
    retval = _wopen (wfilename, flags, mode);
    save_errno = errno;
 
    g_free (wfilename);
 
    errno = save_errno;
    return retval;
#else
    return open (filename, flags, mode);
#endif
}
 
int
g_stat (const gchar *filename,
        struct stat *buf)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;
    int len;
 
    if (wfilename == NULL)
    {
        errno = EINVAL;
        return -1;
    }
 
    len = wcslen (wfilename);
    while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
        len--;
    if (len > 0 &&
        (!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename))
        wfilename[len] = '\0';
 
    retval = _wstat (wfilename, (struct _stat *) buf);
    save_errno = errno;
 
    g_free (wfilename);
 
    errno = save_errno;
    return retval;
#else
    return stat (filename, buf);
#endif
}
 
FILE *
g_fopen (const gchar *filename,
         const gchar *mode)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    wchar_t *wmode;
    FILE *retval;
    int save_errno;
 
    if (wfilename == NULL)
    {
        errno = EINVAL;
        return NULL;
    }
 
    wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
 
    if (wmode == NULL)
    {
        g_free (wfilename);
        errno = EINVAL;
        return NULL;
    }
 
    retval = _wfopen (wfilename, wmode);
    save_errno = errno;
 
    g_free (wfilename);
    g_free (wmode);
 
    errno = save_errno;
    return retval;
#else
    return fopen (filename, mode);
#endif
}
 
#endif /* !GLIB_CHECK_VERSION(2,6,0) */
 
void
purple_buddy_set_displayname (PurpleConnection *gc,
                              const gchar *who,
                              const gchar *value)
{
    PurpleAccount *account = purple_connection_get_account (gc);
    GSList *buddies = purple_find_buddies (account, who);
    PurpleBuddy *b;
 
    while (buddies != NULL)
    {
        b = buddies->data;
        buddies = g_slist_delete_link (buddies, buddies);
 
        if ((b->alias == NULL && value == NULL) ||
            (b->alias && value && !strcmp (b->alias, value)))
        {
            continue;
        }
 
        purple_blist_alias_buddy (b, value);
    }
}
 
void
purple_buddy_set_nickname (PurpleConnection *gc,
                           const gchar *who,
                           const gchar *value)
{
    PurpleAccount *account = purple_connection_get_account (gc);
    GSList *buddies = purple_find_buddies (account, who);
    PurpleBuddy *b;
 
    while (buddies != NULL)
    {
        b = buddies->data;
        buddies = g_slist_delete_link (buddies, buddies);
 
        if ((b->server_alias == NULL && value == NULL) ||
            (b->server_alias && value && !strcmp (b->server_alias, value)))
        {
            continue;
        }
 
        purple_blist_server_alias_buddy (b, value);
    }
}