- /* write error or fd not ready for writing */
- close(fd);
- del_close_on_fork_list(fd);
- num_clients--;
- PARA_INFO_LOG("deleting client on fd %d\n", fd);
- list_del(&sc->node);
- free(sc);
- dump_stat_client_list();
- }
- PARA_DEBUG_LOG("%d client(s)\n", num_clients);
-}
-
-/**
- * send empty status list
- *
- * Send to each connected client the full status item list
- * with empty values.
- */
-void dump_empty_status(void)
-{
- int i;
-
- if (!initialized)
- return;
- FOR_EACH_STAT_ITEM(i) {
- char *tmp = make_message("%s:\n", status_item_list[i]);
- stat_client_write(tmp, i);
- free(tmp);
- }
-}
-
-/**
- * check if string is a known status item.
- *
- * \param item buffer containing the text to check
- *
- * \return If \a item is a valid status item, the number of that status item is
- * returned. Otherwise, this function returns \p -E_UNKNOWN_STAT_ITEM.
- */
-int stat_item_valid(const char *item)
-{
- int i;
- if (!item || !*item)
- return -E_UNKNOWN_STAT_ITEM;
- FOR_EACH_STAT_ITEM(i)
- if (!strcmp(status_item_list[i], item))
- return i;
- return -E_UNKNOWN_STAT_ITEM;
-}
-
-/**
- * check if line starts with known status item.
- *
- * \param line buffer containing the line
- *
- * \return If the beginning of \a line matches any paraslash status item and is
- * followed by a colon, the number of that status item is returned. Otherwise,
- * this function returns \p -E_UNKNOWN_STAT_ITEM.
- */
-int stat_line_valid(const char *line)
-{
- int i;
- size_t line_len;
-
- if (!line || !*line)
- return -E_UNKNOWN_STAT_ITEM;
- line_len = strlen(line);
- FOR_EACH_STAT_ITEM(i) {
- const char *s = status_item_list[i];
- size_t item_len = strlen(s);
-
- if (line_len > item_len && line[item_len] == ':' &&
- !strncmp(line, s, item_len))
- return i;
- }
- return -E_UNKNOWN_STAT_ITEM;
-}
-
-/**
- * call a custom function for each complete line
- *
- * \param buf the buffer containing data seperated by newlines
- * \param n the number of bytes in \a buf
- * \param line_handler the custom function
- *
- * If \a line_handler is \p NULL, return number of complete lines in buf.
- * Otherwise, call \a line_handler for each complete line. The rest of the
- * buffer (last chunk containing incomplete line is moved to the beginning of
- * the buffer.
- *
- * \return If line_handler is not NULL, this function returns the number
- * of bytes not handled to \a line_handler.
- */
-unsigned for_each_line(char *buf, int n, void (*line_handler)(char *))
-{
- char *start = buf, *end;
- int i, num_lines = 0;
-
- while (start < buf + n) {
- char *next_null;
- char *next_cr;
-
- next_cr = memchr(start, '\n', buf + n - start);
- next_null = memchr(start, '\0', buf + n - start);
- if (!next_cr && !next_null)
- break;
- if (next_cr && next_null) {
- end = next_cr < next_null? next_cr : next_null;
- } else if (next_null) {
- end = next_null;
- } else
- end = next_cr;
- num_lines++;
- if (line_handler) {
- *end = '\0';
- line_handler(start);
- start = ++end;
- } else
- start = ++end;