~ubuntu-branches/ubuntu/utopic/gossip/utopic

« back to all changes in this revision

Viewing changes to protocols/jabber/gossip-jid.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-10-17 11:15:38 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20061017111538-8dhxm4g1uoesb0hm
Tags: 0.18-0ubuntu1
* New upstream release:
  - Fixed "Fix crash in src/gossip-galago.c due to missing presence states"
  - Fixed "Fix white space bugs"
  - Fixed "Redesign adding a contact to a GtkDialog instead of GnomeDruid"
  - Fixed "Fix wrong linking order"
  - Fixed "Does not compile on Ubuntu Dapper Drake" 
  - Fixed "Scroll to contact name in history window" 
  - Fixed "The accounts dialog should use widget sets for known protocols"
  - Fixed "Contact information window should appear on the same desktop"
  - Fixed "Remove protocol specific instances of gossip_account_[set,get]_*"
  - Fixed "Use g_base64_[decode/encode] instead of our version"
  - Fixed "Bad glist usage, use g_list_prepend instead"
  - Fixed "Use GtkLinkButton instead of GnomeHRef"
  - Fixed "Gossip fails to build with Galago enabled"
  - Fixed "Gossip fails to build due to some errors in peekaboo-galago.c"
  - Fixed "Implement gossip_account_has_param()"
  - Fixed "Empty resource results in invalid JID used to send messages"
  - Translations: Updated el, nl, sv, ne, fi.
* debian/control.in:
  - bumped glib Build-Dep, dropped galago Build-Dep.
  - drop galago references.
* debian/rules:
  - drop --enable-galago.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
