summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/stub/libmme
diff options
context:
space:
mode:
authorAleksandar Sutic2009-12-29 10:25:10 +0100
committerAleksandar Sutic2009-12-29 10:25:10 +0100
commitb6f063de522a48f05cad05bb1f85fd20e47f6ae6 (patch)
tree6816d70fada4c2615ec3d791d0d551b1a22959bc /cleopatre/devkit/tests/stub/libmme
parentc6c4e80484f329ae7e9db849088239942f9ba0f0 (diff)
cleo/apps/wld [eoc]: creates skeleton for white list daemon
- initial spec version - functionality coded, but not verified - unitary tests placeholder
Diffstat (limited to 'cleopatre/devkit/tests/stub/libmme')
-rw-r--r--cleopatre/devkit/tests/stub/libmme/src/mme.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/cleopatre/devkit/tests/stub/libmme/src/mme.c b/cleopatre/devkit/tests/stub/libmme/src/mme.c
index 8282fa4ff2..1d73e1625d 100644
--- a/cleopatre/devkit/tests/stub/libmme/src/mme.c
+++ b/cleopatre/devkit/tests/stub/libmme/src/mme.c
@@ -324,3 +324,88 @@ mme_error_t mme_send (mme_ctx_t *ctx, mme_send_type_t type, unsigned char *iface
return MME_SUCCESS;
}
+
+/**
+ * Put data at the end of MME payload. MME data tail and length are updated<br>
+ * If there is not enough free place to put data, an error is returned and the remaining free space length is returned.
+ *
+ * \param ctx MME context where to put data
+ * \param data data to put at the end of MME payload
+ * \param length length of data to put
+ * \param result_length length of data really put
+ * \return error type (MME_SUCCESS if success)
+ * \return MME_ERROR_NOT_INIT: context not initialized
+ * \return MME_ERROR_SPACE: not enough available space
+ */
+
+mme_error_t mme_put (mme_ctx_t *ctx, const void *data, unsigned int length, unsigned int *result_length)
+{
+ int free = 0;
+ int delta = 0;
+
+ /* protect from null pointers */
+ if (ctx == NULL || data == NULL || result_length == NULL)
+ return MME_ERROR_GEN;
+ /* check if ctx has been inititalized */
+ if (ctx->status == MME_STATUS_INIT)
+ return MME_ERROR_NOT_INIT;
+
+ free = ctx->length - (ctx->tail - ctx->head);
+ if (length > free)
+ {
+ *result_length = free;
+ return MME_ERROR_SPACE;
+ }
+
+ *result_length = length;
+
+ /* make place after payload, if needed */
+ if (length > ctx->length - ctx->tail)
+ {
+ /*
+ * *length
+ * .---------------^-----------------.
+ * |-----------|------------|xxxxxxx|-------------------------|
+ * buff head tail ctx->length
+ * \________ ________/
+ * \/
+ * payload
+ *
+ * we have to shift left our payload for this difference delta marked with 'x'
+ * in order for *length bytes to fit in from beginning of the buffer
+ */
+ delta = length - (ctx->length - ctx->tail);
+ memmove( (unsigned char *)(ctx->buffer + ctx->head - delta), (unsigned char *)(ctx->buffer + ctx->head), ctx->tail - ctx->head );
+
+ /* update head and tail pointers (offsets) */
+ ctx->head -= delta;
+ ctx->tail -= delta;
+ }
+
+ memcpy( (unsigned char *)(ctx->buffer + ctx->tail), (unsigned char *)data, length );
+ ctx->tail += length;
+
+ return MME_SUCCESS;
+}
+
+/** Get the remaining free space to add payload
+ *
+ * \param ctx MME context to get the remaining space
+ * \param length the remaining space
+ * \return error type (MME_SUCCESS if success)
+ * \return MME_ERROR_NOT_INIT: context not initialized
+ */
+
+mme_error_t mme_get_free_space (mme_ctx_t *ctx, unsigned int *length)
+{
+ /* protect from null pointers */
+ if (ctx == NULL || length == NULL)
+ return MME_ERROR_GEN;
+ /* check if ctx has been inititalized */
+ if (ctx->status == MME_STATUS_INIT)
+ return MME_ERROR_NOT_INIT;
+
+ *length = ctx->length - (ctx->tail - ctx->head);
+ return MME_SUCCESS;
+}
+