I'm looking to grab the source of a webpage and add it to a string, all the guides I see though use curl or winsockets and I need this to be cross-compatible and use C++ only (No external libraries)
Could anyone point me in the right direction please?
Thanks.
You may want to check boost::asio. It offers cross-platform networking, which will cover TCP/IP. boost is not a standard library, but it's de facto second standard C++ library. BTW, a lot of boost stuff ends up in std.
Next thing is HTTP client. Unfortunately, standard C++ library doesn't have HTTP client, but a basic, partial implementation of the protocol is simple enough that you can try to roll your own - you'll probably need only GET request. Try sending GET request over telnet, by typing it manually - you'll see it's very simple.
If SSL/TLS or a complete HTTP support is required, you may be forced to use a 3rd party library, because implementing them is a more than a challenging task.
For C++ only without an external library? No such thing.
Qt is fairly cross platform, supporting Windows, Linux, MacOS, Android, iOS and a bunch of other more exotic platforms, plus embedded.
Qt 4 had a dedicated QHttp class, but it got deprecated and removed in Qt 5. With Qt 5 you will have to use the QNetworkAccessManager class:
A simple download off the network could be accomplished with:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
True, Qt 5 is a big framework, hardly justified for the purpose of that single task, but on the other hand, it is very powerful, very portable application development framework, so odds are it may come in handy in other aspects as well.
Related
I am trying to create a signal/textsecure client using qt and C++, however i cant seem to fibd any C++ bindings for it.
the only bindings i can find are for Go (https://github.com/nanu-c/textsecure/)
is there any way to connect C++ with signal?
edit:
i wanted to clarify some things:
-im talking about the messaging app called Signal (https://signal.org)
-i am trying to write an app for ubuntu touch and am developing on manjaro linux.
On Linux or Unix, you probably want to communicate with other remote applications using some communication protocol, such as HTTP or HTTPS or SOAP or JSONRPC or ONCRPC. Of course read about socket(7) and before that Advanced Linux Programming then about syscalls(2). Consider reading a textbook on Operating Systems
Be sure to study the source code related to Signal. Read their technical documentation.
You surely need to understand the details. So take a few days or weeks to read more about them.
If you want to use some web service, you need to read and understand its documentation and when and how you are allowed to use it. There could be legal or financial issues.
Then you might use HTTP related libraries (e.g. Wt or libonion server side, and libcurl or curlpp client side).
See also in April 2020 the ongoing HelpCovid free software project (for Linux), at least for inspiration. We are coding it in C++.
after a little more digging i found that textsecure bindings are now renamed to libsignal.
after finding that out i found a lib for c/c++
https://github.com/signalapp/libsignal-protocol-c
Is it possible to use a Go API in a Qt C++ project?
I would like to use the following Google API written in Go: https://cloud.google.com/speech-to-text/docs/reference/libraries#client-libraries-install-go
Is it possible to use a Go API in a Qt C++ project?
It could be possible, but it might not be easy and would be very brittle to run Go and Qt code in the same process, since Go and Qt have very different thread (goroutine) and memory models.
However, Go has (in its standard library) many powerful packages to ease the development of server programs, in particular of HTTP or JSONRPC servers.
Perhaps you might consider running two different processes using inter-process communication facilities. Details are operating system specific. I assume you run Linux. Your Qt application could then start the Go program using QProcess and later communicate with it (behaving as a client to your Go specialized "server"-like program).
Then you could use HTTP or JSONRPC to remotely call your Go functions from your Qt application. You need some HTTP client library in Qt (it is there already under Qt Network, and you might also use libcurl) or some JSONRPC client library. Your Go program would be some specialized HTTP or JSONRPC server (and some Google Speech to Text client) and your Qt program would be its only client (and would start it). So your Go program would be some specialized proxy. You could even use pipe(7)-s, unix(7) sockets, or fifo(7)-s to increase the "privacy" of the communication channel.
If the Google Speech to Text API is huge (but it probably is not) you might use Go reflective or introspective abilities to generate some C++ glue code for Qt: go/ast, go/build, go/parser, go/importer, etc
BTW, it seems that Google Speech to Text protocol is using JSON with HTTP (it seems to be some Web API) and has a documented REST API, so you might directly code in C++ the relevant code doing that (of course you need to understand all the details of the protocol: relevant HTTP requests and JSON formats), without any Go code (or process). If you go that route, I recommend making your Qt (or C++) code for Google Speech to Text some separate free software library (to be able to get feedback and help from outside).
I'm looking for a jabber server library in C++.
I tried glooxd but it's tough to compile, buggy and no activity since more than a year now.
What I'm trying to do, is to be able to build a process that accept xmpp stream, implement it own way to authentify and build custom rosters.
Check out Swiften, a relatively new addition to the XMPP scene. It's primarily used in the client Swift, but also by Spectrum 2, which can act as a server to clients.
In the Swift git repo, there's also a tool called Slimber, that acts as a client in serverless messaging mode, and then presents that as a normal client interface. The server parts of Spectrum 2 and Slimber may be useful for you to study.
Check out the libxmpp project on Sourceforge. I don't know much about it. However, a number of years ago, I wrote a C++ layer on top of the loudmouth library. It's not hard to wrap the C library constructs in thin C++ classes.
Libxmpp: http://sourceforge.net/projects/xmpp/
Loudmouth: https://launchpad.net/loudmouth
I have been trying to find a simple C++ WebSocket client that is draft 08+ compatible. I have been able to find some server implementations, but that is not what I need. I need a client, hopefully with no extra stuff like server implementation to keep it small and clean and easy to build with as less dependencies as possible.
It has to be 08+ version compatible (Firefox 6+, Chrome 14+).
Do I need to implement it myself or have I missed a great library?
I want to be able to download a URL in C++. Something as simple as:
std::string s;
s=download("http://www.example.com/myfile.html");
Ideally, this would include URLs like:
ftp://example.com/myfile.dat
file:///usr/home/myfile.dat
https://example.com/myfile.html
I was using asio in Boost, but it didn't really seem to have the code for handling protocols like ftp and https. Now I discovered QT has more what I need (http://doc.trolltech.com/2.3/network.html).
It's tempting to make the switch to Qt, but it seems a bit heavy and intersects a lot of Boost functionality. Is it worth learning yet another API (Qt) or can Boost do more than I think?
Not a direct answer, but you might like to consider libCURL, which is almost exactly what you describe.
There are sample applications here, and in particular this demonstrates how simple usage can be.
I wouldn't go to Qt just for the networking stuff, since it's really not all that spectacular; there are a lot of missing pieces. I'd only switch if you need the GUI stuff, for which it is top notch.
libCURL is pretty simple to use and more robust than the Qt stuff.
You can use URLDownloadToFile.
#include <Urlmon.h>
HANDLE hr;
hr=URLDownloadToFile(NULL, L"http://www.example.com/myfile.html",L"mylocalfile.html",BINDF_GETNEWESTVERSION,NULL);
According to MSDN, BINDF_GETNEWESTVERSION - is a "Value that indicates that the bind operation retrieves the newest version of the data or object available. In URL monikers, this flag maps to the WinInet flag, INTERNET_FLAG_RELOAD, which forces a download of the requested resource".
The Poco Project has classes for cross-platform HTTP and FTP (and a lot of other stuff). There is overlap with boost. I recently found this, but have not used it.
You can use the URLDownloadToFile or URLOpenBlockingStream, although cURL, libcurl are the proper tools for that kind of jobs.
I got it working without either libcurl nor WinSock: https://stackoverflow.com/a/51959694/1599699
Special thanks to Nick Dandoulakis for suggesting URLOpenBlockingStream! I like it.