1 /*
2  * create_txn.c: mod_dav_svn POST handler for creating a commit transaction
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23 
24 #include <httpd.h>
25 #include <mod_dav.h>
26 
27 #include "svn_dav.h"
28 #include "../dav_svn.h"
29 
30 /* Respond to a "create-txn" POST request.
31  *
32  * Syntax:  ( create-txn )
33  */
34 dav_error *
dav_svn__post_create_txn(const dav_resource * resource,svn_skel_t * request_skel,dav_svn__output * output)35 dav_svn__post_create_txn(const dav_resource *resource,
36                          svn_skel_t *request_skel,
37                          dav_svn__output *output)
38 {
39   const char *txn_name;
40   const char *vtxn_name;
41   dav_error *derr;
42   request_rec *r = resource->info->r;
43 
44   /* Create a Subversion repository transaction based on HEAD. */
45   if ((derr = dav_svn__create_txn(resource->info->repos, &txn_name, NULL,
46                                   resource->pool)))
47     return derr;
48 
49   /* Build a "201 Created" response with header that tells the
50      client our new transaction's name. */
51   vtxn_name = apr_table_get(r->headers_in, SVN_DAV_VTXN_NAME_HEADER);
52   if (vtxn_name && vtxn_name[0])
53     {
54       /* If the client supplied a vtxn name then store a mapping from
55          the client name to the FS transaction name in the activity
56          database. */
57       if ((derr  = dav_svn__store_activity(resource->info->repos,
58                                            vtxn_name, txn_name)))
59         return derr;
60       apr_table_set(r->headers_out, SVN_DAV_VTXN_NAME_HEADER, vtxn_name);
61     }
62   else
63     apr_table_set(r->headers_out, SVN_DAV_TXN_NAME_HEADER, txn_name);
64 
65   r->status = HTTP_CREATED;
66 
67   return NULL;
68 }
69 
70 
71 /* Respond to a "create-txn-with-props" POST request.
72  *
73  * Syntax:  ( create-txn-with-props (PROPNAME PROPVAL [PROPNAME PROPVAL ...])
74  */
75 dav_error *
dav_svn__post_create_txn_with_props(const dav_resource * resource,svn_skel_t * request_skel,dav_svn__output * output)76 dav_svn__post_create_txn_with_props(const dav_resource *resource,
77                                     svn_skel_t *request_skel,
78                                     dav_svn__output *output)
79 {
80   const char *txn_name;
81   const char *vtxn_name;
82   dav_error *derr;
83   svn_error_t *err;
84   request_rec *r = resource->info->r;
85   apr_hash_t *revprops;
86   svn_skel_t *proplist_skel = request_skel->children->next;
87 
88   if ((err = svn_skel__parse_proplist(&revprops, proplist_skel,
89                                       resource->pool)))
90     {
91       return dav_svn__convert_err(err, HTTP_BAD_REQUEST,
92                                   "Malformatted request skel", resource->pool);
93     }
94 
95   /* Create a Subversion repository transaction based on HEAD. */
96   if ((derr = dav_svn__create_txn(resource->info->repos, &txn_name,
97                                   revprops, resource->pool)))
98     return derr;
99 
100   /* Build a "201 Created" response with header that tells the
101      client our new transaction's name. */
102   vtxn_name = apr_table_get(r->headers_in, SVN_DAV_VTXN_NAME_HEADER);
103   if (vtxn_name && vtxn_name[0])
104     {
105       /* If the client supplied a vtxn name then store a mapping from
106          the client name to the FS transaction name in the activity
107          database. */
108       if ((derr  = dav_svn__store_activity(resource->info->repos,
109                                            vtxn_name, txn_name)))
110         return derr;
111       apr_table_set(r->headers_out, SVN_DAV_VTXN_NAME_HEADER, vtxn_name);
112     }
113   else
114     apr_table_set(r->headers_out, SVN_DAV_TXN_NAME_HEADER, txn_name);
115 
116   r->status = HTTP_CREATED;
117 
118   return NULL;
119 }
120