jid_locate_resource (const gchar *str)
50
50
{
51
51
        gchar *ch;
52
 
        
 
52
 
53
53
        ch = strchr (str, '/');
54
54
        if (ch) {
55
55
                return (const gchar *) (ch + 1);
74
74
        tmp = g_utf8_casefold (str, at - str);
75
75
        ret = g_strconcat (tmp, at, NULL);
76
76
        g_free (tmp);
77
 
        
 
77
 
78
78
        return ret;
79
79
}
80
80
 
82
82
gossip_jid_new (const gchar *str_jid)
83
83
{
84
84
        GossipJID *jid;
85
 
        
 
85
 
86
86
        g_return_val_if_fail (str_jid != NULL, NULL);
87
87
 
88
88
        jid = g_new0 (GossipJID, 1);
99
99
        return jid;
100
100
}
101
101
 
102
 
void 
 
102
void
103
103
gossip_jid_set_without_resource (GossipJID *jid, const gchar *str)
104
104
{
105
105
        gchar *resource = NULL;
106
 
        
 
106
 
107
107
        g_return_if_fail (jid != NULL);
108
108
 
109
109
        if (jid->resource) {
140
140
gossip_jid_get_full (GossipJID *jid)
141
141
{
142
142
        g_return_val_if_fail (jid != NULL, "");
143
 
        
 
143
 
144
144
        return jid->full;
145
145
}
146
146
 
147
 
const gchar * 
 
147
const gchar *
148
148
gossip_jid_get_without_resource (GossipJID *jid)
149
149
{
150
150
        g_return_val_if_fail (jid != NULL, "");
168
168
        return NULL;
169
169
}
170
170
 
171
 
gboolean 
 
171
gboolean
172
172
gossip_jid_is_service (GossipJID *jid)
173
173
{
174
174
        gchar *ch;
200
200
                }
201
201
        }
202
202
 
203
 
        return g_strdup (""); 
 
203
        return g_strdup ("");
204
204
}
205
205
 
206
206
const gchar *
209
209
        const gchar *ch;
210
210
 
211
211
        g_return_val_if_fail (jid != NULL, "");
212
 
        
 
212
 
213
213
        for (ch = gossip_jid_get_without_resource (jid); *ch; ++ch) {
214
214
                if (*ch == '@') {
215
215
                        return ch + 1;
225
225
        g_return_val_if_fail (jid != NULL, NULL);
226
226
 
227
227
        jid->ref_count++;
228
 
        
 
228
 
229
229
        return jid;
230
230
}
231
 
        
 
231
 
232
232
void
233
233
gossip_jid_unref (GossipJID *jid)
234
234
{
241
241
}
242
242
 
243
243
gboolean
244
 
gossip_jid_equals (GossipJID *jid_a, 
 
244
gossip_jid_equals (GossipJID *jid_a,
245
245
                   GossipJID *jid_b)
246
246
{
247
247
        g_return_val_if_fail (jid_a != NULL, FALSE);
259
259
}
260
260
 
261
261
gboolean
262
 
gossip_jid_equals_without_resource (GossipJID *jid_a, 
 
262
gossip_jid_equals_without_resource (GossipJID *jid_a,
263
263
                                    GossipJID *jid_b)
264
264
{
265
265
        const gchar *a, *b;
266
 
        
 
266
 
267
267
        g_return_val_if_fail (jid_a != NULL, FALSE);
268
268
        g_return_val_if_fail (jid_b != NULL, FALSE);
269
269
 
270
270
        a = gossip_jid_get_without_resource (jid_a);
271
271
        b = gossip_jid_get_without_resource (jid_b);
272
 
        
 
272
 
273
273
        /* NOTE: This is not strictly correct, since the node and resource are
274
274
         * UTF8, and the domain have other rules. The node is also already
275
275
         * casefolded.
289
289
        const gchar *dot;
290
290
        const gchar *slash;
291
291
        gint         len;
292
 
        
 
292
 
293
293
        if (!str || strlen (str) < 1) {
294
294
                return FALSE;
295
295
        }
299
299
        /* check for the '@' sign and make sure it isn't at the start
300
300
           of the string or the last character */
301
301
        at = strchr (str, '@');
302
 
        if (!at || 
303
 
            at == str || 
 
302
        if (!at ||
 
303
            at == str ||
304
304
            at == str + len - 1) {
305
305
                return FALSE;
306
306
        }
308
308
        /* check for the '.' character and if it exists make sure it
309
309
           is not directly after the '@' sign or the last character. */
310
310
        dot = strchr (at, '.');
311
 
        if (dot == at + 1 || 
312
 
            dot == str + len - 1 || 
 
311
        if (dot == at + 1 ||
 
312
            dot == str + len - 1 ||
313
313
            dot == str + len - 2) {
314
314
                return FALSE;
315
315
        }
316
316
 
317
317
        /* check the '/' character exists (if we are checking with
318
318
           resource) and make sure it is not after the '@' sign or the
319
 
           last character */ 
 
319
           last character */
320
320
        slash = strchr (at, '/');
321
 
        if (with_resource && 
 
321
        if (with_resource &&
322
322
            (slash == NULL ||
323
323
             slash == at + 1 ||
324
324
             slash == str + len - 1)) {
325
325
                return FALSE;
326
 
        } 
 
326
        }
327
327
 
328
328
        /* if slash exists and we are expecting a JID without the
329
329
           resource then we return FALSE */
347
347
                }
348
348
        }
349
349
 
350
 
        return g_strdup (""); 
 
350
        return g_strdup ("");
351
351
}
352
352
 
353
353
gchar *
354
 
gossip_jid_string_get_part_host (const gchar *str) 
 
354
gossip_jid_string_get_part_host (const gchar *str)
355
355
{
356
356
        const gchar *r_loc;
357
357
        const gchar *ch;
365
365
 
366
366
                        if (r_loc) {
367
367
                                return g_strndup (ch, r_loc - 1 - ch);
368
 
                        } 
 
368
                        }
369
369
 
370
370
                        return g_strdup (ch);
371
371
                }
372
372
        }
373
373
 
374
 
        return g_strdup (""); 
 
374
        return g_strdup ("");
375
375
}
376
376
 
377
377
const gchar *
378
378
gossip_jid_string_get_part_resource (const gchar *str)
379
379
{
380
380
        gchar *ch;
381
 
        
 
381
 
382
382
        ch = strchr (str, '/');
383
383
        if (ch) {
384
384
                return (const gchar *) (ch + 1);
388
388
}
389
389
 
390
390
gint
391
 
gossip_jid_case_compare (gconstpointer a, 
 
391
gossip_jid_case_compare (gconstpointer a,
392
392
                         gconstpointer b)
393
393
{
394
394
        const gchar *str_a, *str_b;
395
395
 
396
396
        str_a = gossip_jid_get_without_resource ((GossipJID *) a);
397
397
        str_b = gossip_jid_get_without_resource ((GossipJID *) b);
398
 
        
 
398
 
399
399
        return gossip_strncasecmp (str_a, str_b, -1);
400
400
}
401
401
 
402
402
gboolean
403
 
gossip_jid_equal (gconstpointer v1, 
 
403
gossip_jid_equal (gconstpointer v1,
404
404
                  gconstpointer v2)
405
405
{
406
406
        const gchar *a, *b;