static void *folder_listing_open(const char *name, int oflag, mode_t mode, void *driver_data, size_t *size, int *err) { struct mas_session *mas = driver_data; /* 1024 is the default when there was no MaxListCount sent */ uint16_t max = 1024; uint16_t offset = 0; if (oflag != O_RDONLY) { *err = -EBADR; return NULL; } DBG("name = %s", name); if (mas->inparams) { g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max); g_obex_apparam_get_uint16(mas->inparams, MAP_AP_STARTOFFSET, &offset); } *err = messages_get_folder_listing(mas->backend_data, name, max, offset, get_folder_listing_cb, mas); mas->buffer = g_string_new(""); if (*err < 0) return NULL; else return mas; }
static void *msg_listing_open(const char *name, int oflag, mode_t mode, void *driver_data, size_t *size, int *err) { struct mas_session *mas = driver_data; struct messages_filter filter = { 0, }; /* 1024 is the default when there was no MaxListCount sent */ uint16_t max = 1024; uint16_t offset = 0; /* If MAP client does not specify the subject length, then subject_len = 0 and subject should be sent unaltered. */ uint8_t subject_len = 0; DBG(""); if (oflag != O_RDONLY) { *err = -EBADR; return NULL; } if (!mas->inparams) goto done; g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max); g_obex_apparam_get_uint16(mas->inparams, MAP_AP_STARTOFFSET, &offset); g_obex_apparam_get_uint8(mas->inparams, MAP_AP_SUBJECTLENGTH, &subject_len); g_obex_apparam_get_uint32(mas->inparams, MAP_AP_PARAMETERMASK, &filter.parameter_mask); g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERMESSAGETYPE, &filter.type); filter.period_begin = g_obex_apparam_get_string(mas->inparams, MAP_AP_FILTERPERIODBEGIN); filter.period_end = g_obex_apparam_get_string(mas->inparams, MAP_AP_FILTERPERIODEND); g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERREADSTATUS, &filter.read_status); filter.recipient = g_obex_apparam_get_string(mas->inparams, MAP_AP_FILTERRECIPIENT); filter.originator = g_obex_apparam_get_string(mas->inparams, MAP_AP_FILTERORIGINATOR); g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERPRIORITY, &filter.priority); done: *err = messages_get_messages_listing(mas->backend_data, name, max, offset, subject_len, &filter, get_messages_listing_cb, mas); mas->buffer = g_string_new(""); if (*err < 0) return NULL; else return mas; }
static void get_folder_listing_cb(void *session, int err, uint16_t size, const char *name, void *user_data) { struct mas_session *mas = user_data; uint16_t max = 1024; if (err < 0 && err != -EAGAIN) { obex_object_set_io_flags(mas, G_IO_ERR, err); return; } if (mas->inparams) g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max); if (max == 0) { if (err != -EAGAIN) mas->outparams = g_obex_apparam_set_uint16( mas->outparams, MAP_AP_FOLDERLISTINGSIZE, size); if (!name) mas->finished = TRUE; goto proceed; } if (!mas->nth_call) { g_string_append(mas->buffer, XML_DECL); g_string_append(mas->buffer, FL_DTD); if (!name) { g_string_append(mas->buffer, FL_BODY_EMPTY); mas->finished = TRUE; goto proceed; } g_string_append(mas->buffer, FL_BODY_BEGIN); mas->nth_call = TRUE; } if (!name) { g_string_append(mas->buffer, FL_BODY_END); mas->finished = TRUE; goto proceed; } if (g_strcmp0(name, "..") == 0) g_string_append(mas->buffer, FL_PARENT_FOLDER_ELEMENT); else g_string_append_escaped_printf(mas->buffer, FL_FOLDER_ELEMENT, name); proceed: if (err != -EAGAIN) obex_object_set_io_flags(mas, G_IO_IN, err); }
static struct apparam_field *parse_aparam(const uint8_t *buffer, uint32_t hlen) { GObexApparam *apparam; struct apparam_field *param; apparam = g_obex_apparam_decode(buffer, hlen); if (apparam == NULL) return NULL; param = g_new0(struct apparam_field, 1); /* * As per spec when client doesn't include MAXLISTCOUNT_TAG then it * should be assume as Maximum value in vcardlisting 65535 */ param->maxlistcount = UINT16_MAX; g_obex_apparam_get_uint8(apparam, ORDER_TAG, ¶m->order); g_obex_apparam_get_uint8(apparam, SEARCHATTRIB_TAG, ¶m->searchattrib); g_obex_apparam_get_uint8(apparam, FORMAT_TAG, ¶m->format); g_obex_apparam_get_uint16(apparam, MAXLISTCOUNT_TAG, ¶m->maxlistcount); g_obex_apparam_get_uint16(apparam, LISTSTARTOFFSET_TAG, ¶m->liststartoffset); g_obex_apparam_get_uint64(apparam, FILTER_TAG, ¶m->filter); param->searchval = g_obex_apparam_get_string(apparam, SEARCHVALUE_TAG); DBG("o %x sa %x sv %s fil %" G_GINT64_MODIFIER "x for %x max %x off %x", param->order, param->searchattrib, param->searchval, param->filter, param->format, param->maxlistcount, param->liststartoffset); g_obex_apparam_free(apparam); return param; }
static void test_apparam_get_uint16(void) { GObexApparam *apparam; uint16_t data; gboolean ret; apparam = parse_and_decode(tag_uint16, sizeof(tag_uint16)); ret = g_obex_apparam_get_uint16(apparam, TAG_U16, &data); g_assert(ret == TRUE); g_assert(data == 0x0102); g_obex_apparam_free(apparam); }
static void test_apparam_get_multi(void) { GObexApparam *apparam; char *string; uint8_t data8; uint16_t data16; uint32_t data32; uint64_t data64; gboolean ret; apparam = g_obex_apparam_decode(tag_multi, sizeof(tag_multi)); g_assert(apparam != NULL); ret = g_obex_apparam_get_uint8(apparam, TAG_U8, &data8); g_assert(ret == TRUE); g_assert(data8 == 0x01); ret = g_obex_apparam_get_uint16(apparam, TAG_U16, &data16); g_assert(ret == TRUE); g_assert(data16 == 0x0102); ret = g_obex_apparam_get_uint32(apparam, TAG_U32, &data32); g_assert(ret == TRUE); g_assert(data32 == 0x01020304); ret = g_obex_apparam_get_uint64(apparam, TAG_U64, &data64); g_assert(ret == TRUE); g_assert(data64 == 0x0102030405060708); string = g_obex_apparam_get_string(apparam, TAG_STRING); g_assert(string != NULL); g_assert_cmpstr(string, ==, "ABC"); g_free(string); g_obex_apparam_free(apparam); }
static void get_messages_listing_cb(void *session, int err, uint16_t size, gboolean newmsg, const struct messages_message *entry, void *user_data) { struct mas_session *mas = user_data; uint16_t max = 1024; gchar *mse_time; if (err < 0 && err != -EAGAIN) { obex_object_set_io_flags(mas, G_IO_ERR, err); return; } if (mas->inparams) g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max); if (max == 0) { if (!entry) mas->finished = TRUE; goto proceed; } if (!mas->nth_call) { g_string_append(mas->buffer, ML_BODY_BEGIN); mas->nth_call = TRUE; } if (!entry) { g_string_append(mas->buffer, ML_BODY_END); mas->finished = TRUE; goto proceed; } g_string_append(mas->buffer, "<msg"); g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"", entry->handle); if (entry->mask & PMASK_SUBJECT) g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"", entry->subject); if (entry->mask & PMASK_DATETIME) g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"", entry->datetime); if (entry->mask & PMASK_SENDER_NAME) g_string_append_escaped_printf(mas->buffer, " sender_name=\"%s\"", entry->sender_name); if (entry->mask & PMASK_SENDER_ADDRESSING) g_string_append_escaped_printf(mas->buffer, " sender_addressing=\"%s\"", entry->sender_addressing); if (entry->mask & PMASK_REPLYTO_ADDRESSING) g_string_append_escaped_printf(mas->buffer, " replyto_addressing=\"%s\"", entry->replyto_addressing); if (entry->mask & PMASK_RECIPIENT_NAME) g_string_append_escaped_printf(mas->buffer, " recipient_name=\"%s\"", entry->recipient_name); if (entry->mask & PMASK_RECIPIENT_ADDRESSING) g_string_append_escaped_printf(mas->buffer, " recipient_addressing=\"%s\"", entry->recipient_addressing); if (entry->mask & PMASK_TYPE) g_string_append_escaped_printf(mas->buffer, " type=\"%s\"", entry->type); if (entry->mask & PMASK_RECEPTION_STATUS) g_string_append_escaped_printf(mas->buffer, " reception_status=\"%s\"", entry->reception_status); if (entry->mask & PMASK_SIZE) g_string_append_escaped_printf(mas->buffer, " size=\"%s\"", entry->size); if (entry->mask & PMASK_ATTACHMENT_SIZE) g_string_append_escaped_printf(mas->buffer, " attachment_size=\"%s\"", entry->attachment_size); if (entry->mask & PMASK_TEXT) g_string_append_escaped_printf(mas->buffer, " text=\"%s\"", yesorno(entry->text)); if (entry->mask & PMASK_READ) g_string_append_escaped_printf(mas->buffer, " read=\"%s\"", yesorno(entry->read)); if (entry->mask & PMASK_SENT) g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"", yesorno(entry->sent)); if (entry->mask & PMASK_PROTECTED) g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"", yesorno(entry->protect)); if (entry->mask & PMASK_PRIORITY) g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"", yesorno(entry->priority)); g_string_append(mas->buffer, "/>\n"); proceed: if (!entry) { mas->outparams = g_obex_apparam_set_uint16(mas->outparams, MAP_AP_MESSAGESLISTINGSIZE, size); mas->outparams = g_obex_apparam_set_uint8(mas->outparams, MAP_AP_NEWMESSAGE, newmsg ? 1 : 0); /* Response to report the local time of MSE */ mse_time = get_mse_timestamp(); if (mse_time) { g_obex_apparam_set_string(mas->outparams, MAP_AP_MSETIME, mse_time); g_free(mse_time); } } if (err != -EAGAIN) obex_object_set_io_flags(mas, G_IO_IN, 0); }