Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Sunday, September 4, 2016

HTTP chunked encoding using C++ and libcurl

HTTP chunked encoding is the way to transfer large amounts of data via HTTP. It is pretty easy to use with libcurl, if you have all the data in advance. In case you don't have all the data available when uploading, things get a bit tricky. This latter scenario is what this post will be focused on.



Saturday, September 3, 2016

Replacing legacy C-style buffers

Since I've been working lately on legacy projects, filled with C-style buffer containers like void*, char*, byte*, I've started replacing these types of buffers with something a bit more safe and modern, if I might say so.



Sunday, December 13, 2015

Running a stand alone child process from a parent process

Sometimes it is necessary to start a process from within another process, whether it is for executing a command line utility or to create a peer process with which the parent process will need to communicate.



Detaching a process from the terminal

Sometimes it is useful to detach your application from the console terminal. It may be because you're building a daemon or simply because you don't want the application closing when the user ends his terminal session.



Wednesday, May 27, 2015

Using the BPG image format on Android

There's a new image format in town and it's called BPG (Better Portable Graphics). Well, it's not so new, as it's been introduced in 2014, but it's new enough that you can find little information about integration with different platforms.
For academic/experimental purposes I've made a small Android application to see the format in practice.



Monday, April 13, 2015

How to drop root permissions in C

Sometimes it is necessary to run an application with root permissions in order to do some elevated work like binding to ports lower than 1024 or writing to files in /var/log, etc.  After the elevated work is finished, it is good practice to drop the root privileges and continue with the execution path as a non-privileged user. The motivation is based on security reasons: if ever an attacker takes control over your application, it should not give him control over the whole system.



Saturday, April 11, 2015

Getting the stack trace programmatically in C

In some situations where applications run for a long period of time on remote systems, if the application crashes, there is little information about the crash: no core dump or valuable log available. In such cases it is useful to get and log the stack trace at the moment of the crash, thus having some more information in order to solve the problem.
Getting some information about the stack trace is possible using C, as we will see below.



Monday, February 16, 2015

Using boost.property_tree.ptree to store JSON data

A Property Tree in Boost is a data structure that can store information in a tree-like format. Each node having a key and a value. It can be used to store XML, INI, INFO and JSON formats. Maybe also other, but these are the most popular and they are supported by boost, with ready-to-use parsers.
The limitation for JSON handling, is that property trees do not support simple arrays, since all nodes are of key-value type.



Monday, February 9, 2015

How to generate a SHA1 hash in C++

Having been put in the position of generating password hashes (again), I thought I better write it down for posterity.
You can always write your own SHA1 implementation, but let's be serious, who wants that? Unless you're doing it for academic purposes, it makes no sense to reinvent the wheel when there are so many good implementations out there.

Among all the available libraries I chose to experiment with OpenSSL and boost.