~ubuntu-branches/ubuntu/quantal/shotwell/quantal

« back to all changes in this revision

Viewing changes to plugins/common/RESTSupport.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-02-21 13:52:58 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: package-import@ubuntu.com-20120221135258-ao9jiib5qicomq7q
Tags: upstream-0.11.92
ImportĀ upstreamĀ versionĀ 0.11.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2009-2011 Yorba Foundation
 
1
/* Copyright 2009-2012 Yorba Foundation
2
2
 *
3
3
 * This software is licensed under the GNU Lesser General Public License
4
4
 * (version 2.1 or later).  See the COPYING file in this distribution. 
5
5
 */
6
6
 
7
7
extern Soup.Message soup_form_request_new_from_multipart(string uri, Soup.Multipart multipart);
8
 
extern void qsort(void *p, size_t num, size_t size, GLib.CompareFunc func);
9
8
 
10
9
namespace Publishing.RESTSupport {
11
10
 
110
109
 
111
110
        return strcmp(arg1->key, arg2->key);
112
111
    }
 
112
    
 
113
    public static Argument[] sort(Argument[] inputArray) {
 
114
        Gee.TreeSet<Argument> sorted_args = new Gee.TreeSet<Argument>(Argument.compare);
 
115
 
 
116
        foreach (Argument arg in inputArray)
 
117
            sorted_args.add(arg);
 
118
 
 
119
        return sorted_args.to_array();
 
120
    }
113
121
}
114
122
 
115
123
public class Transaction {
196
204
                get_endpoint_url());
197
205
    }
198
206
 
199
 
    protected Argument[] get_arguments() {
 
207
    public Argument[] get_arguments() {
200
208
        return arguments;
201
209
    }
202
210
    
203
 
    protected Argument[] get_sorted_arguments() {
204
 
        Argument[] sorted_array = new Argument[0];
205
 
 
206
 
        foreach (Argument arg in arguments)
207
 
            sorted_array += arg;
208
 
 
209
 
        qsort(sorted_array, sorted_array.length, sizeof(Argument),
210
 
            (CompareFunc) Argument.compare);
211
 
 
212
 
        return sorted_array;
 
211
    public Argument[] get_sorted_arguments() {
 
212
        return Argument.sort(get_arguments());
213
213
    }
214
214
    
215
215
    protected void set_is_executed(bool is_executed) {
233
233
            throw err;
234
234
     }
235
235
 
236
 
    protected HttpMethod get_method() {
 
236
    public HttpMethod get_method() {
237
237
        return HttpMethod.from_string(message.method);
238
238
    }
239
239
 
299
299
 
300
300
        // concatenate the REST arguments array into an HTTP formdata string
301
301
        string formdata_string = "";
302
 
        foreach (Argument arg in arguments) {
303
 
            formdata_string = formdata_string + ("%s=%s&".printf(Soup.URI.encode(arg.key, "&"),
304
 
                Soup.URI.encode(arg.value, "&+")));
 
302
        for (int i = 0; i < arguments.length; i++) {
 
303
            formdata_string += ("%s=%s".printf(arguments[i].key, arguments[i].value));
 
304
            if (i < arguments.length - 1)
 
305
                formdata_string += "&";
305
306
        }
306
 
 
 
307
        
307
308
        // for GET requests with arguments, append the formdata string to the endpoint url after a
308
309
        // query divider ('?') -- but make sure to save the old (caller-specified) endpoint URL
309
310
        // and restore it after the GET so that the underlying Soup message remains consistent
313
314
            old_url = message.get_uri().to_string(false);
314
315
            url_with_query = get_endpoint_url() + "?" + formdata_string;
315
316
            message.set_uri(new Soup.URI(url_with_query));
 
317
        } else {
 
318
            message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY,
 
319
                formdata_string.data);
316
320
        }
317
321
 
318
 
        message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY,
319
 
            formdata_string.data);
320
322
        is_executed = true;
 
323
 
321
324
        try {
 
325
            debug("sending message to URI = '%s'", message.get_uri().to_string(false));
322
326
            send();
323
327
        } finally {
324
328
            // if old_url is non-null, then restore it