Skip to content

Commit

Permalink
added cookie management and token retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil Yadav committed May 5, 2018
1 parent 3d573bb commit b5bdb15
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion web/Makefile.m
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mkoctfile -v __curl__.cc
mkoctfile -v cookie_manager.cc
14 changes: 0 additions & 14 deletions web/__curl__.cc

This file was deleted.

28 changes: 28 additions & 0 deletions web/cookie_manager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <octave/oct.h>
#include <cstdio>
#include "libcurl_wrapper.cc"

DEFUN_DLD (cookie_manager, args, , "Some __cookie manager__ demo.")
{
if (args.length () != 1)
print_usage ();

auto a = libcurl_wrapper::create();

// octave_value_list retval = mkstemp(s,"delete");
FILE* fid = fopen("temp.txt","w+");
// std::string oct_ver = OCTAVE_VERSION;

curl_version_info_data * data = curl_version_info(CURLVERSION_NOW);
const char *lib_ver = data->version;

a.setJAR("temp.txt");
a.setAGENT(lib_ver);
std::string wikiapi = "http://wiki.octave.org/wiki/api.php";
std::string url = wikiapi + "?action=query&meta=tokens&type=login&format=json";
a.setURL (url);

a.perform ();
fclose(fid);
return octave_value (a.getEFFECTIVE_URL ());
}
15 changes: 15 additions & 0 deletions web/libcurl_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ class libcurl_wrapper {
curl_error (curl_easy_setopt (curl, CURLOPT_URL, url.c_str ()));
}

//! COOKIES OPTIONS
//! sets the cookies to be written in the file specified
void setJAR (std::string filename) {
curl_error (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, filename.c_str()));
}

//! USERAGENT OPTIONS
//! sets the cookies to be written in the file specified
void setAGENT (const char *lib_ver) {
std::string agent = "GNU Octave/" + std::string(OCTAVE_VERSION) \
+ " (https://www.gnu.org/software/octave/ ; help@octave.org) libcurl/"
+ std::string(lib_ver);
curl_error (curl_easy_setopt (curl, CURLOPT_USERAGENT, agent.c_str()));
}

//! GETINFO
//! get the last used URL
std::string getEFFECTIVE_URL () {
Expand Down

0 comments on commit b5bdb15

Please sign in to comment.