Go to the source code of this file.
Functions | |
int | printserv (int priority, const char *format,...) |
queue_entry_t * | queue_new (char *text) |
void | queue_append (queue_t *queue, queue_entry_t *q) |
void | queue_unlink (queue_t *queue, queue_entry_t *q) |
void | queue_entry_from_text (queue_entry_t *q, char *text) |
void | queue_entry_to_text (queue_entry_t *q, char *text, int *remaining) |
void | queue_entry_cleanup (queue_entry_t *q) |
queue_t * | queue_get_by_priority (int priority) |
void | dequeue_messages () |
void dequeue_messages | ( | ) |
Definition at line 213 of file output.c.
00214 { 00215 queue_entry_t *q; 00216 queue_t *queue = NULL; 00217 int i, remaining, len; 00218 char *text, buf[1024]; 00219 00220 /* Choose which queue to select from. */ 00221 for (i = 0; i < 3; i++) { 00222 if (output_queues[i+3].queue_head) { 00223 queue = output_queues+i+3; 00224 break; 00225 } 00226 if (output_queues[i].queue_head) { 00227 queue = output_queues+i; 00228 break; 00229 } 00230 } 00231 00232 /* No messages to dequeue? */ 00233 if (!queue) return; 00234 00235 q = queue->queue_head; 00236 00237 /* Remove it from the queue. */ 00238 queue_unlink(queue, q); 00239 00240 /* Construct an irc message out of it. */ 00241 text = buf; 00242 remaining = sizeof(buf); 00243 queue_entry_to_text(q, text, &remaining); 00244 00245 /* Now we're done with q, so free anything we need to free and store it 00246 * in the unused queue. */ 00247 queue_entry_cleanup(q); 00248 queue_append(&unused_queue, q); 00249 00250 /* Make sure last 2 chars are \r\n and there's a space left for \0. */ 00251 if (remaining < 3) remaining = 3; 00252 len = sizeof(buf) - remaining; 00253 buf[len++] = '\r'; 00254 buf[len++] = '\n'; 00255 buf[len] = 0; 00256 00257 do_output(buf, len); 00258 }
int printserv | ( | int | priority, | |
const char * | format, | |||
... | ||||
) |
Definition at line 55 of file output.c.
References do_output(), egg_mvsprintf(), queue_server(), server_config, SERVER_NEXT, and SERVER_NOQUEUE.
00056 { 00057 char buf[1024], *ptr; 00058 int len; 00059 va_list args; 00060 00061 va_start(args, format); 00062 ptr = egg_mvsprintf(buf, sizeof(buf), &len, format, args); 00063 va_end(args); 00064 00065 if (server_config.max_line_len != -1 && len > server_config.max_line_len) len = server_config.max_line_len; 00066 00067 if (len < 2 || ptr[len-1] != '\n') { 00068 ptr[len++] = '\r'; 00069 ptr[len++] = '\n'; 00070 } 00071 ptr[len] = 0; 00072 00073 if ((priority & (~SERVER_NEXT)) == SERVER_NOQUEUE) { 00074 do_output(ptr, len); 00075 } 00076 else { 00077 queue_server(priority, ptr, len); 00078 } 00079 00080 if (ptr != buf) free(ptr); 00081 return(len); 00082 }
void queue_append | ( | queue_t * | queue, | |
queue_entry_t * | q | |||
) |
Definition at line 103 of file output.c.
References queue_t::len, queue_entry::next, NULL, queue_entry::prev, queue_t::queue_head, and queue_t::queue_tail.
00104 { 00105 q->next = NULL; 00106 q->prev = queue->queue_tail; 00107 if (queue->queue_tail) queue->queue_tail->next = q; 00108 else queue->queue_head = q; 00109 queue->queue_tail = q; 00110 00111 queue->len++; 00112 }
void queue_entry_cleanup | ( | queue_entry_t * | q | ) |
Definition at line 142 of file output.c.
References irc_msg::args, irc_msg::cmd, queue_entry::msg, irc_msg::nargs, and irc_msg::prefix.
00143 { 00144 irc_msg_t *msg; 00145 int i; 00146 00147 msg = &q->msg; 00148 if (msg->prefix) free(msg->prefix); 00149 if (msg->cmd) free(msg->cmd); 00150 00151 for (i = 0; i < msg->nargs; i++) { 00152 free(msg->args[i]); 00153 } 00154 memset(msg, 0, sizeof(*msg)); 00155 }
void queue_entry_from_text | ( | queue_entry_t * | q, | |
char * | text | |||
) |
Definition at line 125 of file output.c.
References irc_msg::args, irc_msg::cmd, irc_msg_parse(), queue_entry::msg, irc_msg::nargs, and irc_msg::prefix.
00126 { 00127 irc_msg_t *msg; 00128 int i; 00129 00130 /* Parse the irc message. */ 00131 msg = &q->msg; 00132 irc_msg_parse(text, msg); 00133 00134 /* Copy each item ('text' param belongs to caller). */ 00135 if (msg->prefix) msg->prefix = strdup(msg->prefix); 00136 if (msg->cmd) msg->cmd = strdup(msg->cmd); 00137 for (i = 0; i < msg->nargs; i++) { 00138 msg->args[i] = strdup(msg->args[i]); 00139 } 00140 }
void queue_entry_to_text | ( | queue_entry_t * | q, | |
char * | text, | |||
int * | remaining | |||
) |
Definition at line 157 of file output.c.
References irc_msg::args, irc_msg::cmd, egg_append_static_str(), queue_entry::msg, irc_msg::nargs, and irc_msg::prefix.
00158 { 00159 irc_msg_t *msg; 00160 int i; 00161 00162 msg = &q->msg; 00163 if (msg->prefix) { 00164 egg_append_static_str(&text, remaining, msg->prefix); 00165 egg_append_static_str(&text, remaining, " "); 00166 } 00167 if (msg->cmd) { 00168 egg_append_static_str(&text, remaining, msg->cmd); 00169 } 00170 00171 /* Add the args (except for last one). */ 00172 msg->nargs--; 00173 for (i = 0; i < msg->nargs; i++) { 00174 egg_append_static_str(&text, remaining, " "); 00175 egg_append_static_str(&text, remaining, msg->args[i]); 00176 } 00177 msg->nargs++; 00178 00179 /* If the last arg has a space in it, put a : before it. */ 00180 if (i < msg->nargs) { 00181 if (strchr(msg->args[i], ' ')) egg_append_static_str(&text, remaining, " :"); 00182 else egg_append_static_str(&text, remaining, " "); 00183 egg_append_static_str(&text, remaining, msg->args[i]); 00184 } 00185 }
queue_t* queue_get_by_priority | ( | int | priority | ) |
Definition at line 187 of file output.c.
References SERVER_NEXT, SERVER_QUICK, and SERVER_SLOW.
00188 { 00189 int qnum; 00190 00191 qnum = priority & (~SERVER_NEXT); 00192 if (qnum < SERVER_QUICK || qnum > SERVER_SLOW) qnum = SERVER_SLOW; 00193 qnum -= SERVER_QUICK; 00194 if (priority & SERVER_NEXT) qnum += 3; 00195 00196 return output_queues+qnum; 00197 }
queue_entry_t* queue_new | ( | char * | text | ) |
Definition at line 84 of file output.c.
References queue_entry_from_text, queue_t::queue_head, and queue_unlink.
00085 { 00086 queue_entry_t *q; 00087 00088 /* Either get one from the unused_queue, or allocate a new one. */ 00089 if (unused_queue.queue_head) { 00090 q = unused_queue.queue_head; 00091 queue_unlink(&unused_queue, q); 00092 } 00093 else { 00094 q = calloc(1, sizeof(*q)); 00095 } 00096 00097 /* Parse the text into the queue entry. */ 00098 queue_entry_from_text(q, text); 00099 00100 return(q); 00101 }
void queue_unlink | ( | queue_t * | queue, | |
queue_entry_t * | q | |||
) |
Definition at line 114 of file output.c.
References queue_t::len, queue_entry::next, queue_entry::prev, queue_t::queue_head, and queue_t::queue_tail.
00115 { 00116 if (q->next) q->next->prev = q->prev; 00117 else queue->queue_tail = q->prev; 00118 00119 if (q->prev) q->prev->next = q->next; 00120 else queue->queue_head = q->next; 00121 00122 queue->len--; 00123 }