~ubuntu-branches/ubuntu/oneiric/libgdata/oneiric-backports

« back to all changes in this revision

Viewing changes to gdata/gdata-upload-stream.c

  • Committer: Package Import Robot
  • Author(s): Evan Broder
  • Date: 2011-11-15 21:59:48 UTC
  • mfrom: (4.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20111115215948-e17s889ocgu5fv4f
Tags: 0.10.1-1~oneiric1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * @stability: Unstable
24
24
 * @include: gdata/gdata-upload-stream.h
25
25
 *
26
 
 * #GDataUploadStream is a #GOutputStream subclass to allow uploading of files from GData services with authentication from a #GDataService.
 
26
 * #GDataUploadStream is a #GOutputStream subclass to allow uploading of files from GData services with authorization from a #GDataService under
 
27
 * the given #GDataAuthorizationDomain. If authorization is not required to perform the upload, a #GDataAuthorizationDomain doesn't have to be
 
28
 * specified.
27
29
 *
28
30
 * Once a #GDataUploadStream is instantiated with gdata_upload_stream_new(), the standard #GOutputStream API can be used on the stream to upload
29
31
 * the file. Network communication may not actually begin until the first call to g_output_stream_write(), so having a #GDataUploadStream around is no
59
61
 * connection will be closed immediately. i.e. #GDataUploadStream will do its best to instruct the server to cancel the upload and any associated
60
62
 * server-side changes of state.
61
63
 *
62
 
 * If the server returns an error message (for example, if the user is not correctly authenticated or doesn't have suitable permissions to upload
63
 
 * from the given URI), it will be returned as a #GDataServiceError by g_output_stream_close().
 
64
 * If the server returns an error message (for example, if the user is not correctly authenticated/authorized or doesn't have suitable permissions
 
65
 * to upload from the given URI), it will be returned as a #GDataServiceError by g_output_stream_close().
64
66
 *
65
67
 * <example>
66
68
 *      <title>Uploading from a File</title>
67
69
 *      <programlisting>
68
70
 *      GDataService *service;
 
71
 *      GDataAuthorizationDomain *domain;
69
72
 *      GCancellable *cancellable;
70
73
 *      GInputStream *input_stream;
71
74
 *      GOutputStream *upload_stream;
97
100
 *
98
101
 *      /<!-- -->* Create the upload stream *<!-- -->/
99
102
 *      service = create_my_service ();
 
103
 *      domain = get_my_authorization_domain_from_service (service);
100
104
 *      cancellable = g_cancellable_new (); /<!-- -->* cancel this to cancel the entire upload operation *<!-- -->/
101
 
 *      upload_stream = gdata_upload_stream_new (service, SOUP_METHOD_POST, upload_uri, NULL, g_file_info_get_display_name (file_info),
 
105
 *      upload_stream = gdata_upload_stream_new (service, domain, SOUP_METHOD_POST, upload_uri, NULL, g_file_info_get_display_name (file_info),
102
106
 *                                               g_file_info_get_content_type (file_info), cancellable);
103
107
 *      g_object_unref (file_info);
104
108
 *
109
113
 *      g_object_unref (upload_stream);
110
114
 *      g_object_unref (input_stream);
111
115
 *      g_object_unref (cancellable);
 
116
 *      g_object_unref (domain);
112
117
 *      g_object_unref (service);
113
118
 *
114
119
 *      static void
186
191
        gchar *method;
187
192
        gchar *upload_uri;
188
193
        GDataService *service;
 
194
        GDataAuthorizationDomain *authorization_domain;
189
195
        GDataEntry *entry;
190
196
        gchar *slug;
191
197
        gchar *content_type;
216
222
        PROP_SLUG,
217
223
        PROP_CONTENT_TYPE,
218
224
        PROP_METHOD,
219
 
        PROP_CANCELLABLE
 
225
        PROP_CANCELLABLE,
 
226
        PROP_AUTHORIZATION_DOMAIN,
220
227
};
221
228
 
222
229
G_DEFINE_TYPE (GDataUploadStream, gdata_upload_stream, G_TYPE_OUTPUT_STREAM)
244
251
        /**
245
252
         * GDataUploadStream:service:
246
253
         *
247
 
         * The service which is used to authenticate the upload, and to which the upload relates.
 
254
         * The service which is used to authorize the upload, and to which the upload relates.
248
255
         *
249
256
         * Since: 0.5.0
250
257
         **/
251
258
        g_object_class_install_property (gobject_class, PROP_SERVICE,
252
259
                                         g_param_spec_object ("service",
253
 
                                                              "Service", "The service which is used to authenticate the upload.",
 
260
                                                              "Service", "The service which is used to authorize the upload.",
254
261
                                                              GDATA_TYPE_SERVICE,
255
262
                                                              G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
256
263
 
257
264
        /**
 
265
         * GDataUploadStream:authorization-domain:
 
266
         *
 
267
         * The authorization domain for the upload, against which the #GDataService:authorizer for the #GDataDownloadStream:service should be
 
268
         * authorized. This may be %NULL if authorization is not needed for the upload.
 
269
         *
 
270
         * Since: 0.9.0
 
271
         */
 
272
        g_object_class_install_property (gobject_class, PROP_AUTHORIZATION_DOMAIN,
 
273
                                         g_param_spec_object ("authorization-domain",
 
274
                                                              "Authorization domain", "The authorization domain for the upload.",
 
275
                                                              GDATA_TYPE_AUTHORIZATION_DOMAIN,
 
276
                                                              G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
277
 
 
278
        /**
258
279
         * GDataUploadStream:method:
259
280
         *
260
281
         * The HTTP request method to use when uploading the file.
372
393
 
373
394
        /* Make sure the headers are set */
374
395
        klass = GDATA_SERVICE_GET_CLASS (priv->service);
375
 
        if (klass->append_query_headers != NULL)
376
 
                klass->append_query_headers (priv->service, priv->message);
 
396
        if (klass->append_query_headers != NULL) {
 
397
                klass->append_query_headers (priv->service, priv->authorization_domain, priv->message);
 
398
        }
377
399
 
378
400
        if (priv->slug != NULL)
379
401
                soup_message_headers_append (priv->message->request_headers, "Slug", priv->slug);
416
438
                g_object_unref (priv->service);
417
439
        priv->service = NULL;
418
440
 
 
441
        if (priv->authorization_domain != NULL)
 
442
                g_object_unref (priv->authorization_domain);
 
443
        priv->authorization_domain = NULL;
 
444
 
419
445
        if (priv->message != NULL)
420
446
                g_object_unref (priv->message);
421
447
        priv->message = NULL;
457
483
                case PROP_SERVICE:
458
484
                        g_value_set_object (value, priv->service);
459
485
                        break;
 
486
                case PROP_AUTHORIZATION_DOMAIN:
 
487
                        g_value_set_object (value, priv->authorization_domain);
 
488
                        break;
460
489
                case PROP_METHOD:
461
490
                        g_value_set_string (value, priv->method);
462
491
                        break;
492
521
                        priv->service = g_value_dup_object (value);
493
522
                        priv->session = _gdata_service_get_session (priv->service);
494
523
                        break;
 
524
                case PROP_AUTHORIZATION_DOMAIN:
 
525
                        priv->authorization_domain = g_value_dup_object (value);
 
526
                        break;
495
527
                case PROP_METHOD:
496
528
                        priv->method = g_value_dup_string (value);
497
529
                        break;
965
997
/**
966
998
 * gdata_upload_stream_new:
967
999
 * @service: a #GDataService
 
1000
 * @domain: (allow-none): the #GDataAuthorizationDomain to authorize the upload, or %NULL
968
1001
 * @method: the HTTP method to use
969
1002
 * @upload_uri: the URI to upload
970
1003
 * @entry: (allow-none): the entry to upload as metadata, or %NULL
997
1030
 *
998
1031
 * Return value: a new #GOutputStream, or %NULL; unref with g_object_unref()
999
1032
 *
1000
 
 * Since: 0.8.0
 
1033
 * Since: 0.9.0
1001
1034
 **/
1002
1035
GOutputStream *
1003
 
gdata_upload_stream_new (GDataService *service, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
 
1036
gdata_upload_stream_new (GDataService *service, GDataAuthorizationDomain *domain, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
1004
1037
                         const gchar *slug, const gchar *content_type, GCancellable *cancellable)
1005
1038
{
1006
1039
        g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
 
1040
        g_return_val_if_fail (domain == NULL || GDATA_IS_AUTHORIZATION_DOMAIN (domain), NULL);
1007
1041
        g_return_val_if_fail (method != NULL, NULL);
1008
1042
        g_return_val_if_fail (upload_uri != NULL, NULL);
1009
1043
        g_return_val_if_fail (entry == NULL || GDATA_IS_ENTRY (entry), NULL);
1012
1046
        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
1013
1047
 
1014
1048
        /* Create the upload stream */
1015
 
        return G_OUTPUT_STREAM (g_object_new (GDATA_TYPE_UPLOAD_STREAM, "method", method, "upload-uri", upload_uri, "service", service,
1016
 
                                              "entry", entry, "slug", slug, "content-type", content_type, "cancellable", cancellable, NULL));
 
1049
        return G_OUTPUT_STREAM (g_object_new (GDATA_TYPE_UPLOAD_STREAM,
 
1050
                                              "method", method,
 
1051
                                              "upload-uri", upload_uri,
 
1052
                                              "service", service,
 
1053
                                              "authorization-domain", domain,
 
1054
                                              "entry", entry,
 
1055
                                              "slug", slug,
 
1056
                                              "content-type", content_type,
 
1057
                                              "cancellable", cancellable,
 
1058
                                              NULL));
1017
1059
}
1018
1060
 
1019
1061
/**
1073
1115
 * gdata_upload_stream_get_service:
1074
1116
 * @self: a #GDataUploadStream
1075
1117
 *
1076
 
 * Gets the service used to authenticate the upload, as passed to gdata_upload_stream_new().
 
1118
 * Gets the service used to authorize the upload, as passed to gdata_upload_stream_new().
1077
1119
 *
1078
 
 * Return value: (transfer none): the #GDataService used to authenticate the upload
 
1120
 * Return value: (transfer none): the #GDataService used to authorize the upload
1079
1121
 *
1080
1122
 * Since: 0.5.0
1081
1123
 **/
1087
1129
}
1088
1130
 
1089
1131
/**
 
1132
 * gdata_upload_stream_get_authorization_domain:
 
1133
 * @self: a #GDataUploadStream
 
1134
 *
 
1135
 * Gets the authorization domain used to authorize the upload, as passed to gdata_upload_stream_new(). It may be %NULL if authorization is not
 
1136
 * needed for the upload.
 
1137
 *
 
1138
 * Return value: (transfer none) (allow-none): the #GDataAuthorizationDomain used to authorize the upload, or %NULL
 
1139
 *
 
1140
 * Since: 0.9.0
 
1141
 */
 
1142
GDataAuthorizationDomain *
 
1143
gdata_upload_stream_get_authorization_domain (GDataUploadStream *self)
 
1144
{
 
1145
        g_return_val_if_fail (GDATA_IS_UPLOAD_STREAM (self), NULL);
 
1146
        return self->priv->authorization_domain;
 
1147
}
 
1148
 
 
1149
/**
1090
1150
 * gdata_upload_stream_get_method:
1091
1151
 * @self: a #GDataUploadStream
1092
1152
 *