static size_t story_on_data(gchar *data, size_t len, gpointer arg) { struct story *story = arg; gchar *title, *url, *num_comments, *points, *time; if (!(title = strstr(data, "\"title\":\""))) { g_warning("couldn't find item title"); return 0; } if (!(url = strstr(data, "\"url\":\""))) { g_warning("couldn't find item url"); return 0; } if (!(num_comments = strstr(data, "\"descendants\":"))) { g_warning("couldn't find number of comments"); return 0; } if (!(points = strstr(data, "\"score\":"))) { g_warning("couldn't find item points"); return 0; } if (!(time = strstr(data, "\"time\":"))) { g_warning("couldn't find item time"); return 0; } title += 9; extract_quote(title); story->title = title; url += 7; extract_quote(url); if (story->url) g_free(story->url); story->url = g_strdup(url); story->num_comments = atoi(num_comments + 14); story->points = atoi(points + 8); story->time = atol(time + 7); update_story(story); story->title = NULL; return len; }
gint xml_get_dtd(XMLFile *file) { gchar buf[XMLBUFSIZE]; gchar *bufp = buf; if (xml_get_parenthesis(file, buf, sizeof(buf)) < 0) return -1; if ((*bufp++ == '?') && (bufp = strcasestr(bufp, "xml")) && (bufp = strcasestr(bufp + 3, "version")) && (bufp = strchr(bufp + 7, '?'))) { file->dtd = g_strdup(buf); if ((bufp = strcasestr(buf, "encoding=\""))) { bufp += 9; extract_quote(bufp, '"'); file->encoding = g_strdup(bufp); file->need_codeconv = g_strcmp0(bufp, CS_INTERNAL); } else { file->encoding = g_strdup(CS_INTERNAL); file->need_codeconv = FALSE; } } else { g_warning("Can't get XML DTD in %s", file->path); return -1; } return 0; }