- /* write error or fd not ready for writing */
- close(fd);
- num_clients--;
- PARA_INFO_LOG("deleting client on fd %d\n", fd);
- list_del(&sc->node);
- free(sc);
- dump_stat_client_list();
- }
-// if (num_clients)
-// PARA_DEBUG_LOG("%d client(s)\n", num_clients);
-}
-
-/**
- * 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) {
- PARA_ERROR_LOG("%s\n", "no item");
- return -E_UNKNOWN_STAT_ITEM;
- }
- FOR_EACH_STATUS_ITEM(i)
- if (!strcmp(status_item_list[i], item))
- return i;
- PARA_ERROR_LOG("invalid stat item: %s\n", item);
- 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_STATUS_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;
+ if (buf[7] != ':' || buf[5 + item_len - 1] != '\n')
+ return -E_STAT_ITEM_PARSE;
+ buf[5 + item_len - 1] = '\0';
+ if (item_num >= NUM_STAT_ITEMS)
+ PARA_WARNING_LOG("unknown status item %d: %s\n",
+ item_num, buf + 8);
+ else {
+ ret = item_handler(item_num, buf + 8);
+ if (ret < 0)
+ return ret;
+ }
+ buf += 5 + item_len;
+ len -= 5 + item_len;
+ assert(len >= 0 && buf <= item_buf + num_bytes);