GUAC-236: Add decoder search function.

This commit is contained in:
Michael Jumper 2016-02-27 17:58:07 -08:00
parent 083e48d089
commit 5149d6d5c4
2 changed files with 36 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "image-stream.h" #include "image-stream.h"
#include "jpeg.h" #include "jpeg.h"
#include "log.h"
#include "png.h" #include "png.h"
#ifdef ENABLE_WEBP #ifdef ENABLE_WEBP
@ -30,6 +31,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
guacenc_decoder_mapping guacenc_decoder_map[] = { guacenc_decoder_mapping guacenc_decoder_map[] = {
{"image/png", &guacenc_png_decoder}, {"image/png", &guacenc_png_decoder},
@ -40,3 +42,24 @@ guacenc_decoder_mapping guacenc_decoder_map[] = {
{NULL, NULL} {NULL, NULL}
}; };
guacenc_decoder* guacenc_get_decoder(const char* mimetype) {
/* Search through mapping for the decoder having given mimetype */
guacenc_decoder_mapping* current = guacenc_decoder_map;
while (current->mimetype != NULL) {
/* Return decoder if mimetype matches */
if (strcmp(current->mimetype, mimetype) == 0)
return current->decoder;
/* Next candidate decoder */
current++;
}
/* No such decoder */
guacenc_log(GUAC_LOG_WARNING, "Support for \"%s\" not present", mimetype);
return NULL;
}

View File

@ -193,5 +193,18 @@ typedef struct guacenc_decoder_mapping {
*/ */
extern guacenc_decoder_mapping guacenc_decoder_map[]; extern guacenc_decoder_mapping guacenc_decoder_map[];
/**
* Returns the decoder associated with the given mimetype. If no such decoder
* exists, NULL is returned.
*
* @param mimetype
* The image mimetype to return the associated decoder of.
*
* @return
* The decoder associated with the given mimetype, or NULL if no such
* decoder exists.
*/
guacenc_decoder* guacenc_get_decoder(const char* mimetype);
#endif #endif