-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphp_extractor.c
More file actions
71 lines (56 loc) · 1.88 KB
/
php_extractor.c
File metadata and controls
71 lines (56 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <php.h>
#include <extractor.h>
#include "php_extractor.h"
/* Define functs we want to add */
zend_function_entry extractor_functions[] = {
PHP_FE(extractor_get_keywords, NULL)
{NULL, NULL, NULL}
};
/* Module entry definitions */
zend_module_entry extractor_module_entry = {
STANDARD_MODULE_HEADER,
PHP_EXTRACTOR_EXTNAME,
extractor_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
PHP_EXTRACTOR_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* Install module */
ZEND_GET_MODULE(extractor)
static int process_keyword (void *cls, const char *plugin_name,
enum EXTRACTOR_MetaType type,
enum EXTRACTOR_MetaFormat format,
const char *data_mime_type,
const char *data, size_t data_len) {
zval *keywords, **subarray;
const char *ktype = EXTRACTOR_metatype_to_string(type);
const char *kval = estrndup(data, data_len);
ALLOC_INIT_ZVAL(keywords);
array_init(keywords);
if (zend_hash_find(Z_ARRVAL_P((zval*) cls), ktype, strlen(ktype) + 1, (void**) &subarray) == SUCCESS) {
add_next_index_string(*subarray, kval, 1);
return 0;
}
add_next_index_string(keywords, kval, 1);
add_assoc_zval(cls, ktype, keywords);
return 0;
}
PHP_FUNCTION(extractor_get_keywords) {
char *filepath = NULL;
int argc = ZEND_NUM_ARGS();
int filepath_len;
struct EXTRACTOR_PluginList *plugins;
EXTRACTOR_MetaDataProcessor processor = NULL;
if (zend_parse_parameters(argc TSRMLS_CC, "s", &filepath, &filepath_len) == FAILURE) {
return;
}
array_init(return_value);
processor = &process_keyword;
plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY);
EXTRACTOR_extract(plugins, filepath, NULL, 0, processor, return_value);
EXTRACTOR_plugin_remove_all(plugins);
}