XFREE (MTYPE_COMMUNITY_VAL, com->val);
if (com->str)
XFREE (MTYPE_COMMUNITY_STR, com->str);
+
+ if (com->json)
+ {
+ json_object_free(com->json);
+ com->json = NULL;
+ }
+
XFREE (MTYPE_COMMUNITY, com);
}
return NULL;
new = community_new ();;
+ new->json = NULL;
for (i = 0; i < com->size; i++)
{
0xFFFFFF03 "local-AS"
For other values, "AS:VAL" format is used. */
-static char *
-community_com2str (struct community *com)
+static void
+set_community_string (struct community *com)
{
int i;
char *str;
u_int32_t comval;
u_int16_t as;
u_int16_t val;
+ json_object *json_community_list = NULL;
+ json_object *json_string = NULL;
if (!com)
return NULL;
+ com->json = json_object_new_object();
+ json_community_list = json_object_new_array();
+
/* When communities attribute is empty. */
if (com->size == 0)
{
str = XMALLOC (MTYPE_COMMUNITY_STR, 1);
str[0] = '\0';
- return str;
+
+ json_object_string_add(com->json, "string", "");
+ json_object_object_add(com->json, "list", json_community_list);
+ com->str = str;
+ return;
}
/* Memory allocation is time consuming work. So we calculate
case COMMUNITY_INTERNET:
strcpy (pnt, "internet");
pnt += strlen ("internet");
+ json_string = json_object_new_string("internet");
+ json_object_array_add(json_community_list, json_string);
break;
case COMMUNITY_NO_EXPORT:
strcpy (pnt, "no-export");
pnt += strlen ("no-export");
+ json_string = json_object_new_string("no-export");
+ json_object_array_add(json_community_list, json_string);
break;
case COMMUNITY_NO_ADVERTISE:
strcpy (pnt, "no-advertise");
pnt += strlen ("no-advertise");
+ json_string = json_object_new_string("no-advertise");
+ json_object_array_add(json_community_list, json_string);
break;
case COMMUNITY_LOCAL_AS:
strcpy (pnt, "local-AS");
pnt += strlen ("local-AS");
+ json_string = json_object_new_string("local-AS");
+ json_object_array_add(json_community_list, json_string);
break;
default:
as = (comval >> 16) & 0xFFFF;
val = comval & 0xFFFF;
sprintf (pnt, "%u:%d", as, val);
+ json_string = json_object_new_string(pnt);
+ json_object_array_add(json_community_list, json_string);
pnt += strlen (pnt);
break;
}
}
*pnt = '\0';
- return str;
+ json_object_string_add(com->json, "string", str);
+ json_object_object_add(com->json, "list", json_community_list);
+ com->str = str;
}
/* Intern communities attribute. */
/* Make string. */
if (! find->str)
- find->str = community_com2str (find);
+ set_community_string (find);
return find;
}
{
if (!com)
return NULL;
-
+
if (! com->str)
- com->str = community_com2str (com);
+ set_community_string (com);
return com->str;
}
case community_token_no_advertise:
case community_token_local_as:
if (com == NULL)
- com = community_new();
+ {
+ com = community_new();
+ com->json = NULL;
+ }
community_add_val (com, val);
break;
case community_token_unknown: