]>
git.datanom.net - vcard-parser.git/blob - example/vcard-example.c
18 static void arguments_free(Arguments
* a
) {
27 static Arguments
* parse_commandline(GOptionContext
* opt_context
, gint argc
, gchar
** argv
) {
28 Arguments
* args
= g_new0(Arguments
, 1);
29 static gchar
* uid
= NULL
;
30 static gchar
* pwd
= NULL
;
31 static gchar
* url
= NULL
;
32 static gboolean debug
= FALSE
;
35 static GOptionEntry opt_entries
[] = {
36 { "username", 'u', 0, G_OPTION_ARG_STRING
, &uid
, "Username for the account", "U"},
37 { "password", 'p', 0, G_OPTION_ARG_STRING
, &pwd
, "Password for the account", "P"},
38 { "url", 'l', 0, G_OPTION_ARG_STRING
, &url
, "URL to the server", "<http|https>://foo.bar[/collection]"},
39 { "debug", 'd', 0, G_OPTION_ARG_NONE
, &debug
, "Enable debug mode", NULL
},
43 g_option_context_add_main_entries (opt_context
, opt_entries
, NULL
);
44 if (!g_option_context_parse(opt_context
, &argc
, &argv
, &error
)) {
45 g_printerr ("Error parsing options: %s\n", error
->message
);
53 g_printerr("Missing username and/or url\n");
77 int main(int argc
, char *argv
[]) {
78 GOptionContext
* opt_context
= g_option_context_new(NULL
);
80 Arguments
* args
= parse_commandline(opt_context
, argc
, argv
);
85 for (args = 1; args < argc; args++) {
86 g_file_get_contents(argv[args], &buffer, NULL, &err);
89 fprintf(stderr, "%s\n", err->message);
94 GSList* list = VCard_new_from_text(buffer, VCARD_VERSION_DETECT, FALSE);
99 VCard* vc = (VCard*) tmp->data;
100 gchar* state = VCard_get_state(vc);
101 if (g_strcmp0("OK", state) != 0)
102 fprintf(stderr, "%s\n", state);
105 g_print("Search property ADR in vCard\n");
106 GSList* prop = VCard_get_property(vc, "ADR");
107 for (GSList* iter = prop; iter; iter = g_slist_next(iter)) {
108 gchar* s = (gchar*) iter->data;
115 VCard_print_list(list);
117 VCard_list_free(list);
121 CarddavData
* data
= g_new0(CarddavData
, 1);
122 data
->debug
= args
->debug
;
123 data
->url
= g_strdup(args
->url
);
124 data
->user
= g_strdup(args
->uid
);
125 data
->pwd
= g_strdup(args
->pwd
);
127 arguments_free(args
);
129 GString
* buf
= g_string_new(NULL
);
130 if (curl_get_options(data
, buf
)) {
131 g_print("ERROR\n%s\n", buf
->str
);
133 g_print("OK\nDisplayname: %s\nMKCOL support: %s\n", data
->displayname
, data
->mkcol
? "True" : "False");
135 g_string_free(buf
, TRUE
);
136 gboolean res
= curl_get_resource_type(data
);
138 g_printerr("Unautorized\n");
140 g_print("CollectionType: %s\n", get_resource_type_name(data
->type
));
142 curl_free_CarddavData(data
);
144 gchar
* help
= g_option_context_get_help(opt_context
, TRUE
, NULL
);
145 g_print("%s\n", help
);
148 g_option_context_free(opt_context
);
This page took 0.255811 seconds and 6 git commands to generate.