1 /* liblivejournal - a client library for LiveJournal.
2 * Copyright (C) 2003-2004 Evan Martin <martine@danga.com>
7 #include "liblj/consolecommand.h"
10 static void parse_result (LJVerb
*verb
) {
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
) {
45 lj_verb_free_contents((LJVerb
*)cc
);
47 for (i
= 0; i
< cc
->linecount
; i
++) g_free(cc
->lines
[i
].text
);