char *get_mime_protocol_info(void) { struct mime_type *entry; char *buf = NULL; char *p; int offset; int bufsize = 0; buf = malloc(bufsize); p = buf; assert(buf); // We assume an implementation that does 0-mallocs. if (buf == NULL) { fprintf(stderr, "%s: initial malloc failed\n", __FUNCTION__); return NULL; } for (entry = get_supported_mime_types(); entry; entry = entry->next) { bufsize += strlen(entry->mime_type) + 1 + 8 + 3 + 2; offset = p - buf; buf = realloc(buf, bufsize); if (buf == NULL) { fprintf(stderr, "%s: realloc failed\n", __FUNCTION__); return NULL; } p = buf; p += offset; strncpy(p, "http-get:*:", 11); p += 11; strncpy(p, entry->mime_type, strlen(entry->mime_type)); p += strlen(entry->mime_type); strncpy(p, ":*,", 3); p += 3; } if (p > buf) { p--; *p = '\0'; } *p = '\0'; return buf; }
static void prop_table_init(mpris *inst) { const gpointer default_values[] = { "CanQuit", g_variant_new_boolean(TRUE), "CanSetFullscreen", g_variant_new_boolean(TRUE), "CanRaise", g_variant_new_boolean(TRUE), "Fullscreen", g_variant_new_boolean(FALSE), "HasTrackList", g_variant_new_boolean(FALSE), "Identity", g_variant_new_string(g_get_application_name()), "DesktopEntry", g_variant_new_string(ICON_NAME), "SupportedUriSchemes", get_supported_uri_schemes(), "SupportedMimeTypes", get_supported_mime_types(), NULL }; gint i; for(i = 0; default_values[i]; i += 2) { g_hash_table_insert( inst->base_prop_table, default_values[i], default_values[i+1] ); } }