📄 gupnp-device-info.c
字号:
if (width) *width = icon->width; if (height) *height = icon->height; if (icon->url) { SoupURI *uri; uri = soup_uri_new_with_base (info->priv->url_base, (const char *) icon->url); ret = soup_uri_to_string (uri, FALSE); soup_uri_free (uri); } else ret = NULL; } else { if (mime_type) *mime_type = NULL; if (depth) *depth = -1; if (width) *width = -1; if (height) *height = -1; ret = NULL; } /* Cleanup */ while (icons) { icon_free (icons->data); icons = g_list_delete_link (icons, icons); } return ret;}/* Returns TRUE if @query matches against @base. * - If @query does not specify a version, it matches any version specified * in @base. * - If @query specifies a version, it matches any version specified in @base * that is greater or equal. * */static gbooleanresource_type_match (const char *query, const char *base){ gboolean match; guint type_len; char *colon; guint query_ver, base_ver; /* Inspect last colon (if any!) on @base */ colon = strrchr (base, ':'); if (G_UNLIKELY (*colon == 0)) return !strcmp (query, base); /* No colon */ /* Length of type until last colon */ type_len = strlen (base) - strlen (colon); /* Match initial portions */ match = (strncmp (query, base, type_len) == 0); if (match == FALSE) return FALSE; /* Initial portions matched. Try to position pointers after * last colons of both @query and @base. */ colon += 1; if (G_UNLIKELY (*colon == 0)) return TRUE; query += type_len; switch (*query) { case 0: return TRUE; /* @query does not specify a version */ case ':': query += 1; if (G_UNLIKELY (*query == 0)) return TRUE; break; default: return FALSE; /* Hmm, not EOS, nor colon.. bad */ } /* Parse versions */ query_ver = atoi (query); base_ver = atoi (colon); /* Compare versions */ return (query_ver <= base_ver);}/** * gupnp_device_info_list_devices * @info: A #GUPnPDeviceInfo * * Get a #GList of new objects implementing #GUPnPDeviceInfo * representing the devices directly contained in @info. The returned list * should be g_list_free()'d and the elements should be g_object_unref()'d. * * Note that devices are not cached internally, so that every time you * call this function new objects are created. The application * must cache any used devices if it wishes to keep them around and re-use * them. * * Return value: a #GList of new #GUPnPDeviceInfo objects. **/GList *gupnp_device_info_list_devices (GUPnPDeviceInfo *info){ GUPnPDeviceInfoClass *class; GList *devices; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); class = GUPNP_DEVICE_INFO_GET_CLASS (info); g_return_val_if_fail (class->get_device, NULL); devices = NULL; element = xml_util_get_element (info->priv->element, "deviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("device", (char *) element->name)) { GUPnPDeviceInfo *child; child = class->get_device (info, element); devices = g_list_prepend (devices, child); } } return devices;}/** * gupnp_device_info_list_device_types * @info: A #GUPnPDeviceInfo * * Get a #GList of strings representing the types of the devices * directly contained in @info. * * Return value: A #GList of strings. The elements should be g_free()'d and the * list should be g_list_free()'d. **/GList *gupnp_device_info_list_device_types (GUPnPDeviceInfo *info){ GList *device_types; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); device_types = NULL; element = xml_util_get_element (info->priv->element, "deviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("device", (char *) element->name)) { char *type; type = xml_util_get_child_element_content_glib (element, "deviceType"); if (!type) continue; device_types = g_list_prepend (device_types, type); } } return device_types;}/** * gupnp_device_info_get_device * @info: A #GUPnPDeviceInfo * @type: The type of the device to be retrieved. * * Get the service with type @type directly contained in @info as * a new object implementing #GUPnPDeviceInfo, or %NULL if no such device * was found. The returned object should be unreffed when done. * * Note that devices are not cached internally, so that every time you * call this function a new object is created. The application * must cache any used devices if it wishes to keep them around and re-use * them. * * Return value: A new #GUPnPDeviceInfo. **/GUPnPDeviceInfo *gupnp_device_info_get_device (GUPnPDeviceInfo *info, const char *type){ GUPnPDeviceInfoClass *class; GUPnPDeviceInfo *device; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); class = GUPNP_DEVICE_INFO_GET_CLASS (info); g_return_val_if_fail (class->get_device, NULL); device = NULL; element = xml_util_get_element (info->priv->element, "deviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("device", (char *) element->name)) { xmlNode *type_element; xmlChar *type_str; type_element = xml_util_get_element (element, "deviceType", NULL); if (!type_element) continue; type_str = xmlNodeGetContent (type_element); if (!type_str) continue; if (resource_type_match (type, (char *) type_str)) device = class->get_device (info, element); xmlFree (type_str); if (device) break; } } return device;}/** * gupnp_device_info_list_services * @info: A #GUPnPDeviceInfo * * Get a #GList of new objects implementing #GUPnPServiceInfo * representing the services directly contained in @info. The returned list * should be g_list_free()'d and the elements should be g_object_unref()'d. * * Note that services are not cached internally, so that every time you * call this function new objects are created. The application * must cache any used services if it wishes to keep them around and re-use * them. * * Return value: A #GList of new #GUPnPServiceInfo objects. **/GList *gupnp_device_info_list_services (GUPnPDeviceInfo *info){ GUPnPDeviceInfoClass *class; GList *services; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); class = GUPNP_DEVICE_INFO_GET_CLASS (info); g_return_val_if_fail (class->get_service, NULL); services = NULL; element = xml_util_get_element (info->priv->element, "serviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("service", (char *) element->name)) { GUPnPServiceInfo *service; service = class->get_service (info, element); services = g_list_prepend (services, service); } } return services;}/** * gupnp_device_info_list_service_types * @info: A #GUPnPDeviceInfo * * Get a #GList of strings representing the types of the services * directly contained in @info. * * Return value: A #GList of strings. The elements should be g_free()'d and the * list should be g_list_free()'d. **/GList *gupnp_device_info_list_service_types (GUPnPDeviceInfo *info){ GList *service_types; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); service_types = NULL; element = xml_util_get_element (info->priv->element, "serviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("service", (char *) element->name)) { char *type; type = xml_util_get_child_element_content_glib (element, "serviceType"); if (!type) continue; service_types = g_list_prepend (service_types, type); } } return service_types;}/** * gupnp_device_info_get_service * @info: A #GUPnPDeviceInfo * @type: The type of the service to be retrieved. * * Get the service with type @type directly contained in @info as * a new object implementing #GUPnPServiceInfo, or %NULL if no such device * was found. The returned object should be unreffed when done. * * Note that services are not cached internally, so that every time you * call this function a new object is created. The application * must cache any used services if it wishes to keep them around and re-use * them. * * Return value: A #GUPnPServiceInfo. **/GUPnPServiceInfo *gupnp_device_info_get_service (GUPnPDeviceInfo *info, const char *type){ GUPnPDeviceInfoClass *class; GUPnPServiceInfo *service; xmlNode *element; g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL); class = GUPNP_DEVICE_INFO_GET_CLASS (info); g_return_val_if_fail (class->get_service, NULL); service = NULL; element = xml_util_get_element (info->priv->element, "serviceList", NULL); if (!element) return NULL; for (element = element->children; element; element = element->next) { if (!strcmp ("service", (char *) element->name)) { xmlNode *type_element; xmlChar *type_str; type_element = xml_util_get_element (element, "serviceType", NULL); if (!type_element) continue; type_str = xmlNodeGetContent (type_element); if (!type_str) continue; if (resource_type_match (type, (char *) type_str)) service = class->get_service (info, element); xmlFree (type_str); if (service) break; } } return service;}/* Return associated xmlDoc wrapper */XmlDocWrapper *_gupnp_device_info_get_document (GUPnPDeviceInfo *info){ return info->priv->doc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -