#ifndef __URL_CLASSIFICATION_H__ #define __URL_CLASSIFICATION_H__ #ifdef __cplusplus extern "C" { #endif enum URL_CLASSIFICATION_TYPE { URL_CLASSTYPE_ADULT=0, URL_CLASSTYPE_VIRUS, URL_CLASSTYPE_PHISHING, URL_CLASSTYPE_DUGS, URL_CLASSTYPE_ACCEMIC_FRAUD, URL_CLASSTYPE_TASTELESS, URL_CLASSTYPE_HATE, URL_CLASSTYPE_PEOXIES, URL_CLASSTYPE_DATING, URL_CLASSTYPE_MUSIC, URL_CLASSTYPE_NEWS, URL_CLASSTYPE_AUDIO_VIDEO, URL_CLASSTYPE_ENTERTANMENT, //To be Continued, to be modified. URL_CLASSTYPE_NUM, //类型个数 }; typedef void* URLClassDB_handler_t; /*描述: 查询某个分类的URL配置总数 *返回值: 数量,0代表未查询到; */ int URLClassDB_count_class(URLClassDB_handler_t handler, enum URL_CLASSIFICATION_TYPE type); /*描述: 查询某个URL所属的分类 *输入: @url *输出: @array_num,数组个数 *返回值: 数组,调用者需要free它 */ enum URL_CLASSIFICATION_TYPE *URLClassDB_query_url_type(URLClassDB_handler_t handler, const char *url, int *array_num); /*描述: 获取某个分类的描述信息 *返回值: 某个分类的JSON格式的描述,JSON结构后续会扩充。例如 * {"en_name":"adult","ru_name":"Сайты для взрослых","cn_name":"成人网站"} */ const char *URLClassDB_get_class_description(URLClassDB_handler_t handler, enum URL_CLASSIFICATION_TYPE type); /*描述: 更新关注的分类列表 *输入: @types_array,列表数组 @array_num,数组个数 *返回值: 0: 成功; * -1: 失败; */ int URLClassDB_update_classes(URLClassDB_handler_t handler, const enum URL_CLASSIFICATION_TYPE *types_array, int array_num); typedef void (*update_class_callback)(int succ, void *user); /*描述: 更新关注的分类列表,内部创建线程,在新线程内回调update_class_callback; *输入: @types_array,列表数组 @array_num,数组个数 *返回值: 0: 成功; * -1: 失败; */ int URLClassDB_update_classes_asyn(URLClassDB_handler_t handler, update_class_callback cb, void *user, const enum URL_CLASSIFICATION_TYPE *types_array, int array_num); enum URLCLASSDB_INIT_OPT { URLCLASSDB_OPT_TMP_DIR=0, //Where to store temporary files which are generated by this module. VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. DEFAULT: Current directory. }; int URLClassDB_set_opttype(URLClassDB_handler_t handler, enum URLCLASSDB_INIT_OPT opt, const void* value, int size); /*描述: 创建一个查询/扫描实例 *返回值: 实例的句柄 */ URLClassDB_handler_t URLClassDB_instance_new(const char *dat_dir, const char *log_dir); /*描述: 启动一个实例 *返回值: 0: 成功; * -1: 失败; */ int URLClassDB_instance_starts(URLClassDB_handler_t handler); /*描述: 销毁一个查询/扫描实例 */ void URLClassDB_instance_destroy(URLClassDB_handler_t handler); #ifdef __cplusplus } #endif #endif