Weird character in chrome when sending URL - c++

I'm having some trouble while trying to open a local file in google-chrome as it gives me a weird URL in google chrome but prints just fine in the console.
Here is my code:
int subId = 902 ;
system(("google-chrome "+localURL+"initialFr.html?id="+to_string(subId)).data());
std::cout << ("google-chrome "+localURL+"initialFr.html?id="+to_string(subId)).data() << std::endl
Here is the output I get in the console:
file:///home/lonni/Questionnaire/initialFr.html?id=902
Here is the address I get in chrome:
file:///home/lonni/Questionnaire/initialFr.html%3Fid=902
I am using c++11 (hence the .data()) on ubuntu.
Would you guys know where this comes from?
Thanks in advance

The file: URL schema does not support HTTP schema parameter passing. Those parameters are intended to be interpreted by an HTTP server.
If you need to pass a parameter, you can use an anchor, for example:
file:///home/lonni/Questionnaire/initialFr.html#902

Related

Config File using Environment Variables

I have a .cfg file and I'd like to use an environment variable to configure one of the fields.
directory=${HOME}/folder1/
However, when I parse this config, it's reading ${HOME} as a string, which is obviously not what I want.
I wrote my own parser in C++, in case I need to do something special. Right now it is a very basic read and parse.
void Config_Parser::parse_config_by_delimiter(string config, string delimiter) {
ifstream infile(config);
while (infile >> line) {
key = line.substr(0, line.find(delimiter));
value = line.substr(line.find(delimiter)+1);
if (this->config_settings.find(key) != this->config_settings.end()) {
cout << "Cannot use config... same key is set multiple times" << endl;
}
this->config_settings.insert({key, value});
}
}
The code seems to work fine for all other config settings (anything not using an environment variable), so I don't think its a problem with the code. But, I am a C++ noobie, so it's here anyways.
When I parse and print out the value:
Actual output: ${HOME}/folder1/
Expected/desired output: /home/my_dir/folder1/
Untested
You can use wordexp to do posix shell-like expansion of strings.
The function wordexp() performs a shell-like expansion of the string
s and returns the result in the structure pointed to by p.
You will need to #include <wordexp.h>
You also probably want to specify the flag WRDE_NOCMD to prevent subshell command execution.
http://man7.org/linux/man-pages/man3/wordexp.3.html
Is the following configuration syntax acceptable to you?
directory = getenv("HOME") + "/folder1/";
If so, then a configuration file parser library I wrote called Config4* can do what you want. You can find it on http://www.config4star.org.
I recommend you scroll down the web page to "Download the Manuals" and retrieve Config4* Getting Started Guide and Config4* C++ API Guide. Chapters 2 (overview of syntax) and 3 (overview of API) of the "Getting Started" guide should be more than sufficient to get you up and running.

Google Native Client Visual Studio Add-in: Webserver fails to start because arguments to httpd.py are invalid

I have an application that I turned into a simple Native Client App a year ago, and I've been trying to get it running again. However, when I try to run it, or any of the example VS projects, the web server fails to start, giving me usage hints for httpd.py, and saying "httpd.py: error: unrecognized arguments: 5103".
I wasn't able to find anything about this on the NaCL guide or on the net. I could probably troubleshoot the issue if I could see the script that starts the webserver, but I have no idea where this is stored.
The script that start the server is 'nacl_sdk\pepper_43\tools\httpd.py'. The problem is with the port argument being formated incorrectly.
The expected format is:
httpd.py [-h] [-C SERVE_DIR] [-p PORT] [--no-dir-check]
But, the received arguments formatted by the add-in is:
['--no_dir_check', '5103']
where the port prefix is missing and should be '-p 5103'
For a quick fix, add the following line
parser.add_argument('args', nargs=argparse.REMAINDER)
before the parse_args(args) in the main(args) method in httpd.py.
This will keep the unknown arguments from being parsed and will use the default value for port instead (5103).

Apache standard output stream

In my cpp file I am printing some debug messages to std::cout standard output stream. When i use this file and run the executable using Apache server. Where will the debug messages get printed. I don't see them printed in /var/lib/httpd/error_log.
Thanks in advance.
The only reason you should be using the Apache web server to run a C++ program is if your making a CGI script
Check it out: http://en.wikipedia.org/wiki/Common_Gateway_Interface
The process here is that Apache, the web server, runs your program and uses the output(std::cout) as the page source.
The page source can either be html or plain text. The only problem is the server doesn't know, so you provide it with a little hint at the start of your output. It's called the header.
If your outputting html you must print:
Content-type: text/html
followed by two newlines.
or if you want the web server to interpret the data as plain text, you must initially print
Content-type: text/plain
also followed by two newlines.
For example, a C++ program which should work would look something like this:
#include <iostream>
int main()
{
//output header, then one newline, then another, paired with a flush.
std::cout << "Content-type: text/plain\n" << std::endl;
//now your output
//calculation...
std::cout << "Hello World" << std::endl;
return 0;
}
Any web server parameters can be queried with some pre-set environment variables. Read up on the wikipedia article I linked.
EDIT:
I apologize, The Content-type: text/html and Content-type: text/plain was correct, but I previously said they required a new line. I was mistaken, they require two new lines
If this is the first time you are seeing this post, than don't worry about it.

what is the deal with Facebook API error: Could not parse into a date or time

Im getting group wall posts , just fine in the end of the json response , im getting the paging object
when i take the previous value and try to http request it:
https://graph.facebook.com/175923872448029/feed?access_token=**********13c0fd29b9-557002013|N-oGZ6q2sNDNg1I3leS0v9U-TDw&limit=25&since=2011-01-25T1100253A3400253A2100252B0000
im getting this error :
{
"error": {
"type": "InvalidArgumentException",
"message": "Could not parse '2011-01-25T1100253A3400253A2100252B0000' into a date or time."
}
}
what is wrong with the date ?
when you open https://graph.facebook.com/175923872448029/feed in your browser you'll notice that the paging link consists of utf numeric codes which have to be decoded prior to using them [edit].
However, when I requested the same object using the PHP SDK I got an encoded URL which works fine.
The reason for that behaviour is explained, I believe, in this post.
In summary, you have to check what the returned string looks like and decode it adequately before you proceed.

Getting HTTP xml error response using cURL

I am currently using cURL to communicate to a cloud site... everything is going well except for an annoying issue. The issue is that I cannot get the site's xml response when there is an error. for example, when I use Wire Shark to check the transfer I can see that in the HTTP header that I'm getting which contains the error code; there is an XML data that contains in addition to the error code, a message that describes the code. I have tried many cURL options to try and get the XML but all my attempts failed.
Could someone tell me how can I get the XML. please note that I'm using the cURL C APIs as my code is in c++ and moreover, I can get XML responses when the operation succeeds using my write callback function.
Set CURLOPT_FAILONERROR to 0. If this is set to 1, then any HTTP response >= 300 will result in an error rather than processing like you want.