Fixed Erbium chunks for minimal-net

This commit is contained in:
Matthias Kovatsch 2011-10-10 16:09:17 +02:00
parent 2522566b68
commit df9f871313
2 changed files with 19 additions and 14 deletions

View File

@ -315,7 +315,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next)
{
PRINTF("res: /%s (%p)\n", resource->url, resource);
PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos);
if (strpos >= *offset && bufpos < preferred_size)
{
@ -333,7 +333,8 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
if (strpos+tmplen > *offset)
{
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
"%s", resource->url + (*offset-strpos > 0 ? *offset-strpos : 0));
"%s", resource->url + ((*offset-(int32_t)strpos > 0) ? (*offset-(int32_t)strpos) : 0));
/* minimal-net requires these casts */
}
strpos += tmplen;
@ -355,10 +356,9 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
if (strpos+tmplen > *offset)
{
bufpos += snprintf((char *) buffer + bufpos, preferred_size - bufpos + 1,
"%s", resource->attributes + (*offset-strpos > 0 ? *offset-strpos : 0));
"%s", resource->attributes + (*offset-(int32_t)strpos > 0 ? *offset-(int32_t)strpos : 0));
}
strpos += tmplen;
}
if (resource->next)
@ -367,10 +367,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t
{
buffer[bufpos++] = ',';
}
if (bufpos <= preferred_size)
{
++strpos;
}
++strpos;
}
/* buffer full, but resource not completed yet; or: do not break if resource exactly fills buffer. */

View File

@ -301,11 +301,19 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
}
/* Generate data until reaching CHUNKS_TOTAL. */
while (strpos<REST_MAX_CHUNK_SIZE) {
strpos += snprintf((char *)buffer+strpos, REST_MAX_CHUNK_SIZE-strpos+1, "|%ld|", *offset);
while (strpos<preferred_size)
{
strpos += snprintf((char *)buffer+strpos, preferred_size-strpos+1, "|%ld|", *offset);
}
/* Truncate if above. */
if (*offset+strpos > CHUNKS_TOTAL)
/* snprintf() does not adjust return value if truncated by size. */
if (strpos > preferred_size)
{
strpos = preferred_size;
}
/* Truncate if above total size. */
if (*offset+(int32_t)strpos > CHUNKS_TOTAL)
{
strpos = CHUNKS_TOTAL - *offset;
}
@ -315,7 +323,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
/* IMPORTANT for chunk-wise resources: Signal chunk awareness to REST engine. */
*offset += strpos;
/* Signal end of resource. */
/* Signal end of resource representation. */
if (*offset>=CHUNKS_TOTAL)
{
*offset = -1;