summaryrefslogtreecommitdiff
path: root/src/client/Client.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-18 12:07:33 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-18 12:07:33 (GMT)
commita8e4221f38edefb5b342f470407b1f100d0248a3 (patch)
tree39f9d8036358c6150d5f7f6285a29e48a8c16882 /src/client/Client.cpp
parent78c4aba468a35166bf4ef5056b8e15be4098ba07 (diff)
downloadpowder-a8e4221f38edefb5b342f470407b1f100d0248a3.zip
powder-a8e4221f38edefb5b342f470407b1f100d0248a3.tar.gz
Working comment submission
Diffstat (limited to 'src/client/Client.cpp')
-rw-r--r--src/client/Client.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index d851e55..5ecb8ac 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -685,6 +685,67 @@ failure:
return RequestFailure;
}
+RequestStatus Client::AddComment(int saveID, std::string comment)
+{
+ lastError = "";
+ std::vector<string> * tags = NULL;
+ std::stringstream urlStream;
+ char * data = NULL;
+ int dataStatus, dataLength;
+ urlStream << "http://" << SERVER << "/Browse/Comments.json?ID=" << saveID << "&Key=" << authUser.SessionKey;
+ if(authUser.ID)
+ {
+ std::stringstream userIDStream;
+ userIDStream << authUser.ID;
+
+ char * postNames[] = { "Comment", NULL };
+ char * postDatas[] = { (char*)(comment.c_str()) };
+ int postLengths[] = { comment.length() };
+ data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
+ }
+ else
+ {
+ lastError = "Not authenticated";
+ return RequestFailure;
+ }
+ if(dataStatus == 200 && data)
+ {
+ try
+ {
+ std::istringstream dataStream(data);
+ json::Object objDocument;
+ json::Reader::Read(objDocument, dataStream);
+
+ int status = ((json::Number)objDocument["Status"]).Value();
+
+ if(status!=1)
+ {
+ lastError = ((json::Number)objDocument["Error"]).Value();
+ }
+
+ if(status!=1)
+ goto failure;
+ }
+ catch (json::Exception &e)
+ {
+ lastError = "Could not read response";
+ goto failure;
+ }
+ }
+ else
+ {
+ lastError = http_ret_text(dataStatus);
+ goto failure;
+ }
+ if(data)
+ free(data);
+ return RequestOkay;
+failure:
+ if(data)
+ free(data);
+ return RequestFailure;
+}
+
RequestStatus Client::FavouriteSave(int saveID, bool favourite)
{
lastError = "";