summaryrefslogtreecommitdiff
path: root/libcmis/libcmis-0.3.0-lotus-live-fix.patch
blob: 2aca934df8061329a7676c7f675576e9bc7f0846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff --git src/libcmis/atom-folder.cxx src/libcmis/atom-folder.cxx
index 68fb124..2756a5d 100644
--- src/libcmis/atom-folder.cxx
+++ src/libcmis/atom-folder.cxx
@@ -57,8 +57,11 @@ vector< libcmis::ObjectPtr > AtomFolder::getChildren( ) throw ( libcmis::Excepti
 {
     AtomLink* childrenLink = getLink( "down", "application/atom+xml;type=feed" );
 
+    // Some servers aren't giving the GetChildren properly... if not defined, we need to try
+    // as we may have the right to proceed.
     if ( ( NULL == childrenLink ) || ( getAllowableActions( ).get() &&
-                !getAllowableActions()->isAllowed( libcmis::ObjectAction::GetChildren ) ) )
+                ( !getAllowableActions()->isAllowed( libcmis::ObjectAction::GetChildren ) &&
+                  getAllowableActions()->isDefined( libcmis::ObjectAction::GetChildren ) ) ) )
         throw libcmis::Exception( string( "GetChildren not allowed on node " ) + getId() );
 
     vector< libcmis::ObjectPtr > children;
@@ -182,7 +185,8 @@ libcmis::DocumentPtr AtomFolder::createDocument( const map< string, libcmis::Pro
     AtomLink* childrenLink = getLink( "down", "application/atom+xml;type=feed" );
 
     if ( ( NULL == childrenLink ) || ( getAllowableActions( ).get() &&
-                !getAllowableActions()->isAllowed( libcmis::ObjectAction::CreateDocument ) ) )
+                !getAllowableActions()->isAllowed( libcmis::ObjectAction::CreateDocument ) &&
+                getAllowableActions()->isDefined( libcmis::ObjectAction::CreateDocument ) ) )
         throw libcmis::Exception( string( "CreateDocument not allowed on folder " ) + getId() );
 
     xmlBufferPtr buf = xmlBufferCreate( );
@@ -210,9 +214,37 @@ libcmis::DocumentPtr AtomFolder::createDocument( const map< string, libcmis::Pro
     }
 
     string respBuf = response->getStream( )->str( );
-    xmlDocPtr doc = xmlReadMemory( respBuf.c_str(), respBuf.size(), getInfosUrl().c_str(), NULL, 0 );
+    xmlDocPtr doc = xmlReadMemory( respBuf.c_str(), respBuf.size(), getInfosUrl().c_str(), NULL, XML_PARSE_NOERROR );
     if ( NULL == doc )
-        throw libcmis::Exception( "Failed to parse object infos" );
+    {
+        // We may not have the created document entry in the response body: this is
+        // the behaviour of some servers, but the standard says we need to look for
+        // the Location header.
+        map< string, string >& headers = response->getHeaders( );
+        map< string, string >::iterator it = headers.find( "Location" );
+
+        // Some servers like Lotus Live aren't sending Location header, but Content-Location
+        if ( it == headers.end( ) )
+            it = headers.find( "Content-Location" );
+
+        if ( it != headers.end() )
+        {
+            try
+            {
+                response = getSession( )->httpGetRequest( it->second );
+                respBuf = response->getStream( )->str( );
+                doc = xmlReadMemory( respBuf.c_str(), respBuf.size(), getInfosUrl().c_str(), NULL, XML_PARSE_NOERROR );
+            }
+            catch ( const CurlException& e )
+            {
+                throw e.getCmisException( );
+            }
+        }
+
+        // if doc is still NULL after that, then throw an exception
+        if ( NULL == doc )
+            throw libcmis::Exception( "Missing expected response from server" );
+    }
 
     libcmis::ObjectPtr created = getSession( )->createObjectFromEntryDoc( doc );
     xmlFreeDoc( doc );
diff --git src/libcmis/atom-object.cxx src/libcmis/atom-object.cxx
index b7b3b4a..812951d 100644
--- src/libcmis/atom-object.cxx
+++ src/libcmis/atom-object.cxx
@@ -140,6 +140,34 @@ libcmis::ObjectPtr AtomObject::updateProperties( const map< string, libcmis::Pro
     return updated;
 }
 
+libcmis::AllowableActionsPtr AtomObject::getAllowableActions( )
+{
+    if ( !m_allowableActions )
+    {
+        // For some reason we had no allowable actions before, get them now.
+        AtomLink* link = getLink( "http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions", "application/cmisallowableactions+xml" );
+        if ( link )
+        {
+            try
+            {
+                libcmis::HttpResponsePtr response = getSession()->httpGetRequest( link->getHref() );
+                string buf = response->getStream()->str();
+                xmlDocPtr doc = xmlReadMemory( buf.c_str(), buf.size(), link->getHref().c_str(), NULL, 0 );
+                xmlNodePtr actionsNode = xmlDocGetRootElement( doc );
+                if ( actionsNode )
+                    m_allowableActions.reset( new libcmis::AllowableActions( actionsNode ) );
+
+                xmlFreeDoc( doc );
+            }
+            catch ( libcmis::Exception& )
+            {
+            }
+        }
+    }
+
+    return libcmis::Object::getAllowableActions();
+}
+
 void AtomObject::refreshImpl( xmlDocPtr doc ) throw ( libcmis::Exception )
 {
     bool createdDoc = ( NULL == doc );
diff --git src/libcmis/atom-object.hxx src/libcmis/atom-object.hxx
index 2d1761d..452b4f5 100644
--- src/libcmis/atom-object.hxx
+++ src/libcmis/atom-object.hxx
@@ -69,6 +69,8 @@ class AtomObject : public virtual libcmis::Object
         virtual libcmis::ObjectPtr updateProperties(
                     const std::map< std::string, libcmis::PropertyPtr >& properties ) throw ( libcmis::Exception );
 
+        virtual libcmis::AllowableActionsPtr getAllowableActions( );
+
         /** Reload the data from the server.
               */
         virtual void refresh( ) throw ( libcmis::Exception ) { refreshImpl( NULL ); }
-- 
1.7.10.4