Cache the XML representation when creating a context

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Prefer snprintf instead of sprintf when possible

The sprintf function is not secure, as it cannot prevent buffer
overflows. The snprintf function takes an additionnal parameter, which
corresponds to the size of the buffer, and it is guaranteed that it will
not overflow the buffer.

Note that the few "sprintf" left in the code are not a security risk,
as we already assure that the buffer is large enough.

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>
Generate valid XML even if context does not contain any device

Signed-off-by: Paul Cercueil <paul.cercueil@analog.com>