~ubuntu-branches/debian/sid/flickcurl/sid

« back to all changes in this revision

Viewing changes to src/favorites-api.c

  • Committer: Package Import Robot
  • Author(s): Kumar Appaiah
  • Date: 2013-05-20 21:15:09 UTC
  • mfrom: (1.4.1) (15.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130520211509-e701o5dlwa04aqiw
Tags: 1.24-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * favorites-api.c - Flickr flickr.favorites.* API calls
4
4
 *
5
 
 * Copyright (C) 2008, David Beckett http://www.dajobe.org/
 
5
 * Copyright (C) 2008-2012, David Beckett http://www.dajobe.org/
6
6
 * 
7
7
 * This file is licensed under the following three licenses as alternatives:
8
8
 *   1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
56
56
int
57
57
flickcurl_favorites_add(flickcurl* fc, const char* photo_id)
58
58
{
59
 
  const char* parameters[8][2];
60
 
  int count = 0;
61
59
  xmlDocPtr doc = NULL;
62
60
  xmlXPathContextPtr xpathCtx = NULL; 
63
61
  
 
62
  flickcurl_init_params(fc);
 
63
 
64
64
  if(!photo_id)
65
65
    return 1;
66
66
 
67
 
  parameters[count][0]  = "photo_id";
68
 
  parameters[count++][1]= photo_id;
69
 
 
70
 
  parameters[count][0]  = NULL;
71
 
 
72
 
  if(flickcurl_prepare(fc, "flickr.favorites.add", parameters, count))
 
67
  flickcurl_add_param(fc, "photo_id", photo_id);
 
68
 
 
69
  flickcurl_end_params(fc);
 
70
 
 
71
  if(flickcurl_prepare(fc, "flickr.favorites.add"))
73
72
    goto tidy;
74
73
 
75
74
  flickcurl_set_write(fc, 1);
117
116
                               int num_next,
118
117
                               const char* extras)
119
118
{
120
 
  const char* parameters[12][2];
121
 
  int count = 0;
122
119
  xmlDocPtr doc = NULL;
123
120
  xmlXPathContextPtr xpathCtx = NULL; 
124
121
  flickcurl_photos_list** photos_lists = NULL;
126
123
  char num_next_str[10];
127
124
  int i;
128
125
 
 
126
  flickcurl_init_params(fc);
 
127
 
129
128
  if(!photo_id || !user_id)
130
129
    return NULL;
131
130
 
132
 
  parameters[count][0]  = "photo_id";
133
 
  parameters[count++][1]= photo_id;
134
 
  parameters[count][0]  = "user_id";
135
 
  parameters[count++][1]= user_id;
 
131
  flickcurl_add_param(fc, "photo_id", photo_id);
 
132
  flickcurl_add_param(fc, "user_id", user_id);
136
133
  if(num_prev >= 0) {
137
134
    sprintf(num_prev_str, "%d", num_prev);
138
 
    parameters[count][0]  = "num_prev";
139
 
    parameters[count++][1]= num_prev_str;
 
135
    flickcurl_add_param(fc, "num_prev", num_prev_str);
140
136
  }
141
137
  if(num_next >= 0) {
142
138
    sprintf(num_next_str, "%d", num_next);
143
 
    parameters[count][0]  = "num_next";
144
 
    parameters[count++][1]= num_next_str;
 
139
    flickcurl_add_param(fc, "num_next", num_next_str);
145
140
  }
146
141
  /* this is the only standard photos response parameter supported 
147
142
   * so using flickcurl_append_photos_list_params() is not really needed
148
143
   */
149
144
  if(extras) {
150
 
    parameters[count][0]  = "extras";
151
 
    parameters[count++][1]= extras;
 
145
    flickcurl_add_param(fc, "extras", extras);
152
146
  }
153
147
 
154
 
  parameters[count][0]  = NULL;
 
148
  flickcurl_end_params(fc);
155
149
 
156
 
  if(flickcurl_prepare(fc, "flickr.favorites.getContext", parameters, count))
 
150
  if(flickcurl_prepare(fc, "flickr.favorites.getContext"))
157
151
    goto tidy;
158
152
 
159
153
  doc = flickcurl_invoke(fc);
169
163
  }
170
164
 
171
165
  /* 3 lists of photo lists: prev, next and NULL to end the list */
172
 
  photos_lists = calloc(sizeof(flickcurl_photos_list*), 3);
 
166
  photos_lists = (flickcurl_photos_list**)calloc(sizeof(flickcurl_photos_list*), 3);
173
167
 
174
168
  /* Decode the prev and next into photo lists */
175
169
  for(i = 0; i < 2; i++) {
176
170
    const xmlChar* xpathExpr = (i == 0) ? (const xmlChar*)"/rsp/prevphoto" : (const xmlChar*)"/rsp/nextphoto";
177
 
    flickcurl_photos_list* photos_list = photos_lists[i];
 
171
    flickcurl_photos_list* photos_list;
178
172
    xmlXPathObjectPtr xpathObj = NULL;
179
173
 
180
174
    xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
213
207
  if(xpathCtx)
214
208
    xmlXPathFreeContext(xpathCtx);
215
209
 
216
 
  if(fc->failed)
 
210
  if(fc->failed) {
 
211
    if(photos_lists)
 
212
      free(photos_lists);
217
213
    photos_lists = NULL;
 
214
  }
218
215
 
219
216
  return photos_lists;
220
217
}
245
242
flickcurl_favorites_getList_params(flickcurl* fc, const char* user_id,
246
243
                                   flickcurl_photos_list_params* list_params)
247
244
{
248
 
  const char* parameters[12][2];
249
 
  int count = 0;
250
245
  flickcurl_photos_list* photos_list = NULL;
251
246
  const char* format = NULL;
252
247
   
 
248
  flickcurl_init_params(fc);
 
249
 
253
250
  /* API parameters */
254
251
  if(user_id) {
255
 
    parameters[count][0]  = "user_id";
256
 
    parameters[count++][1]= user_id;
 
252
    flickcurl_add_param(fc, "user_id", user_id);
257
253
  }
258
254
  /* Photos List parameters */
259
 
  flickcurl_append_photos_list_params(list_params, parameters, &count, &format);
 
255
  flickcurl_append_photos_list_params(fc, list_params, &format);
260
256
  
261
 
  parameters[count][0]  = NULL;
 
257
  flickcurl_end_params(fc);
262
258
 
263
 
  if(flickcurl_prepare(fc, "flickr.favorites.getList", parameters, count))
 
259
  if(flickcurl_prepare(fc, "flickr.favorites.getList"))
264
260
    goto tidy;
265
261
 
266
262
  photos_list = flickcurl_invoke_photos_list(fc,
338
334
flickcurl_favorites_getPublicList_params(flickcurl* fc, const char* user_id,
339
335
                                         flickcurl_photos_list_params* list_params)
340
336
{
341
 
  const char* parameters[13][2];
342
 
  int count = 0;
343
337
  flickcurl_photos_list* photos_list = NULL;
344
338
  const char* format = NULL;
345
339
  
 
340
  flickcurl_init_params(fc);
 
341
 
346
342
  if(!user_id)
347
343
    return NULL;
348
344
 
349
345
  /* API parameters */
350
 
  parameters[count][0]  = "user_id";
351
 
  parameters[count++][1]= user_id;
 
346
  flickcurl_add_param(fc, "user_id", user_id);
352
347
 
353
348
  /* Photos List parameters */
354
 
  flickcurl_append_photos_list_params(list_params, parameters, &count, &format);
355
 
 
356
 
  parameters[count][0]  = NULL;
357
 
 
358
 
  if(flickcurl_prepare(fc, "flickr.favorites.getPublicList", parameters, count))
 
349
  flickcurl_append_photos_list_params(fc, list_params, &format);
 
350
 
 
351
  flickcurl_end_params(fc);
 
352
 
 
353
  if(flickcurl_prepare(fc, "flickr.favorites.getPublicList"))
359
354
    goto tidy;
360
355
 
361
356
  photos_list = flickcurl_invoke_photos_list(fc,
432
427
int
433
428
flickcurl_favorites_remove(flickcurl* fc, const char* photo_id)
434
429
{
435
 
  const char* parameters[8][2];
436
 
  int count = 0;
437
430
  xmlDocPtr doc = NULL;
438
431
  xmlXPathContextPtr xpathCtx = NULL; 
439
432
  
 
433
  flickcurl_init_params(fc);
 
434
 
440
435
  if(!photo_id)
441
436
    return 1;
442
437
 
443
 
  parameters[count][0]  = "photo_id";
444
 
  parameters[count++][1]= photo_id;
445
 
 
446
 
  parameters[count][0]  = NULL;
447
 
 
448
 
  if(flickcurl_prepare(fc, "flickr.favorites.remove", parameters, count))
 
438
  flickcurl_add_param(fc, "photo_id", photo_id);
 
439
 
 
440
  flickcurl_end_params(fc);
 
441
 
 
442
  if(flickcurl_prepare(fc, "flickr.favorites.remove"))
449
443
    goto tidy;
450
444
 
451
445
  flickcurl_set_write(fc, 1);