static void import_resource_cb (GUPnPServiceProxy *cds_proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error; guint transfer_id; char *file_name; file_name = (gchar *) user_data; error = NULL; if (!gupnp_service_proxy_end_action (cds_proxy, action, &error, "TransferID", G_TYPE_UINT, &transfer_id, NULL)) { g_critical ("Failed to start file transfer: %s", error->message); g_free (file_name); g_error_free (error); transfer_completed (); return; } g_print ("Uploading %s: 00%%", file_name); start_tracking_transfer (cds_proxy, transfer_id); g_free (file_name); }
static void get_transfer_progress_cb (GUPnPServiceProxy *cds_proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error; TrackTransferData *data; guint64 total, length; gchar *status; data = (TrackTransferData *) user_data; error = NULL; total = length = 0; status = NULL; if (!gupnp_service_proxy_end_action (cds_proxy, action, &error, "TransferStatus", G_TYPE_STRING, &status, "TransferLength", G_TYPE_UINT64, &length, "TransferTotal", G_TYPE_UINT64, &total, NULL)) { g_critical ("Failed to track file transfer: %s", error->message); g_error_free (error); transfer_completed (); return; } if (g_strcmp0 (status, "IN_PROGRESS") == 0) { if (total > 0) { guint64 progress = length * 100 / total; g_print ("\b\b\b%2" G_GUINT64_FORMAT "%%", progress); } data->action = NULL; g_free (status); } else { g_print ("\b\b\bDone.\n"); g_free (status); g_source_remove (data->timeout_id); g_slice_free (TrackTransferData, data); transfer_completed (); } }
static void _service_proxy_added_port_mapping (GUPnPServiceProxy *proxy, GUPnPServiceProxyAction *action, gpointer user_data) { struct ProxyMapping *pm = user_data; GUPnPSimpleIgd *self = pm->proxy->parent; GError *error = NULL; g_return_if_fail (pm->action == action); pm->action = NULL; if (gupnp_service_proxy_end_action (proxy, action, &error, NULL)) { pm->mapped = TRUE; if (pm->proxy->external_ip) g_signal_emit (self, signals[SIGNAL_MAPPED_EXTERNAL_PORT], 0, pm->mapping->protocol, pm->proxy->external_ip, NULL, pm->actual_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); if (pm->mapping->lease_duration > 0) { pm->renew_src = g_timeout_source_new_seconds (pm->mapping->lease_duration / 2); g_source_set_callback (pm->renew_src, _renew_mapping_timeout, pm, NULL); g_source_attach (pm->renew_src, self->priv->main_context); } } else { g_return_if_fail (error); /* 718 == ConflictInMappingEntry */ if (pm->mapping->requested_external_port == 0 && error->domain == GUPNP_CONTROL_ERROR && error->code == 718) { /* The previous port was already used, lets pick another random port */ pm->actual_external_port = g_random_int_range (1025, 65535); gupnp_simple_igd_call_add_port_mapping (pm, _service_proxy_added_port_mapping); } else { g_signal_emit (self, signals[SIGNAL_ERROR_MAPPING_PORT], error->domain, error, pm->mapping->protocol, pm->mapping->requested_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); } } g_clear_error (&error); }
void browse_cb(GUPnPServiceProxy *content_dir, GUPnPServiceProxyAction *action, gpointer user_data) { struct browse_data *data; char *didl_xml; guint32 number_returned; guint32 total_matches; GError *error; data = (struct browse_data *)user_data; didl_xml = NULL; error = NULL; gupnp_service_proxy_end_action(content_dir, action, &error, "Result", G_TYPE_STRING, &didl_xml, "NumberReturned", G_TYPE_UINT, &number_returned, "TotalMatches", G_TYPE_UINT, &total_matches, NULL); if (didl_xml) { guint32 remaining; GError *error = NULL; if (!gupnp_didl_lite_parser_parse_didl(data->didl_parser, didl_xml, add_content, data, &error)) { g_warning("%s\n", error->message); g_error_free(error); } g_free(didl_xml); data->starting_index += number_returned; /* See if we have more objects to get */ remaining = total_matches - data->starting_index; /* Keep browsing till we get each and every object */ if (remaining != 0) browse(content_dir, data->id, data->starting_index, MIN(remaining, MAX_BROWSE), data->list, data->didl_parser); } else if (error) { GUPnPServiceInfo *info; info = GUPNP_SERVICE_INFO(content_dir); g_warning("Failed to browse '%s': %s\n", gupnp_service_info_get_location(info), error->message); g_error_free(error); } browse_data_free(data); }
static void browse_cb (GUPnPServiceProxy *cds_proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error; char *result; char *container_id; error = NULL; if (!gupnp_service_proxy_end_action (cds_proxy, action, &error, "Result", G_TYPE_STRING, &result, NULL)) { g_critical ("Failed to browse root container: %s", error->message); g_error_free (error); application_exit (); return; } g_assert (result != NULL); container_id = parse_result (result); if (container_id == NULL) { g_critical ("Failed to find a suitable container for upload."); g_free (result); application_exit (); return; } else { container_found (container_id); g_free (container_id); } g_free (result); }
static void create_object_cb (GUPnPServiceProxy *cds_proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error; char *result; const char *import_uri; error = NULL; if (!gupnp_service_proxy_end_action (cds_proxy, action, &error, "Result", G_TYPE_STRING, &result, NULL)) { g_critical ("Failed to create new item on remote container: %s", error->message); g_error_free (error); item_created (NULL); return; } if (result == NULL) { g_critical ("Failed to create new item on remote container." "No reasons given by MediaServer."); item_created (NULL); return; } import_uri = parse_result (result); item_created (import_uri); g_free (result); }
static void _service_proxy_delete_port_mapping (GUPnPServiceProxy *proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error = NULL; GUPnPSimpleIgd *self = user_data; if (!gupnp_service_proxy_end_action (proxy, action, &error, NULL)) { g_return_if_fail (error); g_warning ("Error deleting port mapping: %s", error->message); } g_clear_error (&error); if (self) { self->priv->deleting_count--; g_object_unref (self); } }
static void on_service_proxy_action_ret (GUPnPServiceProxy *proxy, GUPnPServiceProxyAction *action, gpointer user_data) { GError *error = NULL; gupnp_service_proxy_end_action (proxy, action, &error, NULL); if (error) { GUPnPServiceInfo *info = GUPNP_SERVICE_INFO (proxy); g_warning ("Failed to call action \"%s\" on \"%s\": %s", (char *) user_data, gupnp_service_info_get_location (info), error->message); g_error_free (error); } g_free (user_data); }
static void _service_proxy_renewed_port_mapping (GUPnPServiceProxy *proxy, GUPnPServiceProxyAction *action, gpointer user_data) { struct ProxyMapping *pm = user_data; GUPnPSimpleIgd *self = pm->proxy->parent; GError *error = NULL; g_return_if_fail (pm->action == action); pm->action = NULL; if (!gupnp_service_proxy_end_action (proxy, action, &error, NULL)) { g_return_if_fail (error); g_signal_emit (self, signals[SIGNAL_ERROR_MAPPING_PORT], error->domain, error, pm->mapping->protocol, pm->mapping->requested_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); } g_clear_error (&error); }
static void _service_proxy_got_external_ip_address (GUPnPServiceProxy *proxy, GUPnPServiceProxyAction *action, gpointer user_data) { struct Proxy *prox = user_data; GUPnPSimpleIgd *self = prox->parent; GError *error = NULL; gchar *ip = NULL; g_return_if_fail (prox->external_ip_action == action); prox->external_ip_action = NULL; if (gupnp_service_proxy_end_action (proxy, action, &error, "NewExternalIPAddress", G_TYPE_STRING, &ip, NULL)) { guint i; if (!validate_ip_address (ip)) { prox->external_ip_failed = TRUE; for (i=0; i < prox->proxymappings->len; i++) { struct ProxyMapping *pm = g_ptr_array_index (prox->proxymappings, i); GError gerror = {GUPNP_SIMPLE_IGD_ERROR, GUPNP_SIMPLE_IGD_ERROR_EXTERNAL_ADDRESS, "Invalid IP address returned by router" }; g_signal_emit (self, signals[SIGNAL_ERROR_MAPPING_PORT], GUPNP_SIMPLE_IGD_ERROR, &gerror, pm->mapping->protocol, pm->mapping->requested_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); } return; } /* Only emit the new signal if the IP changes */ if (prox->external_ip && strcmp (ip, prox->external_ip)) { for (i=0; i < prox->proxymappings->len; i++) { struct ProxyMapping *pm = g_ptr_array_index (prox->proxymappings, i); if (pm->mapped) g_signal_emit (self, signals[SIGNAL_MAPPED_EXTERNAL_PORT], 0, pm->mapping->protocol, ip, prox->external_ip, pm->actual_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); } } g_free (prox->external_ip); prox->external_ip = ip; } else { guint i; prox->external_ip_failed = TRUE; g_return_if_fail (error); for (i=0; i < prox->proxymappings->len; i++) { struct ProxyMapping *pm = g_ptr_array_index (prox->proxymappings, i); g_signal_emit (self, signals[SIGNAL_ERROR_MAPPING_PORT], error->domain, error, pm->mapping->protocol, pm->mapping->requested_external_port, pm->mapping->local_ip, pm->mapping->local_port, pm->mapping->description); } } g_clear_error (&error); }