root / lib / filters / ngram-filter.c @ 4012ec30
History | View | Annotate | Download (970 Bytes)
| 1 | #include <glib.h> |
|---|---|
| 2 | |
| 3 | #include "filter.h" |
| 4 | #include "ngram-filter.h" |
| 5 | |
| 6 | |
| 7 | static char *do_ngram(const char *content) |
| 8 | {
|
| 9 | return g_strdup(content);
|
| 10 | } |
| 11 | |
| 12 | static XFilterStatus xfilter_ngram_func(XFilter *filter, const XMessageData *data, XMessageData **result) |
| 13 | {
|
| 14 | const char *mime_type; |
| 15 | const char *content = NULL; |
| 16 | char *processed_content;
|
| 17 | |
| 18 | *result = NULL;
|
| 19 | |
| 20 | mime_type = xfilter_message_data_get_mime_type(data); |
| 21 | if (!mime_type)
|
| 22 | return XF_UNSUPPORTED_TYPE;
|
| 23 | |
| 24 | if (!g_strncasecmp(mime_type, "text/", 5)) |
| 25 | content = xfilter_message_data_get_content(data); |
| 26 | else
|
| 27 | return XF_UNSUPPORTED_TYPE;
|
| 28 | |
| 29 | processed_content = do_ngram(content); |
| 30 | |
| 31 | *result = xfilter_message_data_new(NULL, mime_type);
|
| 32 | xfilter_message_data_set_content(*result, processed_content); |
| 33 | |
| 34 | return XF_REWRITTEN;
|
| 35 | } |
| 36 | |
| 37 | XFilter *xfilter_ngram_new(void)
|
| 38 | {
|
| 39 | XFilter *filter; |
| 40 | |
| 41 | filter = xfilter_new(XF_CONTENT, "ngram");
|
| 42 | xfilter_set_content_filter_func(X_CONTENT_FILTER(filter), |
| 43 | xfilter_ngram_func); |
| 44 | |
| 45 | return filter;
|
| 46 | } |