forked from dajobe/flickcurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickcurl.c
6076 lines (4929 loc) · 159 KB
/
flickcurl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: c; c-basic-offset: 2 -*-
*
* flickcurl utility - Invoke the Flickcurl library
*
* Copyright (C) 2007-2012, David Beckett http://www.dajobe.org/
*
* This file is licensed under the following three licenses as alternatives:
* 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
* 2. GNU General Public License (GPL) V2 or any newer version
* 3. Apache License, V2.0 or any newer version
*
* You may not use this file except in compliance with at least one of
* the above three licenses.
*
* See LICENSE.html or LICENSE.txt at the top of this package for the
* complete terms and further detail along with the license texts for
* the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
*
*
* USAGE: flickcurl [OPTIONS] flickr-api-command args...
*
* ~/.flickcurl.conf should contain the authentication details in the form:
* [flickr]
* oauth_token=1234567-8901234567890123
* oauth_token_secret=fedcba9876543210
* oauth_client_key=0123456789abcdef0123456789abcdef
* oauth_client_secret=fedcba9876543210
*
* If the old Flickr auth is used the values will be:
* api_key=0123456789abcdef0123456789abcdef
* auth_token=1234567-8901234567890123
* secret=fedcba9876543210
*
* To authenticate from a FROB - to generate an auth_token from a FROB use:
* flickcurl -a FROB
* FROB like 123-456-789
* which will write a new ~/.flickcurl.conf with the auth_token received
*
* API calls are invoked like:
*
* flickcurl test.echo KEY VALUE
* This method does not require authentication.
* Echoes back the KEY and VALUE received - an API test.
*
* flickcurl photo.getinfo PHOTO-ID
* PHOTO-ID like 123456789
* This method does not require authentication.
* -- http://www.flickr.com/services/api/flickr.photos.getInfo.html
* Gets information about a photo including its tags
*
* See the help message for full list of supported Flickr API Calls.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
/* many places for getopt */
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
#include <flickcurl_getopt.h>
#endif
#include <flickcurl.h>
#include <curl/curl.h>
#ifdef NEED_OPTIND_DECLARATION
extern int optind;
extern char *optarg;
#endif
static int verbose = 1;
static const char* program;
static FILE* output_fh;
static const char *output_filename = "<stdout>";
static const char* config_filename = ".flickcurl.conf";
static const char* config_section = "flickr";
char config_path[1024];
static const char*
my_basename(const char *name)
{
char *p;
if((p = strrchr(name, '/')))
name = p+1;
else if((p = strrchr(name, '\\')))
name = p+1;
return name;
}
static void
my_message_handler(void *user_data, const char *message)
{
fprintf(stderr, "%s: ERROR: %s\n", program, message);
}
#ifdef HAVE_GETOPT_LONG
#define HELP_TEXT(short, long, description) " -" short ", --" long " " description
#define HELP_TEXT_LONG(long, description) " --" long " " description
#define HELP_ARG(short, long) "--" #long
#define HELP_PAD "\n "
#else
#define HELP_TEXT(short, long, description) " -" short " " description
#define HELP_TEXT_LONG(long, description)
#define HELP_ARG(short, long) "-" #short
#define HELP_PAD "\n "
#endif
#ifdef HAVE_GETOPT_LONG
/* + makes GNU getopt_long() never permute the arguments */
#define GETOPT_STRING "+a:d:ho:qvV"
#else
#define GETOPT_STRING "a:d:ho:qvV"
#endif
#ifdef FLICKCURL_MAINTAINER
#define GETOPT_STRING_MORE "m:"
#else
#define GETOPT_STRING_MORE
#endif
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] =
{
/* name, has_arg, flag, val */
{"auth", 1, 0, 'a'},
{"delay", 1, 0, 'd'},
{"help", 0, 0, 'h'},
#ifdef FLICKCURL_MAINTAINER
{"maintainer", 1, 0, 'm'},
#endif
{"output", 0, 0, 'o'},
{"quiet", 0, 0, 'q'},
{"version", 0, 0, 'v'},
{"verbose", 0, 0, 'V'},
{NULL, 0, 0, 0}
};
#endif
typedef int (*command_handler)(flickcurl* fc, int argc, char *argv[]);
static int
command_test_echo(flickcurl* fc, int argc, char *argv[])
{
return flickcurl_test_echo(fc, argv[1], argv[2]);
}
static int
command_test_login(flickcurl* fc, int argc, char *argv[])
{
char* username;
username = flickcurl_test_login(fc);
if(username) {
fprintf(stdout, "%s: Returned username '%s'\n", program, username);
free(username);
}
return (username == NULL);
}
static int
command_test_null(flickcurl* fc, int argc, char *argv[])
{
return flickcurl_test_null(fc);
}
static int
command_people_findByEmail(flickcurl* fc, int argc, char *argv[])
{
char* nsid = NULL;
char* email = argv[1];
nsid = flickcurl_people_findByEmail(fc, email);
if(nsid)
fprintf(stdout, "%s: NSID %s for user email %s\n",
program, nsid, email);
return (nsid == NULL);
}
static int
command_people_findByUsername(flickcurl* fc, int argc, char *argv[])
{
char* nsid = NULL;
char* user_name = argv[1];
nsid = flickcurl_people_findByUsername(fc, user_name);
if(nsid)
fprintf(stdout, "%s: NSID %s for username %s\n",
program, nsid, user_name);
return (nsid == NULL);
}
static void
command_print_person(flickcurl_person* person)
{
int i;
fprintf(stdout, "Found person with ID %s\n", person->nsid);
for(i = (int)PERSON_FIELD_FIRST; i <= (int)PERSON_FIELD_LAST; i++) {
flickcurl_person_field_type field = (flickcurl_person_field_type)i;
flickcurl_field_value_type datatype = person->fields[field].type;
if(datatype == VALUE_TYPE_NONE)
continue;
fprintf(stdout, "field %s (%d) with %s value: '%s' / %d\n",
flickcurl_get_person_field_label(field), field,
flickcurl_get_field_value_type_label(datatype),
person->fields[field].string, person->fields[field].integer);
}
}
static int
command_people_getInfo(flickcurl* fc, int argc, char *argv[])
{
flickcurl_person* person;
person = flickcurl_people_getInfo(fc, argv[1]);
if(!person)
return 1;
command_print_person(person);
flickcurl_free_person(person);
return 0;
}
static void
command_print_tags(flickcurl_tag** tags, const char* label, const char* value)
{
int i;
if(!tags)
return;
if(label)
fprintf(stdout, "%s: %s %s tags\n", program, label,
(value ? value : "(none)"));
else
fprintf(stdout, "tags:\n");
for(i = 0; tags[i]; i++) {
flickcurl_tag* tag = tags[i];
fprintf(stdout,
"%d) %s tag: id %s author ID %s name %s raw '%s' cooked '%s' count %d\n",
i, (tag->machine_tag ? "machine" : "regular"),
tag->id, tag->author,
(tag->authorname ? tag->authorname : "(Unknown)"),
tag->raw, tag->cooked, tag->count);
}
}
static int
command_print_location(flickcurl_location* location)
{
const char* accuracy_label;
accuracy_label = flickcurl_get_location_accuracy_label(location->accuracy);
if(accuracy_label)
fprintf(stdout, "latitude %f longitude %f accuracy %s(%d)\n",
location->latitude, location->longitude,
accuracy_label, location->accuracy);
else
fprintf(stdout, "latitude %f longitude %f accuracy unknown\n",
location->latitude, location->longitude);
return 0;
}
static void
command_print_shape(flickcurl_shapedata* shape)
{
fprintf(stdout,
"created %d alpha %2.2f #points %d #edges %d\n"
" is donuthole: %d has donuthole: %d\n",
shape->created, shape->alpha, shape->points, shape->edges,
shape->is_donuthole, shape->has_donuthole);
if(shape->data_length > 0) {
int s;
#define MAX_XML 70
s = (shape->data_length > MAX_XML ? MAX_XML : shape->data_length);
fprintf(stdout, " Shapedata (%d bytes):\n ",
(int)shape->data_length);
fwrite(shape->data, 1, s, stdout);
fputs("...\n", stdout);
}
if(shape->file_urls_count > 0) {
int j;
fprintf(stdout, " Shapefile URLs: %d\n", shape->file_urls_count);
for(j = 0; j < shape->file_urls_count; j++) {
fprintf(stdout," URL %d: %s\n", j, shape->file_urls[j]);
}
}
}
static void
command_print_place(flickcurl_place* place,
const char* label, const char* value,
int print_locality)
{
int i;
if(label)
fprintf(stdout, "%s: %s %s places\n", program, label,
(value ? value : "(none)"));
if(print_locality && place->type != FLICKCURL_PLACE_LOCATION)
fprintf(stdout, " Type %s (%d)\n",
flickcurl_get_place_type_label(place->type), (int)place->type);
if(place->location.accuracy != 0) {
fputs(" Location: ", stdout);
command_print_location(&place->location);
}
if(place->timezone)
fprintf(stdout, " Timezone: %s\n", place->timezone);
if(place->shape)
command_print_shape(place->shape);
if(place->count >0)
fprintf(stdout, " Photos at Place: %d\n", place->count);
for(i = (int)0; i <= (int)FLICKCURL_PLACE_LAST; i++) {
char* name = place->names[i];
char* id = place->ids[i];
char* url = place->urls[i];
char* woe_id = place->woe_ids[i];
if(!name && !id && !url && !woe_id)
continue;
fprintf(stdout, " %d) place %s:", i,
flickcurl_get_place_type_label((flickcurl_place_type)i));
if(name)
fprintf(stdout," name '%s'", name);
if(id)
fprintf(stdout," id %s", id);
if(woe_id)
fprintf(stdout," woeid %s", woe_id);
if(url)
fprintf(stdout," url '%s'", url);
fputc('\n', stdout);
}
}
static void
command_print_video(flickcurl_video* v)
{
fprintf(stdout,
"video: ready %d failed %d pending %d duration %d width %d height %d\n",
v->ready, v->failed, v->pending, v->duration,
v->width, v->height);
}
static void
command_print_notes(flickcurl_note** notes, const char* label,
const char* value)
{
int i;
if(!notes)
return;
if(label)
fprintf(stdout, "%s: %s %s notes\n", program, label,
(value ? value : "(none)"));
else
fprintf(stdout, "notes:\n");
for(i = 0; notes[i]; i++) {
flickcurl_note* note = notes[i];
fprintf(stdout,
"%d) id %d note: author ID %s name %s x %d y %d w %d h %d text '%s'\n",
i, note->id,
note->author, (note->authorname ? note->authorname : "(Unknown)"),
note->x, note->y, note->w, note->h,
note->text);
}
}
static void
command_print_photo(flickcurl_photo* photo)
{
int i;
fprintf(stdout, "%s with URI %s ID %s and %d tags\n",
photo->media_type,
(photo->uri ? photo->uri : "(Unknown)"),
photo->id, photo->tags_count);
for(i = 0; i <= PHOTO_FIELD_LAST; i++) {
flickcurl_photo_field_type field = (flickcurl_photo_field_type)i;
flickcurl_field_value_type datatype = photo->fields[field].type;
if(datatype == VALUE_TYPE_NONE)
continue;
fprintf(stdout, " field %s (%d) with %s value: '%s' / %d\n",
flickcurl_get_photo_field_label(field), field,
flickcurl_get_field_value_type_label(datatype),
photo->fields[field].string, photo->fields[field].integer);
}
command_print_tags(photo->tags, NULL, NULL);
if(photo->notes)
command_print_notes(photo->notes, NULL, NULL);
if(photo->place)
command_print_place(photo->place, NULL, NULL, 1);
if(photo->video)
command_print_video(photo->video);
}
static int
command_photos_getInfo(flickcurl* fc, int argc, char *argv[])
{
flickcurl_photo* photo;
photo = flickcurl_photos_getInfo(fc, argv[1]);
if(photo) {
fprintf(stdout, "%s: ", program);
command_print_photo(photo);
flickcurl_free_photo(photo);
}
return (photo == NULL);
}
static int
command_photos_licenses_getInfo(flickcurl* fc, int argc, char *argv[])
{
flickcurl_license** licenses;
int i;
licenses = flickcurl_photos_licenses_getInfo(fc);
if(licenses) {
if(verbose)
fprintf(stdout, "%s: Found licenses\n", program);
for(i = 0; licenses[i]; i++) {
flickcurl_license* license = licenses[i];
fprintf(stdout, "%d) license: id %d name '%s' url %s\n",
i, license->id, license->name,
license->url ? license->url : "(none)");
}
}
return (licenses == NULL);
}
static int
command_urls_lookupUser(flickcurl* fc, int argc, char *argv[])
{
char* nsid = NULL;
char* url = argv[1];
nsid = flickcurl_urls_lookupUser(fc, url);
if(nsid)
fprintf(stdout, "%s: NSID %s for user profile/photo URL %s\n",
program, nsid, url);
return (nsid != NULL);
}
static void
command_contexts_print(FILE* fh, flickcurl_context** contexts)
{
flickcurl_context* context;
int i;
for(i = 0; (context = contexts[i]); i++) {
const char* label = flickcurl_get_context_type_field_label(context->type);
fprintf(fh, "%d) context type '%s' id %s secret %s server %d farm %d\n title: %s\n url: %s\n thumb: %s\n",
i, label,
context->id,
(context->secret ? context->secret : "NULL"),
context->server, context->farm,
(context->title ? context->title : "NULL"),
(context->url ? context->url : "NULL"),
(context->thumb ? context->thumb : "NULL")
);
}
}
static int
command_groups_pools_getContext(flickcurl* fc, int argc, char *argv[])
{
flickcurl_context** contexts;
contexts = flickcurl_groups_pools_getContext(fc, argv[1], argv[2]);
if(!contexts)
return 1;
if(verbose)
fprintf(stdout, "%s: Pool context of photo %s in pool %s:\n", program,
argv[1], argv[2]);
command_contexts_print(stdout, contexts);
flickcurl_free_contexts(contexts);
return 0;
}
static int
command_photos_getAllContexts(flickcurl* fc, int argc, char *argv[])
{
flickcurl_context** contexts;
contexts = flickcurl_photos_getAllContexts(fc, argv[1]);
if(!contexts)
return 1;
if(verbose)
fprintf(stdout, "%s: Photos %s all contexts:\n", program, argv[1]);
command_contexts_print(stdout, contexts);
flickcurl_free_contexts(contexts);
return 0;
}
static int
command_photos_getContext(flickcurl* fc, int argc, char *argv[])
{
flickcurl_context** contexts;
contexts = flickcurl_photos_getContext(fc, argv[1]);
if(!contexts)
return 1;
if(verbose)
fprintf(stdout, "%s: Photos %s context:\n", program, argv[1]);
command_contexts_print(stdout, contexts);
flickcurl_free_contexts(contexts);
return 0;
}
static int
command_photos_getCounts(flickcurl* fc, int argc, char *argv[])
{
char** dates_array = NULL;
char** taken_dates_array = NULL;
int** counts;
if(argv[1]) {
dates_array = flickcurl_array_split(argv[1], ',');
if(argv[2])
taken_dates_array = flickcurl_array_split(argv[2], ',');
}
counts = flickcurl_photos_getCounts(fc, (const char**)dates_array,
(const char**)taken_dates_array);
if(counts) {
int i;
for(i = 0; counts[i]; i++) {
fprintf(stdout, "%s: photocount %i: count %d fromdate %d todate %d\n",
program, i, counts[i][0], counts[i][1], counts[i][2]);
}
free(counts);
}
if(dates_array)
flickcurl_array_free(dates_array);
if(taken_dates_array)
flickcurl_array_free(taken_dates_array);
return (counts == NULL);
}
static int
command_photosets_getContext(flickcurl* fc, int argc, char *argv[])
{
flickcurl_context** contexts;
contexts = flickcurl_photosets_getContext(fc, argv[1], argv[2]);
if(!contexts)
return 1;
if(verbose)
fprintf(stdout, "%s: Photo %s in photoset %s context:\n", program,
argv[1], argv[2]);
command_contexts_print(stdout, contexts);
flickcurl_free_contexts(contexts);
return 0;
}
static int
command_auth_getFrob(flickcurl* fc, int argc, char *argv[])
{
char* frob;
frob = flickcurl_auth_getFrob(fc);
if(!frob)
return 1;
fprintf(stdout, "%s: Got frob: %s\n", program, frob);
free(frob);
return 0;
}
static int
command_auth_checkToken(flickcurl* fc, int argc, char *argv[])
{
char* perms;
perms = flickcurl_auth_checkToken(fc, argv[1]);
if(!perms)
return 1;
fprintf(stdout, "%s: Checked token %s and got perms: %s\n", program,
argv[1], perms);
free(perms);
return 0;
}
static int
command_auth_getToken(flickcurl* fc, int argc, char *argv[])
{
char* perms;
perms = flickcurl_auth_getToken(fc, argv[1]);
if(!perms)
return 1;
fprintf(stdout, "%s: Got token %s perms: %s\n", program, argv[1], perms);
free(perms);
return 0;
}
static int
command_auth_getFullToken(flickcurl* fc, int argc, char *argv[])
{
char* perms;
perms = flickcurl_auth_getFullToken(fc, argv[1]);
if(!perms)
return 1;
fprintf(stdout, "%s: Got full token %s perms: %s\n", program, argv[1], perms);
free(perms);
return 0;
}
static int
command_tags_getListPhoto(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *photo_id = argv[1];
tags = flickcurl_tags_getListPhoto(fc, photo_id);
if(!tags)
return 1;
command_print_tags(tags, "Photo ID", photo_id);
free(tags);
return 0;
}
static int
command_tags_getListUser(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *user_id = argv[1];
tags = flickcurl_tags_getListUser(fc, user_id);
if(!tags)
return 1;
command_print_tags(tags, "User ID", user_id);
free(tags);
return 0;
}
static int
command_tags_getListUserPopular(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *user_id = NULL;
int pop_count= -1;
if(argv[1]) {
user_id = argv[1];
if(argv[2])
pop_count = atoi(argv[2]);
}
tags = flickcurl_tags_getListUserPopular(fc, user_id, pop_count);
if(!tags)
return 1;
command_print_tags(tags, "User ID", user_id);
free(tags);
return 0;
}
static int
command_tags_getListUserRaw(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *tag = argv[1];
tags = flickcurl_tags_getListUserRaw(fc, tag);
if(!tags)
return 1;
command_print_tags(tags, "Tag", tag);
free(tags);
return 0;
}
static int
command_tags_getRelated(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *tag = argv[1];
tags = flickcurl_tags_getRelated(fc, tag);
if(!tags)
return 1;
command_print_tags(tags, "Related to Tag", tag);
free(tags);
return 0;
}
static int
command_urls_getGroup(flickcurl* fc, int argc, char *argv[])
{
char* nsid = NULL;
char* url = argv[1];
nsid = flickcurl_urls_getGroup(fc, url);
if(nsid)
fprintf(stdout, "%s: NSID %s for group profile/photo URL %s\n",
program, nsid, url);
return (nsid == NULL);
}
static int
command_urls_getUserPhotos(flickcurl* fc, int argc, char *argv[])
{
char* url = NULL;
char* user = argv[1];
url = flickcurl_urls_getUserPhotos(fc, user);
if(url)
fprintf(stdout, "%s: photo URL %s for user %s\n",
program, url, user);
return (url == NULL);
}
static int
command_urls_getUserProfile(flickcurl* fc, int argc, char *argv[])
{
char* url = NULL;
char* user = argv[1];
url = flickcurl_urls_getUserProfile(fc, user);
if(url)
fprintf(stdout, "%s: photo URL %s for user %s\n",
program, url, user);
return (url == NULL);
}
static int
command_urls_lookupGroup(flickcurl* fc, int argc, char *argv[])
{
char* nsid = NULL;
char* url = argv[1];
nsid = flickcurl_urls_lookupGroup(fc, url);
if(nsid)
fprintf(stdout, "%s: NSID %s for group profile/photo URL %s\n",
program, nsid, url);
return (url == NULL);
}
static int
command_tags_getHotList(flickcurl* fc, int argc, char *argv[])
{
flickcurl_tag** tags;
char *period = NULL;
int count= -1;
if(argv[1]) {
period = argv[1];
if(argv[2])
count = atoi(argv[2]);
}
tags = flickcurl_tags_getHotList(fc, period, count);
if(!tags)
return 1;
command_print_tags(tags, "Hot tags for period",
(period ? period : "day"));
free(tags);
return 0;
}
static int
command_photos_addTags(flickcurl* fc, int argc, char *argv[])
{
const char *photo_id = argv[1];
const char *tags = argv[2];
return flickcurl_photos_addTags(fc, photo_id, tags);
}
static int
command_photos_delete(flickcurl* fc, int argc, char *argv[])
{
const char *photo_id = argv[1];
return flickcurl_photos_delete(fc, photo_id);
}
static int
command_photos_removeTag(flickcurl* fc, int argc, char *argv[])
{
const char *tag_id = argv[1];
return flickcurl_photos_removeTag(fc, tag_id);
}
static int
command_photos_setTags(flickcurl* fc, int argc, char *argv[])
{
const char *photo_id = argv[1];
const char *tags = argv[2];
return flickcurl_photos_setTags(fc, photo_id, tags);
}
static int
command_reflection_getMethodInfo(flickcurl* fc, int argc, char *argv[])
{
flickcurl_method* method;
method = flickcurl_reflection_getMethodInfo(fc, argv[1]);
if(method) {
fprintf(stdout, "%s: Found method %s\n", program, method->name);
fprintf(stdout, " Needs Login? %s\n", (method->needslogin? "yes" : "no"));
fprintf(stdout, " Description: %s\n", method->description);
fprintf(stdout, " Response: '%s'\n", method->response);
fprintf(stdout, " Explanation of Response: %s\n",
method->explanation ? method->explanation : "(None)");
if(method->args_count) {
int i;
fprintf(stdout, "%s: %d argument%s:\n", program, method->args_count,
((method->args_count != 1) ? "s" : ""));
for(i = 0; method->args[i]; i++) {
flickcurl_arg* arg = method->args[i];
fprintf(stdout, "%d) argument '%s' %s description: '%s'\n",
i, arg->name, (arg->optional? "" : "(required)"),
arg->description);
}
} else
fprintf(stdout, "%s: No arguments\n", program);
flickcurl_free_method(method);
}
return (method == NULL);
}
static int
command_reflection_getMethods(flickcurl* fc, int argc, char *argv[])
{
char** methods;
methods = flickcurl_reflection_getMethods(fc);
if(methods) {
int i;
fprintf(stdout, "%s: Found methods:\n", program);
for(i = 0; methods[i]; i++)
printf("%d) %s\n", i, methods[i]);
for(i = 0; methods[i]; i++)
free(methods[i]);
free(methods);
}
return (methods == NULL);
}
static int
command_photos_comments_addComment(flickcurl* fc, int argc, char *argv[])
{
const char *photo_id = argv[1];
const char *comment_text = argv[2];
char* id;
id = flickcurl_photos_comments_addComment(fc, photo_id, comment_text);
if(id) {
fprintf(stdout,
"%s: Added comment '%s' to photo %s giving comment ID %s\n",
program, photo_id, comment_text, id);
}
return (id == NULL);
}
static int