📄 swfdec_loader.c
字号:
/** * swfdec_loader_push: * @loader: a #SwfdecLoader * @buffer: new data to make available. The loader takes the reference * to the buffer. * * Makes the data in @buffer available to @loader and processes it. The @loader * must be open. **/voidswfdec_loader_push (SwfdecLoader *loader, SwfdecBuffer *buffer){ g_return_if_fail (SWFDEC_IS_LOADER (loader)); g_return_if_fail (loader->state == SWFDEC_LOADER_STATE_OPEN || loader->state == SWFDEC_LOADER_STATE_READING); g_return_if_fail (buffer != NULL); swfdec_buffer_queue_push (loader->queue, buffer); g_object_notify (G_OBJECT (loader), "loaded"); loader->state = SWFDEC_LOADER_STATE_READING; if (loader->player) swfdec_player_add_external_action (loader->player, loader, swfdec_loader_perform_push, NULL);}/** * swfdec_loader_eof: * @loader: a #SwfdecLoader * * Indicates to @loader that no more data will follow. The loader must be open. **/voidswfdec_loader_eof (SwfdecLoader *loader){ g_return_if_fail (SWFDEC_IS_LOADER (loader)); g_return_if_fail (loader->state == SWFDEC_LOADER_STATE_OPEN || loader->state == SWFDEC_LOADER_STATE_READING); if (loader->size == 0) { gulong bytes = swfdec_loader_get_loaded (loader); if (bytes) swfdec_loader_set_size (loader, bytes); } g_object_notify (G_OBJECT (loader), "eof"); loader->state = SWFDEC_LOADER_STATE_EOF; if (loader->player) swfdec_player_add_external_action (loader->player, loader, swfdec_loader_perform_eof, NULL);}/** * swfdec_loader_get_filename: * @loader: a #SwfdecLoader * * Gets the suggested filename to use for this loader. This may be of interest * when displaying information about the file that is played back. * * Returns: A string in the glib filename encoding that contains the filename * for this loader. g_free() after use. **/char *swfdec_loader_get_filename (SwfdecLoader *loader){ const SwfdecURL *url; const char *path, *ext; char *ret = NULL; g_return_val_if_fail (SWFDEC_IS_LOADER (loader), NULL); url = swfdec_loader_get_url (loader); path = swfdec_url_get_path (url); if (path) { char *s = strchr (path, '/'); if (s) path = s + 1; if (path[0] == 0) path = NULL; } if (path) ret = g_filename_from_utf8 (path, -1, NULL, NULL, NULL); if (ret == NULL) ret = g_strdup ("unknown"); ext = swfdec_loader_data_type_get_extension (loader->data_type); if (*ext) { char *dot = strrchr (ret, '.'); char *real; guint len = dot ? strlen (dot) : G_MAXUINT; if (len <= 5) *dot = '\0'; real = g_strdup_printf ("%s.%s", ret, ext); g_free (ret); ret = real; } return ret;}/** * swfdec_loader_get_url: * @loader: a #SwfdecLoader * * Gets the url this loader is handling. This is mostly useful for writing * subclasses of #SwfdecLoader. * * Returns: a #SwfdecURL describing @loader. **/const SwfdecURL *swfdec_loader_get_url (SwfdecLoader *loader){ g_return_val_if_fail (SWFDEC_IS_LOADER (loader), NULL); return loader->url;}/** * swfdec_loader_get_data_type: * @loader: a #SwfdecLoader * * Queries the type of data this loader provides. The type is determined * automatically by Swfdec. * * Returns: the type this data was identified to be in or * #SWFDEC_LOADER_DATA_UNKNOWN if not identified **/SwfdecLoaderDataTypeswfdec_loader_get_data_type (SwfdecLoader *loader){ g_return_val_if_fail (SWFDEC_IS_LOADER (loader), SWFDEC_LOADER_DATA_UNKNOWN); return loader->data_type;}voidswfdec_loader_set_data_type (SwfdecLoader *loader, SwfdecLoaderDataType type){ g_return_if_fail (SWFDEC_IS_LOADER (loader)); g_return_if_fail (loader->data_type == SWFDEC_LOADER_DATA_UNKNOWN); g_return_if_fail (type != SWFDEC_LOADER_DATA_UNKNOWN); loader->data_type = type; g_object_notify (G_OBJECT (loader), "data-type");}/** * swfdec_loader_set_size: * @loader: a #SwfdecLoader * @size: the amount of bytes in this loader * * Sets the size of bytes in this loader. This function may only be called once. **/voidswfdec_loader_set_size (SwfdecLoader *loader, gulong size){ g_return_if_fail (SWFDEC_IS_LOADER (loader)); g_return_if_fail (loader->size == 0); g_return_if_fail (size > 0); loader->size = size; g_object_notify (G_OBJECT (loader), "size");}/** * swfdec_loader_get_size: * @loader: a #SwfdecLoader * * Queries the amount of bytes inside @loader. If the size is unknown, 0 is * returned. * * Returns: the total number of bytes for this loader or 0 if unknown **/gulongswfdec_loader_get_size (SwfdecLoader *loader){ g_return_val_if_fail (SWFDEC_IS_LOADER (loader), 0); return loader->size;}/** * swfdec_loader_get_loaded: * @loader: a #SwfdecLoader * * Gets the amount of bytes that have already been pushed into @loader and are * available to Swfdec. * * Returns: Amount of bytes in @loader **/gulongswfdec_loader_get_loaded (SwfdecLoader *loader){ g_return_val_if_fail (SWFDEC_IS_LOADER (loader), 0); return swfdec_buffer_queue_get_depth (loader->queue) + swfdec_buffer_queue_get_offset (loader->queue);}/** * swfdec_loader_data_type_get_extension: * @type: a #SwfdecLoaderDataType * * Queries the extension to be used for data of the given @type. * * Returns: the typical extension for this data type or the empty string * if the type has no extension **/const char *swfdec_loader_data_type_get_extension (SwfdecLoaderDataType type){ switch (type) { case SWFDEC_LOADER_DATA_UNKNOWN: return ""; case SWFDEC_LOADER_DATA_SWF: return "swf"; case SWFDEC_LOADER_DATA_FLV: return "flv"; case SWFDEC_LOADER_DATA_XML: return "xml"; case SWFDEC_LOADER_DATA_TEXT: return "txt"; default: g_warning ("unknown data type %u", type); return ""; }}/*** X-WWW-FORM-URLENCODED ***//* if speed ever gets an issue, use a 256 byte array instead of strchr */static const char *urlencode_unescaped="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.,:/()'";static voidswfdec_urlencode_append_string (GString *str, const char *s){ g_assert (s != NULL); while (*s) { if (strchr (urlencode_unescaped, *s)) g_string_append_c (str, *s); else if (*s == ' ') g_string_append_c (str, '+'); else g_string_append_printf (str, "%%%02X", (guint) *s); s++; }}static char *swfdec_urldecode_one_string (const char *s, const char **out){ GString *ret = g_string_new (""); while (*s) { if (strchr (urlencode_unescaped, *s)) { g_string_append_c (ret, *s); } else if (*s == '+') { g_string_append_c (ret, ' '); } else if (*s == '%') { guint byte; s++; if (*s >= '0' && *s <= '9') { byte = *s - '0'; } else if (*s >= 'A' && *s <= 'F') { byte = *s - 'A' + 10; } else if (*s >= 'a' && *s <= 'f') { byte = *s - 'a' + 10; } else { g_string_free (ret, TRUE); *out = s; return NULL; } byte *= 16; s++; if (*s >= '0' && *s <= '9') { byte += *s - '0'; } else if (*s >= 'A' && *s <= 'F') { byte += *s - 'A' + 10; } else if (*s >= 'a' && *s <= 'f') { byte += *s - 'a' + 10; } else { g_string_free (ret, TRUE); *out = s; return NULL; } g_assert (byte < 256); g_string_append_c (ret, byte); } else { break; } s++; } *out = s; return g_string_free (ret, FALSE);}/** * swfdec_string_append_urlencoded: * @str: a #GString * @name: name of the property to append * @value: value of property to append or NULL for empty * * Appends a name/value pair in encoded as 'application/x-www-form-urlencoded' * to the given @str **/voidswfdec_string_append_urlencoded (GString *str, const char *name, const char *value){ g_return_if_fail (str != NULL); g_return_if_fail (name != NULL); if (str->len > 0) g_string_append_c (str, '&'); swfdec_urlencode_append_string (str, name); g_string_append_c (str, '='); if (value) swfdec_urlencode_append_string (str, value);}/** * swfdec_urldecode_one: * @string: string in 'application/x-www-form-urlencoded' form * @name: pointer that will hold a newly allocated string for the name of the * parsed property or NULL * @value: pointer that will hold a newly allocated string containing the * value of the parsed property or NULL * @end: If not %NULL, on success, pointer to the first byte in @s that was * not parsed. On failure it will point to the byte causing the problem * * Tries to parse the given @string into a name/value pair, assuming the string * is in the application/x-www-form-urlencoded format. If the parsing succeeds, * @name and @value will contain the parsed values and %TRUE will be returned. * * Returns: %TRUE if parsing the property succeeded, %FALSE otherwise */gbooleanswfdec_urldecode_one (const char *string, char **name, char **value, const char **end){ char *name_str, *value_str; g_return_val_if_fail (string != NULL, FALSE); name_str = swfdec_urldecode_one_string (string, &string); if (name_str == NULL) goto fail; if (*string != '=') { g_free (name_str); goto fail; } string++; value_str = swfdec_urldecode_one_string (string, &string); if (value_str == NULL) { g_free (name_str); goto fail; } if (name) *name = name_str; else g_free (name_str); if (value) *value = value_str; else g_free (value_str); if (end) *end = string; return TRUE;fail: if (name) *name = NULL; if (value) *value = NULL; if (end) *end = string; return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -