we don't really need to build src/liblj/ as library; and we don't need to write each...
[k8lowj.git] / src / liblj / consolecommand.c
blobe3537b93ff19bec0cf07c1260bb79989520e692e
1 /* liblivejournal - a client library for LiveJournal.
2 * Copyright (C) 2003-2004 Evan Martin <martine@danga.com>
3 */
5 #include <glib.h>
7 #include "liblj/consolecommand.h"
10 static void parse_result (LJVerb *verb) {
11 int i;
12 char *linetext, *linetype;
13 LJConsoleCommand *cc = (LJConsoleCommand *)verb;
15 cc->linecount = lj_result_get_int(verb->result, "cmd_line_count");
16 cc->lines = g_new0(LJConsoleLine, cc->linecount);
17 for (i = 0; i < cc->linecount; i++) {
18 linetext = lj_result_getf(verb->result, "cmd_line_%d", i+1);
19 linetype = lj_result_getf(verb->result, "cmd_line_%d_type", i+1);
20 if (linetype == NULL) linetype = "info";
22 if (g_ascii_strcasecmp(linetype, "error") == 0) cc->lines[i].type = LJ_CONSOLE_LINE_TYPE_ERROR;
23 else if (g_ascii_strcasecmp(linetype, "info") == 0) cc->lines[i].type = LJ_CONSOLE_LINE_TYPE_INFO;
24 else cc->lines[i].type = LJ_CONSOLE_LINE_TYPE_INFO;
26 if (linetext) cc->lines[i].text = g_strdup(linetext);
31 LJConsoleCommand *lj_consolecommand_new (LJUser *user, const char *command) {
32 LJConsoleCommand *consolecommand = g_new0(LJConsoleCommand, 1);
33 LJVerb *verb = (LJVerb *)consolecommand;
35 lj_verb_init(verb, user, "consolecommand", FALSE, parse_result);
36 lj_request_add(verb->request, "command", command);
38 return consolecommand;
42 void lj_consolecommand_free (LJConsoleCommand *cc) {
43 int i;
45 lj_verb_free_contents((LJVerb*)cc);
46 if (cc->lines) {
47 for (i = 0; i < cc->linecount; i++) g_free(cc->lines[i].text);
48 g_free(cc->lines);
50 g_free(cc);