00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _EGG_SCRIPT_H_
00023 #define _EGG_SCRIPT_H_
00024
00025 BEGIN_C_DECLS
00026
00027
00028 enum
00029 {
00030 SCRIPT_EVENT_LOAD_SCRIPT = 0,
00031 SCRIPT_EVENT_LINK_VAR,
00032 SCRIPT_EVENT_UNLINK_VAR,
00033 SCRIPT_EVENT_CREATE_CMD,
00034 SCRIPT_EVENT_DELETE_CMD,
00035 SCRIPT_EVENT_MAX
00036 };
00037
00038
00039 enum
00040 {
00041 SCRIPT_OK = 0,
00042 SCRIPT_ERR_NOT_RESPONSIBLE,
00043 SCRIPT_ERR_CODE,
00044 };
00045
00046
00047
00048 typedef struct byte_array_b {
00049 unsigned char *bytes;
00050 int len;
00051 int do_free;
00052 } byte_array_t;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #define SCRIPT_PASS_CDATA 1
00074 #define SCRIPT_PASS_RETVAL 2
00075 #define SCRIPT_PASS_COUNT 4
00076 #define SCRIPT_PASS_ARRAY 8
00077 #define SCRIPT_VAR_ARGS 16
00078 #define SCRIPT_VAR_FRONT 32
00079
00080
00081
00082
00083
00084 #define SCRIPT_CALLBACK_ONCE 1
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #define SCRIPT_FREE 256
00098 #define SCRIPT_FREE_VAR 512
00099 #define SCRIPT_ARRAY 1024
00100 #define SCRIPT_ERROR 2048
00101 #define SCRIPT_READONLY 4096
00102
00103
00104 #define SCRIPT_STRING 's'
00105 #define SCRIPT_STRING_LIST 'S'
00106 #define SCRIPT_INTEGER 'i'
00107 #define SCRIPT_UNSIGNED 'u'
00108 #define SCRIPT_POINTER 'p'
00109 #define SCRIPT_CALLBACK 'c'
00110 #define SCRIPT_USER 'U'
00111 #define SCRIPT_BOT 'B'
00112 #define SCRIPT_PARTIER 'P'
00113 #define SCRIPT_ENTITY 'E'
00114 #define SCRIPT_BYTES 'b'
00115 #define SCRIPT_VAR 'v'
00116 #define SCRIPT_OBJECT 'o'
00117 #define SCRIPT_TYPE_MASK 255
00118
00119 typedef struct script_callback_b {
00120 int (*callback)();
00121 void *callback_data;
00122 void *delete_data;
00123 char *syntax;
00124 char *name;
00125 int flags;
00126 event_owner_t *owner;
00127 } script_callback_t;
00128
00129 typedef struct script_var_b {
00130 int type;
00131 void *value;
00132 int len;
00133 } script_var_t;
00134
00135 struct script_linked_var_b;
00136
00137 typedef struct script_var_callbacks_b {
00138 int (*on_read)(struct script_linked_var_b *linked_var, script_var_t *newvalue);
00139 int (*on_write)(struct script_linked_var_b *linked_var, script_var_t *newvalue);
00140 void *client_data;
00141 } script_var_callbacks_t;
00142
00143 typedef struct script_linked_var_b {
00144 char *class;
00145 char *name;
00146 void *value;
00147 int type;
00148 script_var_callbacks_t *callbacks;
00149 } script_linked_var_t;
00150
00151 typedef struct script_command_b {
00152 char *class;
00153 char *name;
00154 void *callback;
00155 void *client_data;
00156 int nargs;
00157 char *syntax;
00158 char *syntax_error;
00159 int retval_type;
00160 int flags;
00161 } script_command_t;
00162
00163 struct script_module_b;
00164
00165 typedef struct script_args_b {
00166 struct script_module_b *module;
00167 void *client_data;
00168 int len;
00169 } script_args_t;
00170
00171 typedef struct {
00172 char *class;
00173 char *name;
00174 int (*callback)(void *client_data, script_args_t *args, script_var_t *retval);
00175 void *client_data;
00176 } script_raw_command_t;
00177
00178 extern int script_init(void);
00179 extern int script_shutdown(void);
00180 extern int script_remove_events_by_owner(egg_module_t *module, void *script);
00181
00182 extern int script_load(char *filename);
00183 extern int script_link_vars(script_linked_var_t *table);
00184 extern int script_unlink_vars(script_linked_var_t *table);
00185 extern int script_create_raw_commands(script_raw_command_t *table);
00186 extern int script_delete_raw_commands(script_raw_command_t *table);
00187 extern int script_create_commands(script_command_t *table);
00188 extern int script_delete_commands(script_command_t *table);
00189 extern int script_get_arg(script_args_t *args, int num, script_var_t *var, int type);
00190
00191 extern script_var_t *script_string(char *str, int len);
00192 extern script_var_t *script_dynamic_string(char *str, int len);
00193 extern script_var_t *script_copy_string(char *str, int len);
00194 extern script_var_t *script_int(int val);
00195 extern script_var_t *script_list(int nitems, ...);
00196 extern int script_list_append(script_var_t *list, script_var_t *item);
00197
00198
00199
00200 typedef struct script_module_b {
00201 char *name;
00202 void *client_data;
00203
00204 int (*load_script)(void *client_data, char *filename);
00205 int (*link_var)(void *client_data, script_linked_var_t *linked_var);
00206 int (*unlink_var)(void *client_data, script_linked_var_t *linked_var);
00207 int (*create_command)(void *client_data, script_raw_command_t *cmd);
00208 int (*delete_command)(void *client_data, script_raw_command_t *cmd);
00209 int (*get_arg)(void *client_data, script_args_t *args, int num, script_var_t *var, int type);
00210 } script_module_t;
00211
00212 typedef int dns_function_t(const char *query, int timeout, dns_callback_t callback, void *data, event_owner_t *event);
00213
00214 extern int script_register_module(script_module_t *module);
00215 extern int script_unregister_module(script_module_t *module);
00216 extern int script_playback(script_module_t *module);
00217 extern int script_linked_var_on_write(script_linked_var_t *var, script_var_t *newval);
00218 extern int script_dns_query(dns_function_t *function, const char *host, script_callback_t *callback, char *text, int len);
00219
00220 END_C_DECLS
00221
00222 #endif