I'm looking for the simplest possible (cross-platform, but not necessarily cross-browser) code to send data from a local web page to a C (not C++) application running locally. Basically, I have an HTML page with a form and I want to send the data from that form to another process in the simplest way possible. (I know that I can read local data from a webpage relatively easily, especially now with HTML5, but writing outside of the javascript sandbox is a mystery.)
I know that browsers make this very hard to do for security concerns, and I don't want to open up my machine to attacks, but maybe I can run a very simple server inside the C application to receive the submitted data... Either way, I cannot run any standard webserver, so I need to have a C library/app that does it for me.
I've looked into .hta files (seem to only work for Windows) and some C web servers (all I've found are *nix specific). A similar question is how to transfer of data from webpage to a server c program , except that user allows the use of Java and other webserver platforms (I must use C).
UPDATE: Promising libraries: https://stackoverflow.com/questions/175507/c-c-web-server-library
Have you considered FastCGI? I have a fast CGI library written in C that might be helpful. It still needs a lot of work and I'm not sure if I would want to use in a production environment.
If you find any bugs or make any enhancements, please share them so that it can help others.
https://github.com/manvscode/shrewd-cgi
You could write a very simple web server in C, serve the page from it (avoids security issues), and post the form to it.
If you're bound to c, you'll have to go low-level and deal with all the nifty details around the sockets library. (There's a reason why people abstract that in high-level languages). Check out some example code for RPC in C with server and client here. If you can afford to bind to C, e.g. using Tcl, i would implement the server in a tcl script and bind your C functions as a Tcl command. That way you pass the content directly to your c method while avoiding to write all the sockets code low-level.
Send the desired data from web to specific port of your system (for example port X). Then run your application (e.g. APP) in background using following command:
nc -l X | ./APP
And of course you need nc package.
Related
My question should be very simple to answer for anyone not being a self-taught newbie like me...
On this page is a cheatsheet concerning a function to be used in GIS/DB environnement : http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg
I would like to create a script allowing users to just have to click on it to launch the process, given the proper datas. But I don't understand how to use this. It obviously doesn't work in a Python console, nor directly in the windows console. How is it supposed to work ? What language is this ?
Thanks
shp2pgsql is indeed a command line tool. It comes with your PostgreSQL/PostGIS installation (usually) and, if not accessible via PATH-variable, can (usually) be run from within the /bin-folder in your PostgreSQL-Installation. You can also always 'make' the programm from source in any location yourself, if needed.
EDIT:
One way to set up a script (independent of whether you use it within qgis own python environment or not) would be to use Pythons subprocess (or os.system) module (check related question here) to write to shell and execute shp2pgsql.
A slightly more sophisitcated solution to (batch) insert (multiple) shapefiles via script could be to implement ogr2ogr via gdal/ogr module within python (check this blog). That, however, would require a working installation of the gdal core library, and the respective Python bindings (at least to use outside of QGIS Python environment, where it is pre-installed AFAIK), which can be tiresome at times. Once installed correctly, it offers a powerful (I dare say almighty) toolset for geodata management and manipulation via Python, though.
Apart from that, the blog link I provided also states the implementation of a batch insert script/tool (which operates ogr2ogr) in qgis 2.8 toolbox...maybe that can help you, either with your work directly or (via sourcecode) to point you in the direction of creating your own tool.
I'm implementing a RESTful web API in an embedded stack which provides a webserver without the REST feature. To be precise, the embedded stack is RTCS which runs on top of the MQX RT operating system, the microcontroller is a Kinetis K60 from Freescale. I'm able to distinguish GET/POST/DELETE/PUT requests and to get the url with the parameters (let's say /this/firstValue/that/secondValue/...).
I use strtok to separate the different elements of the url and take decisions. But my code is just ugly because it's full of strcmp functions and if statements. I also need to check bounds for firstValue and secondValue (which I could do in set/get functions, but 2 functions for each parameter will be repetitve). Moreover I'd like to be able to add parameters without messing around with the decision tree.
I have two questions:
How would you make the code nice and dry?
Do you think a REST webservice is appropriate to control my microcontroller over the network? Do you have examples of such things? I'm using a REST webservice because it provides authentication (no secrecy however because I can't setup SSL sockets yet) and I think it's an elegant solution.
I evaluated some other solutions:
SNMP (snmpset/snmpget): it worked but setting up the MIBs was a real pain, and since it's SNMPv2 there is still no secrecy.
telnet server (I have no SSH solution yet): I don't see any advantage/drawback aside that REST will probably be easier to control from the outside, I'm testing it with curl :)
SOAP Remote Procedure Call (I just don't like it)
Any other idea ? I need something simple and scalable since there could be multiple targets to control. I have limited resources :s. I would need secrecy at some point, and I expect to have it when CyaSSL (an embedded ssl implemetation) is ported to MQX. They said it's happening next month so secrecy won't be an issue anymore but if you have other ideas...
--
Emilien
REST is an architectual pattern, So i guess you mean your server provides HTTP.
A resource is 'any data that can be named'. e.g. an LED on your embedded device could be a URI of '/leds/led3' You could change the data it holds (its state, rgb led? etc) with the standard PUT request, and GET should return its current state.
As for coding it, a generic tree structure maybe wise if memory permits to make path finding as simple as possible. With the data and function pointers (emulating objects) at the leafs
I want to create an application in C that allows two users to share a file. I'll call the person sending the file the server and the receiver the client. There are a few requirements:
The users need no identification, no "login". You could say they are unknown for my application.
The server selects a file for transfer and gets returned a simple ~10 character ID string/hash that the client can use to retrieve the file.
The same application is used for both serving and receiving.
My application must not need dedicated software running on a remote server, unless it's freely available (e.g. bittorrent trackers).
Now this sounds a lot like bittorrent and I am seriously thinking of doing this through bittorrent. I'm not sure how I would do this. Are there any good libraries for torrent creation / seeding / downloading?
Please answer this question by either:
Posing a viable alternative for bittorrent / other ideas.
Posting good libraries / snippets / implementations of the bittorrent protocol in C.
This does indeed sound like something best done with BitTorrent. Have you had a look at libbt? It's not very well documented but does include a sample client, which is btget.c in /src/.
I have now found this library: rasterbar libtorrent. It's in C++ but I don't mind (I don't know either that well anyway).
Sharing here for future reference if other people are looking for the same thing as me.
And an other solution, send the file through an IRC server (like Freenode). I came up with this solution after I had trouble with opening ports with bittorrent.
I want to make a program that reads a serial port (V.24).
with the info from the serial port I need to split a string up, and add it to a MySQL database.
I don't know C very well, so I need some help with what functions I should use
The program has to run under windows XP, and I have to make it an service.
thanks,
Sebastian
Services are a pain to debug. I suggest writing your code as a normal application first - command line will do - and then, once it works, converting it to a service (which is a mechanical process).
In general, Windows GUI based apps in C are a PITA to write for the first time. Very finicky, very sensitive. A command line app or a service will be quite a bit easier.
I recommend reading this. As for if this will work as a service, I am not sure, but it should.
You can also look at existing open source projects, to see if you can take that source as a starting point, or if they already solve your problems.
I have some C code that parses a file and generates another file of processed data. I now need to post these files to a website on a web server. I guess there is a way to do a HTTP POST but I have never done this in c (using GCC on Ubuntu). Does anyone know how to do this? I need a starting point as I have no clue of doing this in C. I also need to be able to authenticate with the website.
libcurl is probably a good place to start.
I think Hank Gay's suggestion of using a library to handle the details is the best one, but if you want to "do it yourself", you need to open a socket to the web server and then send your data in the HTTP POST format which is described here. Authentication can mean a variety of different things, so you need to be more specific.
Unfortunately, all of the above three jobs involve a fair bit of complexity, so you need to break the question down into stages and come back and ask about each bit separately.