Esempio n. 1
0
static void test_unicode_string_invalid(void)
{
    {
        /* check writing to stream that is not large enough */
        cbor_stream_t stream;
        cbor_init(&stream, 0, 0);

        TEST_ASSERT_EQUAL_INT(0, cbor_serialize_unicode_string(&stream, "foo"));

        cbor_destroy(&stream);
    }
}
int handleConfig(coap_rw_buffer_t* scratch,
                 const coap_packet_t* inpkt,
                 coap_packet_t* outpkt,
                 uint8_t id_hi, uint8_t id_lo)
{
    (void)scratch;
    (void)outpkt;
    (void)id_hi;
    (void)id_lo;

    coap_buffer_t payload = inpkt->payload;
    unsigned char* data = (unsigned char*) payload.p;

    // create cbor stream
    cbor_stream_t stream = {data, sizeof(data), 0};

    size_t map_length;
    // read out length of the map
    size_t offset = cbor_deserialize_map(&stream, 0, &map_length);
    int key1, key2, key3;
    char medtemp[8], hightemp[8], windowsize[8];
    // read key 1
    offset += cbor_deserialize_int(&stream, offset, &key1);
    // read medtemp
    offset += cbor_deserialize_byte_string(&stream, offset, medtemp, sizeof(medtemp));
    // read key 2
    offset += cbor_deserialize_int(&stream, offset, &key2);
    // read hightemp
    offset += cbor_deserialize_byte_string(&stream, offset, hightemp, sizeof(hightemp));
    // read key 3
    offset += cbor_deserialize_int(&stream, offset, &key3);
    // read windowsize
    offset += cbor_deserialize_byte_string(&stream, offset, windowsize, sizeof(windowsize));

    cbor_destroy(&stream);

    puts("NEW CONFIGURATION RECEIVED");

    YELLOW_TEMP = atoi(medtemp);
    RED_TEMP = atoi(hightemp);

    printf("YELLOW_TEMP set to: %d\n", YELLOW_TEMP);
    printf("RED_TEMP set to: %d\n", RED_TEMP);

    if (strcmp(windowsize, "-") != 0) {
        printf("Set windowsize to: %d\n", atoi(windowsize));
        setWindowSize(atoi(windowsize));
    }

    return 0;
}
Esempio n. 3
0
static void test_map_invalid(void)
{
    {
        /* check writing to stream that is not large enough */
        cbor_stream_t stream;
        cbor_init(&stream, 0, 0);

        TEST_ASSERT_EQUAL_INT(0, cbor_serialize_map(&stream, 1));

        cbor_destroy(&stream);
    }
    {
        /* check reading from stream that contains other type of data */
        unsigned char data[] = {0x40}; /* empty string encoded in CBOR */
        cbor_stream_t stream = {data, 1, 1};

        size_t map_length;
        TEST_ASSERT_EQUAL_INT(0, cbor_deserialize_map(&stream, 0, &map_length));
    }
}