/* -*- Mode: c; c-basic-offset: 2 -*- * * test.c - Flickcurl test * * Copyright (C) 2007, David Beckett http://purl.org/net/dajobe/ * * 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: triplr [OPTIONS] FLICKR-PHOTO-URI * * */ #include #include #include #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #include #include static const char* program; 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); } static void my_set_config_var_handler(void* userdata, const char* key, const char* value) { flickcurl *fc=(flickcurl *)userdata; if(!strcmp(key, "api_key")) flickcurl_set_api_key(fc, value); else if(!strcmp(key, "secret")) flickcurl_set_shared_secret(fc, value); else if(!strcmp(key, "auth_token")) flickcurl_set_auth_token(fc, value); } static const char* config_filename=".flickcurl.conf"; static const char* config_section="flickr"; int main(int argc, char *argv[]) { flickcurl *fc=NULL; int rc=0; const char* home; char config_path[1024]; program=my_basename(argv[0]); flickcurl_init(); home=getenv("HOME"); if(home) sprintf(config_path, "%s/%s", home, config_filename); else strcpy(config_path, config_filename); /* Initialise the Flickcurl library */ fc=flickcurl_new(); if(!fc) { rc=1; goto tidy; } flickcurl_set_error_handler(fc, my_message_handler, NULL); if(!access((const char*)config_path, R_OK)) { if(read_ini_config(config_path, config_section, fc, my_set_config_var_handler)) { fprintf(stderr, "%s: Failed to read config filename %s: %s\n", program, config_path, strerror(errno)); rc=1; goto tidy; } } if(1) { const char * parameters[10][2]; int count=0; xmlDocPtr doc; parameters[count][0] = "photo_id"; parameters[count++][1]= argv[1]; parameters[count][0] = "tags"; parameters[count++][1]= argv[2]; parameters[count][0] = NULL; if(flickcurl_prepare(fc, "flickr.photos.addTags", parameters, count)) goto tidy; flickcurl_set_write(fc, 1); flickcurl_set_data(fc, (void*)"", 0); doc=flickcurl_invoke(fc); } tidy: if(fc) flickcurl_free(fc); flickcurl_finish(); return(rc); }