Tuesday, June 16, 2015

Integration with Amazon SNS for push notifications

Pseudocode for Android integration with Amazon SNS:
server call to register for push notifications with registration token and DeviceId
if DeviceId is already stored then
    call DeleteEndpoint
else
    call CreatePlatformEndpoint to create new ARN for this device 
    store new ARN, Token and DeviceId
endif
I know there are other algorithms for working with Amazon’s SNS (like this one) but this seems to be the simplest, and it also solves the problem with Amazon not disabling the ARNs when applications are re-installed.
This should work for iOS-SNS integration, but I haven't had the chance to test.

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.



Sunday, May 10, 2015

SQL queries with optional WHERE parameters

There may be at some point a need to filter data based on some user input, which may or may not be available at application run-time. This is what we'll discuss in this post, in the context of SQL queries.



Sunday, April 26, 2015

Building JSONs using the POCO C++ library

POCO refers to a very handy set of libraries for C++. They are cleanly written, STL-like, easy to use and most importantly, free (Boost License). I've had a small encounter with these libraries, mainly the JSON module and I'll detail, in this article, on how to build a JSON and then how to parse a JSON object manually using POCO::JSON.



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.