Revision 747990ee

View differences:

include/chunkidset.h
16 16
*/
17 17
typedef struct chunkID_set ChunkIDSet;
18 18

  
19
enum chunkID_set_encoding_type {
20
  bitmap, priority
21
};
22

  
23 19
 /**
24 20
  * @brief Allocate a chunk ID set.
25 21
  * 
som/ChunkIDSet/chunkids_ops.c
7 7
#include <stdlib.h>
8 8
#include <stdint.h>
9 9
#include <limits.h>
10
#include <string.h>
10 11
#include <assert.h>
11 12

  
12 13
#include "chunkids_private.h"
......
19 20
{
20 21
  struct chunkID_set *p;
21 22
  struct tag *cfg_tags;
22
  int res, type;
23
  int res;
24
  const char *type;
23 25

  
24 26
  p = malloc(sizeof(struct chunkID_set));
25 27
  if (p == NULL) {
......
37 39
    p->elements = NULL;
38 40
  }
39 41
  p->type = CIST_PRIORITY;
40
  res = config_value_int(cfg_tags, "type", &type);
41
  free(cfg_tags);
42
  if (res) {
43
    switch (type) {
44
      case priority:
45
        p->type = CIST_PRIORITY;
46
        break;
47
      case bitmap:
48
        p->type = CIST_BITMAP;
49
        break;
50
      default:
51
        chunkID_set_free(p);
52

  
53
        return NULL; 
42
  type = config_value_str(cfg_tags, "type");
43
  if (type) {
44
    if (!memcmp(type, "priority", strlen(type) - 1)) {
45
      p->type = CIST_PRIORITY;
46
    } else if (!memcmp(type, "bitmap", strlen(type) - 1)) {
47
      p->type = CIST_BITMAP;
48
    } else {
49
      chunkID_set_free(p);
50
      free(cfg_tags);
51

  
52
      return NULL; 
54 53
    }
55 54
  }
55
  free(cfg_tags);
56 56
  assert(p->type == CIST_PRIORITY || p->type == CIST_BITMAP);
57

  
57 58
  return p;
58 59
}
59 60

  
som/Tests/chunkidset_test.c
69 69
  free(cset);
70 70
}
71 71

  
72
static void encoding_test(enum chunkID_set_encoding_type mode)
72
static void encoding_test(const char *mode)
73 73
{
74 74
  struct chunkID_set *cset, *cset1;
75 75
  static uint8_t buff[2048];
......
77 77
  void *meta;
78 78
  char config[32];
79 79

  
80
  sprintf(config,"type=%d", mode);
80
  sprintf(config,"type=%s", mode);
81 81
  cset = chunkID_set_init(config);
82 82
  populate(cset);
83 83
  res = encodeChunkSignaling(cset, NULL, 0, buff, sizeof(buff));
......
117 117
int main(int argc, char *argv[])
118 118
{
119 119
  simple_test();
120
  encoding_test(priority);
121
  encoding_test(bitmap);
120
  encoding_test("priority");
121
  encoding_test("bitmap");
122 122
  metadata_test();
123 123

  
124 124
  return 0;

Also available in: Unified diff