+ GString* buf = NULL;
+ switch (args->action) {
+ case GETOPTIONS:
+ buf = g_string_new(NULL);
+ if (curl_get_options(data, buf)) {
+ g_print("ERROR\n%s\n", buf->str);
+ } else {
+ g_print("OK\nDisplayname: %s\nMKCOL support: %s\n", data->displayname, data->mkcol ? "True" : "False");
+ }
+ g_string_free(buf, TRUE);
+ break;
+
+ case GETDISPLAYNAME:
+ buf = g_string_new(NULL);
+ if (curl_get_options(data, buf)) {
+ g_print("ERROR\n%s\n", buf->str);
+ } else {
+ g_print("OK\nDisplayname: %s\n", data->displayname);
+ }
+ g_string_free(buf, TRUE);
+ break;
+
+ case GETTYPE:
+ gboolean res = curl_get_resource_type(data);
+ if (res) {
+ g_printerr("Unautorized\n");
+ } else {
+ g_print("CollectionType: %s\n", get_resource_type_name(data->type));
+ }
+ gboolean dirty = curl_collection_dirty(data);
+ g_print("Etag: %s\nCollection dirty: %s\n", data->etag, dirty ? "YES" : "NO");
+ break;
+
+ case GETOBJECTS:
+ buf = g_string_new(NULL);
+ res = curl_get_objects(data, buf);
+ g_print("Objects:\n%s\n", res ? "ERROR": buf->str);
+ g_string_free(buf, TRUE);
+ break;
+
+ case READFILE:
+ // "/home/mir/git/vcard-parser/example/mir_book.vcf"
+ FILE* file = g_fopen(args->file, "r");
+ if (file) {
+ GSList* cards = VCard_new_from_file(file, VCARD_VERSION_DETECT, TRUE);
+ fclose(file);
+ VCard_print_list(cards);
+ g_print("\n");
+ vcard_slist_property_free(cards);
+ } else {
+ g_printerr("%s: Read error\n", args->file);
+ }
+ break;
+
+ case ADDOBJECT:
+ VCard* vcard = VCard_new();
+ VCard_set_email(vcard, EMAIL_HOME, "mir@miras.org");
+ VCard_set_email(vcard, EMAIL_WORK, "mr.it@cbs.dk");
+ VCard_set_name(vcard, "Michael", "Rasmussen");
+ VCard_set_company(vcard, "No Name");
+ VCard_set_telefon(vcard, TEL_DEFAULT, "40757616");
+ VCard_set_telefon(vcard, TEL_HOME, "40757616");
+ VCard_set_address(vcard, ADDR_HOME, "Helmer Søgårds Alle 7, st.th", NULL, "Kastrup", "2770", "Denmark");
+ VCard_set_photo_image(vcard, PHOTO_JPG, hacker_jpeg);
+
+ buf = g_string_new(NULL);
+ res = curl_set_object(data, vcard, buf);
+ gchar* output;
+ if (res) {
+ output = g_strconcat("ERROR: ", buf->str, NULL);
+ } else {
+ gchar* tmp = VCard_get_etag(vcard);
+ output = g_strconcat("ETag: ", tmp, "\n", NULL);
+ g_free(tmp);
+ }
+ g_print(output);
+ g_free(output);
+ g_string_free(buf, TRUE);
+
+ // Update
+ buf = g_string_new(NULL);;
+ VCard_set_company(vcard, "Some changed Name");
+ res = curl_update_object(data, vcard, buf);
+ if (res) {
+ output = VCard_get_etag(vcard);
+ g_print("Error updating (UID:%s", output);
+ g_free(output);
+ } else {
+ gchar* tmp = VCard_get_etag(vcard);
+ output = g_strconcat("ETag: ", tmp, "\n", NULL);
+ g_free(tmp);
+ g_print(output);
+ g_free(output);
+ }
+ g_string_free(buf, TRUE);
+
+ // Delete
+ buf = g_string_new(NULL);;
+ res = curl_delete_object(data, vcard, buf);
+ if (res) {
+ output = VCard_get_etag(vcard);
+ g_print("Error updating (UID:%s", output);
+ g_free(output);
+ } else {
+ g_print(buf->str);
+ }
+ g_string_free(buf, TRUE);
+
+ VCard_free(vcard);
+ break;
+ case UPDATEOBJECT:
+ g_print("%s\n", args->vc);
+ break;