#include "server.h"
Go to the source code of this file.
Functions | |
static int | script_isbotnick (char *nick) |
static int | script_irccmp (char *nick1, char *nick2) |
static int | script_server_list (script_var_t *retval) |
static int | name_to_priority (const char *queue, const char *next) |
static int | script_putserv (char *queue, char *next, char *text) |
static int | script_jump (int nargs, int num) |
static int | script_dcc_send_info (int idx, char *what) |
static int | script_channel_list (script_var_t *retval) |
static int | script_channel_members (script_var_t *retval, char *chan_name) |
static int | script_channel_topic (script_var_t *retval, char *chan_name) |
static int | script_channel_mask_list (script_var_t *retval, char *chan_name, char *type) |
static char * | script_channel_mode (char *chan, char *nick) |
static const char * | script_channel_mode_arg (char *chan, char *mode) |
static char * | script_channel_key (char *chan_name) |
static int | script_channel_limit (char *chan_name) |
static char * | script_schan_get (char *chan_name, char *setting) |
static int | script_schan_set (char *chan_name, char *setting, char *value) |
static int | script_queue_len (char *qname, char *next) |
static void | get_queue_entry (char *qname, char *next, int num, queue_t **queue_ptr, queue_entry_t **queue_entry_ptr) |
static char * | script_queue_get (char *qname, char *next, int num) |
static int | script_queue_set (char *qname, char *next, int num, char *msg) |
static int | script_queue_insert (char *qname, char *next, int num, char *msg) |
static int | script_supports (const char *name) |
static const char * | script_support_val (const char *name) |
int | server_script_init () |
int | server_script_destroy () |
Variables | |
static const char | rcsid [] = "$Id: scriptcmds.c,v 1.47 2005-06-09 02:56:44 stdarg Exp $" |
int | cycle_delay |
current_server_t | current_server |
char * | global_output_string |
char * | global_input_string |
static script_linked_var_t | server_script_vars [] |
static script_command_t | server_script_cmds [] |
static void get_queue_entry | ( | char * | qname, | |
char * | next, | |||
int | num, | |||
queue_t ** | queue_ptr, | |||
queue_entry_t ** | queue_entry_ptr | |||
) | [static] |
Definition at line 286 of file scriptcmds.c.
References queue_t::len, name_to_priority(), queue_entry::next, NULL, queue_entry::prev, queue_get_by_priority, queue_t::queue_head, and queue_t::queue_tail.
Referenced by script_queue_get(), script_queue_insert(), and script_queue_set().
00287 { 00288 int prio; 00289 queue_t *queue; 00290 queue_entry_t *q; 00291 00292 /* Look up queue. */ 00293 prio = name_to_priority(qname, next); 00294 queue = queue_get_by_priority(prio); 00295 00296 /* Get entry. */ 00297 if (num >= 0 && num < queue->len/2) { 00298 for (q = queue->queue_head; q && num > 0; q = q->next) { 00299 num--; 00300 } 00301 } 00302 else if (num >= queue->len/2 && num < queue->len) { 00303 num -= (queue->len/2); 00304 for (q = queue->queue_tail; q && num > 0; q = q->prev) { 00305 num--; 00306 } 00307 } 00308 else q = NULL; 00309 00310 if (queue_ptr) *queue_ptr = queue; 00311 if (queue_entry_ptr) *queue_entry_ptr = q; 00312 }
static int name_to_priority | ( | const char * | queue, | |
const char * | next | |||
) | [static] |
Definition at line 60 of file scriptcmds.c.
References NULL, SERVER_NEXT, SERVER_NOQUEUE, SERVER_NORMAL, SERVER_QUICK, and SERVER_SLOW.
Referenced by get_queue_entry(), script_putserv(), and script_queue_len().
00061 { 00062 int prio; 00063 00064 /* Figure out which arguments they've given us. */ 00065 if (!next) queue = NULL; 00066 else if (!queue) { 00067 /* If we only have 1 option, check to see if it's -next or 00068 a queue. */ 00069 if (!strcasecmp(next, "next")) queue = NULL; 00070 else { 00071 queue = next; 00072 next = NULL; 00073 } 00074 } 00075 else if (!strcasecmp(queue, "next")) { 00076 /* They did it in reverse order, so swap them. */ 00077 const char *temp = next; 00078 next = queue; 00079 queue = temp; 00080 } 00081 00082 /* Figure out which queue they want. */ 00083 if (!queue) prio = SERVER_NORMAL; 00084 else if (!strcasecmp(queue, "noqueue")) prio = SERVER_NOQUEUE; 00085 else if (!strcasecmp(queue, "slow")) prio = SERVER_SLOW; 00086 else if (!strcasecmp(queue, "quick")) prio = SERVER_QUICK; 00087 else prio = SERVER_NORMAL; 00088 00089 if (next) prio |= SERVER_NEXT; 00090 00091 return(prio); 00092 }
static char* script_channel_key | ( | char * | chan_name | ) | [static] |
Definition at line 236 of file scriptcmds.c.
References channel_probe, channel::key, and NULL.
00237 { 00238 channel_t *chan; 00239 00240 chan = channel_probe(chan_name, 0); 00241 if (chan) return(chan->key); 00242 return(NULL); 00243 }
static int script_channel_limit | ( | char * | chan_name | ) | [static] |
Definition at line 245 of file scriptcmds.c.
References channel_probe, and channel::limit.
00246 { 00247 channel_t *chan; 00248 00249 chan = channel_probe(chan_name, 0); 00250 if (chan) return(chan->limit); 00251 return(-1); 00252 }
static int script_channel_list | ( | script_var_t * | retval | ) | [static] |
Definition at line 145 of file scriptcmds.c.
References channel_head, script_var_b::len, channel::name, channel::next, SCRIPT_ARRAY, SCRIPT_FREE, script_list_append(), script_string(), SCRIPT_VAR, and script_var_b::type.
00146 { 00147 channel_t *chan; 00148 00149 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR; 00150 retval->len = 0; 00151 00152 for (chan = channel_head; chan; chan = chan->next) { 00153 script_list_append(retval, script_string(chan->name, -1)); 00154 } 00155 return(0); 00156 }
static int script_channel_mask_list | ( | script_var_t * | retval, | |
char * | chan_name, | |||
char * | type | |||
) | [static] |
Definition at line 192 of file scriptcmds.c.
References channel_get_mask_list, channel_probe, channel_mask_list::head, script_var_b::len, channel_mask::mask, channel_mask::next, SCRIPT_ARRAY, SCRIPT_FREE, script_int(), script_list(), script_list_append(), script_string(), SCRIPT_VAR, channel_mask::set_by, channel_mask::time, and script_var_b::type.
00193 { 00194 channel_t *chan; 00195 channel_mask_t *m; 00196 channel_mask_list_t *l; 00197 00198 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR; 00199 retval->len = 0; 00200 00201 chan = channel_probe(chan_name, 0); 00202 if (!chan) return(-1); 00203 00204 l = channel_get_mask_list(chan, type[0]); 00205 if (!l) return(-1); 00206 00207 for (m = l->head; m; m = m->next) { 00208 script_list_append(retval, 00209 script_list(3, 00210 script_string(m->mask, -1), 00211 script_string(m->set_by, -1), 00212 script_int(m->time) 00213 ) 00214 ); 00215 } 00216 return(0); 00217 }
static int script_channel_members | ( | script_var_t * | retval, | |
char * | chan_name | |||
) | [static] |
Definition at line 158 of file scriptcmds.c.
References channel_probe, script_var_b::len, channel::member_head, channel_member::next, channel_member::nick, SCRIPT_ARRAY, SCRIPT_FREE, script_list_append(), script_string(), SCRIPT_VAR, and script_var_b::type.
00159 { 00160 channel_t *chan; 00161 channel_member_t *m; 00162 00163 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR; 00164 retval->len = 0; 00165 00166 chan = channel_probe(chan_name, 0); 00167 if (!chan) return(-1); 00168 00169 for (m = chan->member_head; m; m = m->next) { 00170 script_list_append(retval, script_string(m->nick, -1)); 00171 } 00172 00173 return(0); 00174 }
static char* script_channel_mode | ( | char * | chan, | |
char * | nick | |||
) | [static] |
Definition at line 219 of file scriptcmds.c.
References channel_mode.
00220 { 00221 char *buf; 00222 00223 buf = malloc(64); 00224 channel_mode(chan, nick, buf); 00225 return(buf); 00226 }
static const char* script_channel_mode_arg | ( | char * | chan, | |
char * | mode | |||
) | [static] |
Definition at line 228 of file scriptcmds.c.
References channel_mode_arg, and NULL.
00229 { 00230 const char *value = NULL; 00231 00232 channel_mode_arg(chan, *mode, &value); 00233 return(value); 00234 }
static int script_channel_topic | ( | script_var_t * | retval, | |
char * | chan_name | |||
) | [static] |
Definition at line 176 of file scriptcmds.c.
References channel_probe, script_var_b::len, SCRIPT_ARRAY, SCRIPT_FREE, script_int(), script_list_append(), script_string(), SCRIPT_VAR, channel::topic, channel::topic_nick, channel::topic_time, and script_var_b::type.
00177 { 00178 channel_t *chan; 00179 00180 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR; 00181 retval->len = 0; 00182 00183 chan = channel_probe(chan_name, 0); 00184 if (!chan) return(-1); 00185 00186 script_list_append(retval, script_string(chan->topic, -1)); 00187 script_list_append(retval, script_string(chan->topic_nick, -1)); 00188 script_list_append(retval, script_int(chan->topic_time)); 00189 return(0); 00190 }
static int script_dcc_send_info | ( | int | idx, | |
char * | what | |||
) | [static] |
Definition at line 114 of file scriptcmds.c.
References DCC_SEND_ACKS, DCC_SEND_BYTES_ACKED, DCC_SEND_CONNECT_TIME, DCC_SEND_CPS_SNAPSHOT, DCC_SEND_CPS_TOTAL, dcc_send_info, DCC_SEND_LEFT, DCC_SEND_REQUEST_TIME, DCC_SEND_RESUMED_AT, and DCC_SEND_SENT.
00115 { 00116 int field, value; 00117 00118 if (!strcasecmp(what, "bytes_left")) 00119 field = DCC_SEND_LEFT; 00120 else if (!strcasecmp(what, "bytes_sent")) 00121 field = DCC_SEND_SENT; 00122 else if (!strcasecmp(what, "total_cps")) 00123 field = DCC_SEND_CPS_TOTAL; 00124 else if (!strcasecmp(what, "snapshot_cps")) 00125 field = DCC_SEND_CPS_SNAPSHOT; 00126 else if (!strcasecmp(what, "acks")) 00127 field = DCC_SEND_ACKS; 00128 else if (!strcasecmp(what, "bytes_acked")) 00129 field = DCC_SEND_BYTES_ACKED; 00130 else if (!strcasecmp(what, "resumed_at")) 00131 field = DCC_SEND_RESUMED_AT; 00132 else if (!strcasecmp(what, "request_time")) 00133 field = DCC_SEND_REQUEST_TIME; 00134 else if (!strcasecmp(what, "connect_time")) 00135 field = DCC_SEND_CONNECT_TIME; 00136 else 00137 return(-1); 00138 00139 if (dcc_send_info(idx, field, &value) < 0) 00140 return(-1); 00141 00142 return(value); 00143 }
static int script_irccmp | ( | char * | nick1, | |
char * | nick2 | |||
) | [static] |
Definition at line 42 of file scriptcmds.c.
References current_server_t::strcmp.
00043 { 00044 return (current_server.strcmp)(nick1, nick2); 00045 }
static int script_isbotnick | ( | char * | nick | ) | [static] |
Definition at line 37 of file scriptcmds.c.
References match_my_nick.
00038 { 00039 return match_my_nick(nick); 00040 }
static int script_jump | ( | int | nargs, | |
int | num | |||
) | [static] |
Definition at line 104 of file scriptcmds.c.
References cycle_delay, kill_server, server_config, and server_set_next.
00105 { 00106 if (nargs) server_set_next(num); 00107 00108 cycle_delay = server_config.cycle_delay; 00109 kill_server("changing servers"); 00110 00111 return(0); 00112 }
static int script_putserv | ( | char * | queue, | |
char * | next, | |||
char * | text | |||
) | [static] |
Definition at line 94 of file scriptcmds.c.
References name_to_priority(), and printserv.
00095 { 00096 int prio; 00097 00098 prio = name_to_priority(queue, next); 00099 printserv(prio, "%s\r\n", text); 00100 00101 return(0); 00102 }
static char* script_queue_get | ( | char * | qname, | |
char * | next, | |||
int | num | |||
) | [static] |
Definition at line 314 of file scriptcmds.c.
References get_queue_entry(), NULL, and queue_entry_to_text.
00315 { 00316 queue_entry_t *q; 00317 char buf[1024]; 00318 int remaining; 00319 00320 get_queue_entry(qname, next, num, NULL, &q); 00321 if (!q) return(NULL); 00322 00323 remaining = sizeof(buf); 00324 queue_entry_to_text(q, buf, &remaining); 00325 if (remaining < sizeof(buf)) buf[sizeof(buf)-remaining-1] = 0; 00326 else buf[0] = 0; 00327 00328 return strdup(buf); 00329 }
static int script_queue_insert | ( | char * | qname, | |
char * | next, | |||
int | num, | |||
char * | msg | |||
) | [static] |
Definition at line 342 of file scriptcmds.c.
References get_queue_entry(), queue_t::len, queue_entry::next, queue_entry::prev, queue_append, queue_t::queue_head, and queue_new.
00343 { 00344 queue_t *queue; 00345 queue_entry_t *q, *newq; 00346 00347 get_queue_entry(qname, next, num, &queue, &q); 00348 newq = queue_new(msg); 00349 if (!q) queue_append(queue, newq); 00350 else { 00351 queue->len++; 00352 newq->next = q; 00353 newq->prev = q->prev; 00354 if (q->prev) q->prev->next = newq; 00355 else queue->queue_head = newq; 00356 q->prev = q; 00357 } 00358 00359 return(0); 00360 }
static int script_queue_len | ( | char * | qname, | |
char * | next | |||
) | [static] |
Definition at line 274 of file scriptcmds.c.
References queue_t::len, name_to_priority(), and queue_get_by_priority.
00275 { 00276 int prio; 00277 queue_t *queue; 00278 00279 /* Look up queue. */ 00280 prio = name_to_priority(qname, next); 00281 queue = queue_get_by_priority(prio); 00282 00283 return(queue->len); 00284 }
static int script_queue_set | ( | char * | qname, | |
char * | next, | |||
int | num, | |||
char * | msg | |||
) | [static] |
Definition at line 331 of file scriptcmds.c.
References get_queue_entry(), NULL, and queue_entry_from_text.
00332 { 00333 queue_entry_t *q; 00334 00335 get_queue_entry(qname, next, num, NULL, &q); 00336 if (!q) return(-1); 00337 00338 queue_entry_from_text(q, msg); 00339 return(0); 00340 }
static char* script_schan_get | ( | char * | chan_name, | |
char * | setting | |||
) | [static] |
Definition at line 254 of file scriptcmds.c.
References channel_get, channel_probe, and NULL.
00255 { 00256 channel_t *chan = channel_probe(chan_name, 0); 00257 char *value; 00258 00259 if (!chan) return(NULL); 00260 channel_get(chan, &value, setting, 0, NULL); 00261 return(value); 00262 }
static int script_schan_set | ( | char * | chan_name, | |
char * | setting, | |||
char * | value | |||
) | [static] |
Definition at line 264 of file scriptcmds.c.
References channel_probe, channel_set, and NULL.
00265 { 00266 channel_t *chan = channel_probe(chan_name, 1); 00267 00268 if (!chan) return(-1); 00269 return channel_set(chan, value, setting, 0, NULL); 00270 }
static int script_server_list | ( | script_var_t * | retval | ) | [static] |
Definition at line 47 of file scriptcmds.c.
References server::host, script_var_b::len, server::next, server::pass, server::port, SCRIPT_ARRAY, SCRIPT_FREE, script_int(), script_list(), script_list_append(), script_string(), SCRIPT_VAR, server_list, and script_var_b::type.
00048 { 00049 server_t *s; 00050 00051 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_VAR; 00052 retval->len = 0; 00053 00054 for (s = server_list; s; s = s->next) { 00055 script_list_append(retval, script_list(3, script_string(s->host, -1), script_string(s->pass, -1), script_int(s->port))); 00056 } 00057 return(0); 00058 }
static const char* script_support_val | ( | const char * | name | ) | [static] |
Definition at line 374 of file scriptcmds.c.
References server_support.
00375 { 00376 const char *value; 00377 server_support(name, &value); 00378 return value; 00379 }
static int script_supports | ( | const char * | name | ) | [static] |
Definition at line 363 of file scriptcmds.c.
References server_support.
00364 { 00365 const char *value; 00366 00367 if (!server_support(name, &value)) { 00368 /* Supported. */ 00369 return(1); 00370 } 00371 return(0); 00372 }
int server_script_destroy | ( | ) |
Definition at line 456 of file scriptcmds.c.
References script_delete_commands(), and script_unlink_vars().
00457 { 00458 script_delete_commands(server_script_cmds); 00459 script_unlink_vars(server_script_vars); 00460 return(0); 00461 }
int server_script_init | ( | ) |
Definition at line 449 of file scriptcmds.c.
References script_create_commands(), and script_link_vars().
00450 { 00451 script_create_commands(server_script_cmds); 00452 script_link_vars(server_script_vars); 00453 return(0); 00454 }
int cycle_delay |
char* global_input_string |
char* global_output_string |
const char rcsid[] = "$Id: scriptcmds.c,v 1.47 2005-06-09 02:56:44 stdarg Exp $" [static] |
Definition at line 21 of file scriptcmds.c.
script_command_t server_script_cmds[] [static] |
Definition at line 392 of file scriptcmds.c.
script_linked_var_t server_script_vars[] [static] |
Initial value:
{ {"", "servidx", ¤t_server.idx, SCRIPT_INTEGER | SCRIPT_READONLY, NULL}, {"", "server", &server_list_index, SCRIPT_INTEGER | SCRIPT_READONLY, NULL}, {"", "botnick", ¤t_server.nick, SCRIPT_STRING | SCRIPT_READONLY, NULL}, {"", "myip", ¤t_server.myip, SCRIPT_STRING, NULL}, {"", "mylongip", ¤t_server.mylongip, SCRIPT_UNSIGNED, NULL}, {"", "server_input_string", &global_input_string, SCRIPT_STRING, NULL}, {"", "server_output_string", &global_output_string, SCRIPT_STRING, NULL}, {0} }
Definition at line 381 of file scriptcmds.c.