~ci-train-bot/url-dispatcher/url-dispatcher-ubuntu-yakkety-landing-061

« back to all changes in this revision

Viewing changes to service/dispatcher.c

  • Committer: CI Train Bot
  • Author(s): Ted Gould
  • Date: 2015-01-23 15:19:23 UTC
  • mfrom: (74.3.17 intent-pkg-domain-trunk)
  • Revision ID: ci-train-bot@canonical.com-20150123151923-gdhlx43c5bl6wyn3
Special handling for intent URLs Fixes: #1407709
Approved by: Charles Kerr, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
static GRegex * applicationre = NULL;
32
32
static GRegex * appidre = NULL;
33
33
static GRegex * genericre = NULL;
 
34
static GRegex * intentre = NULL;
34
35
static sqlite3 * urldb = NULL;
35
36
 
36
37
/* Errors */
326
327
        return TRUE;
327
328
}
328
329
 
 
330
/* Determine the domain for an intent using the package variable */
 
331
static gchar *
 
332
intent_domain (const gchar * url)
 
333
{
 
334
        gchar * domain = NULL;
 
335
        GMatchInfo * intentmatch = NULL;
 
336
 
 
337
        if (g_regex_match(intentre, url, 0, &intentmatch)) {
 
338
                domain = g_match_info_fetch(intentmatch, 1);
 
339
 
 
340
                g_match_info_free(intentmatch);
 
341
        }
 
342
 
 
343
        return domain;
 
344
}
 
345
 
329
346
/* The core of the URL handling */
330
347
gboolean
331
348
dispatcher_url_to_appid (const gchar * url, gchar ** out_appid, const gchar ** out_url)
367
384
        if (g_regex_match(genericre, url, 0, &genericmatch)) {
368
385
                gboolean found = FALSE;
369
386
                gchar * protocol = g_match_info_fetch(genericmatch, 1);
370
 
                gchar * domain = g_match_info_fetch(genericmatch, 2);
 
387
                gchar * domain = NULL;
 
388
 
 
389
                /* We special case the intent domain (further comment there) */
 
390
                if (g_strcmp0(protocol, "intent") == 0) {
 
391
                        domain = intent_domain(url);
 
392
                } else {
 
393
                        domain = g_match_info_fetch(genericmatch, 2);
 
394
                }
371
395
 
372
396
                *out_appid = url_db_find_url(urldb, protocol, domain);
373
397
                g_debug("Protocol '%s' for domain '%s' resulting in app id '%s'", protocol, domain, *out_appid);
450
474
        applicationre = g_regex_new("^application:///([a-zA-Z0-9_\\.-]*)\\.desktop$", 0, 0, NULL);
451
475
        appidre = g_regex_new("^appid://([a-z0-9\\.-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9\\.-]*)$", 0, 0, NULL);
452
476
        genericre = g_regex_new("^([a-z][a-z0-9]*):(?://(?:.*@)?([a-zA-Z0-9\\.-]*)(?::[0-9]*)?/?)?(.*)?$", 0, 0, NULL);
 
477
        intentre = g_regex_new("^intent://.*package=([a-zA-Z0-9\\.]*);.*$", 0, 0, NULL);
453
478
 
454
479
        g_bus_get(G_BUS_TYPE_SESSION, cancellable, bus_got, mainloop);
455
480
 
471
496
        g_regex_unref(applicationre);
472
497
        g_regex_unref(appidre);
473
498
        g_regex_unref(genericre);
 
499
        g_regex_unref(intentre);
474
500
        sqlite3_close(urldb);
475
501
 
476
502
        return TRUE;