/** * gupnp_white_list_check_context: * @white_list: A #GUPnPWhiteList * @context: A #GUPnPContext to test. * * It will check if the @context is allowed or not. The @white_list will check * all its entries againt #GUPnPContext interface, host ip and network fields * information. This function doesn't take into account the @white_list status * (enabled or not). * * Return value: %TRUE if @context is matching the @white_list criterias, * %FALSE otherwise. * * Since: 0.20.5 **/ gboolean gupnp_white_list_check_context (GUPnPWhiteList *white_list, GUPnPContext *context) { GSSDPClient *client; GList *l; const char *interface; const char *host_ip; const char *network; gboolean match = FALSE; g_return_val_if_fail (GUPNP_IS_WHITE_LIST (white_list), FALSE); g_return_val_if_fail (GUPNP_IS_CONTEXT (context), FALSE); client = GSSDP_CLIENT (context); interface = gssdp_client_get_interface (client); host_ip = gssdp_client_get_host_ip (client); network = gssdp_client_get_network (client); l = white_list->priv->entries; while (l && !match) { match = (interface && !strcmp (l->data, interface)) || (host_ip && !strcmp (l->data, host_ip)) || (network && !strcmp (l->data, network)); l = l->next; } return match; }
static char* rygel_http_item_uri_create_uri_for_path (RygelHTTPItemURI* self, const char* path) { #line 532 "rygel-http-item-uri.c" char* result = NULL; #line 115 "rygel-http-item-uri.vala" g_return_val_if_fail (self != NULL, NULL); #line 115 "rygel-http-item-uri.vala" g_return_val_if_fail (path != NULL, NULL); #line 538 "rygel-http-item-uri.c" result = g_strdup_printf ("http://%s:%u%s%s", gssdp_client_get_host_ip ((GSSDPClient*) self->http_server->context), gupnp_context_get_port (self->http_server->context), rygel_http_server_get_path_root (self->http_server), path); #line 116 "rygel-http-item-uri.vala" return result; #line 542 "rygel-http-item-uri.c" }
void start_transfer (const char *file_path, const char *dest_uri, GUPnPServiceProxy *cds_proxy, GUPnPContext *context) { char *source_uri; char *file_name; if (!g_path_is_absolute (file_path)) { g_critical ("Given file path '%s' is not absolute.", file_path); transfer_completed (); return; } /* Time to host the file */ gupnp_context_host_path (context, file_path, file_path); source_uri = g_strdup_printf ("http://%s:%u%s", gssdp_client_get_host_ip (GSSDP_CLIENT (context)), gupnp_context_get_port (context), file_path); file_name = g_path_get_basename (file_path); gupnp_service_proxy_begin_action (cds_proxy, "ImportResource", import_resource_cb, file_name, "SourceURI", G_TYPE_STRING, source_uri, "DestinationURI", G_TYPE_STRING, dest_uri, NULL); g_free (source_uri); }
gint main (gint argc, gchar *argv[]) { GError *error = NULL; gint i; GOptionContext *context; #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init (); #endif context = g_option_context_new ("- Upload files to UPnP MediaServer"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); return -1; } if (argc < 3) { char *help = NULL; help = g_option_context_get_help (context, TRUE, NULL); g_print ("%s\n", help); g_free (help); return -4; } /* Get the list of files to upload */ for (i = 1; i < argc; i++) { if (!g_file_test (argv[i], G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_printerr ("File %s does not exist\n", argv[i]); } else { files = g_list_append (files, argv[i]); } } if (files == NULL) { return -5; } error = NULL; upnp_context = gupnp_context_new (NULL, interface, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return -6; } g_print ("UPnP context created for interface %s (%s)\n", gssdp_client_get_interface (GSSDP_CLIENT (upnp_context)), gssdp_client_get_host_ip (GSSDP_CLIENT (upnp_context))); if (!init_control_point (upnp_context, udn, search_timeout)) { return -3; } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Clean-up */ g_clear_pointer (&main_loop, g_main_loop_unref); deinit_control_point (); g_object_unref (upnp_context); g_option_context_free (context); g_free (dest_container); g_free (interface); return 0; }
static void prv_device_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dls_upnp_t *upnp = user_data; const char *udn; dls_device_t *device; const gchar *ip_address; dls_device_context_t *context; const dleyna_task_queue_key_t *queue_id; unsigned int i; prv_device_new_ct_t *priv_t; GUPnPDeviceInfo *device_proxy = (GUPnPDeviceInfo *)proxy; GUPnPDeviceInfo *device_info = NULL; const gchar *device_type; gboolean subscribe = FALSE; gpointer key; gpointer val; udn = gupnp_device_info_get_udn(device_proxy); ip_address = gssdp_client_get_host_ip( GSSDP_CLIENT(gupnp_control_point_get_context(cp))); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); device_type = gupnp_device_info_get_device_type(device_proxy); if (!g_str_has_prefix(device_type, DLS_DMS_DEVICE_TYPE)) { device_info = prv_lookup_dms_child_device(device_proxy); if (device_info == NULL) goto on_error; } else { device_info = device_proxy; } device = g_hash_table_lookup(upnp->device_udn_map, udn); if (!device) { device = g_hash_table_lookup(upnp->sleeping_device_udn_map, udn); if (device != NULL) { if (g_hash_table_lookup_extended( upnp->sleeping_device_udn_map, udn, &key, &val)) { g_hash_table_steal( upnp->sleeping_device_udn_map, udn); g_free(key); } g_hash_table_insert(upnp->device_udn_map, g_strdup(udn), device); if (device->wake_on_timeout_id) { DLEYNA_LOG_DEBUG("Stop WAKE-ON watcher..."); (void) g_source_remove( device->wake_on_timeout_id); device->wake_on_timeout_id = 0; } dls_device_delete_context(device->sleeping_context); device->sleeping_context = NULL; device->sleeping = FALSE; subscribe = TRUE; } } if (!device) { priv_t = g_hash_table_lookup(upnp->device_uc_map, udn); if (priv_t) device = priv_t->device; } if (!device) { DLEYNA_LOG_DEBUG("Device not found. Adding"); DLEYNA_LOG_DEBUG_NL(); queue_id = prv_create_device_queue(&priv_t); device = dls_device_new(upnp->connection, proxy, device_info, ip_address, upnp->interface_info, upnp->property_map, udn, queue_id); prv_update_device_context(priv_t, upnp, udn, device, ip_address, queue_id); } else { DLEYNA_LOG_DEBUG("Device Found"); for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i == device->contexts->len) { DLEYNA_LOG_DEBUG("Adding Context"); (void) dls_device_append_new_context(device, ip_address, proxy, device_info); if (subscribe) dls_device_subscribe_to_service_changes(device); } DLEYNA_LOG_DEBUG_NL(); } on_error: return; }
static void prv_server_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dlr_upnp_t *upnp = user_data; const char *udn; dlr_device_t *device; const gchar *ip_address; dlr_device_context_t *context; const dleyna_task_queue_key_t *queue_id; unsigned int i; prv_device_new_ct_t *priv_t; DLEYNA_LOG_DEBUG("Enter"); udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); ip_address = gssdp_client_get_host_ip( GSSDP_CLIENT(gupnp_control_point_get_context(cp))); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) device = priv_t->device; } if (!device) { DLEYNA_LOG_DEBUG("Device not found. Adding"); queue_id = prv_create_device_queue(&priv_t); device = dlr_device_new(upnp->connection, proxy, ip_address, udn, upnp->interface_info, queue_id); prv_update_device_context(priv_t, upnp, udn, device, ip_address, queue_id); } else { DLEYNA_LOG_DEBUG("Device Found"); for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i == device->contexts->len) { DLEYNA_LOG_DEBUG("Adding Context"); dlr_device_append_new_context(device, ip_address, proxy); } } on_error: DLEYNA_LOG_DEBUG("Exit"); DLEYNA_LOG_DEBUG_NL(); return; }