Re: [LEDE-DEV] [PATCH V2] Support specifying instance name in JSON file

2017-05-18 Thread John Crispin



On 12/05/17 11:08, Rafał Miłecki wrote:

From: Rafał Miłecki 

So far we were using host label as the instance name for every service.
This change allows specifying it manually and fallbacks to the label for
backward compatibility.

Signed-off-by: Rafał Miłecki 

Acked-by: John Crispin 

---
V2: Rebased on top of recent changes. This should work fine now thanks
 to the commits:
 26ce7dca8085d ("Allow filtering with instance name in service_reply")
 49fdb9f7a5454 ("Support PTR queries for a specific service")
---
  service.c | 10 --
  1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/service.c b/service.c
index 67e8f40..0a9e25d 100644
--- a/service.c
+++ b/service.c
@@ -34,6 +34,7 @@
  #include "announce.h"
  
  enum {

+   SERVICE_INSTANCE,
SERVICE_SERVICE,
SERVICE_PORT,
SERVICE_TXT,
@@ -55,6 +56,7 @@ struct service {
  };
  
  static const struct blobmsg_policy service_policy[__SERVICE_MAX] = {

+   [SERVICE_INSTANCE] = { .name = "instance", .type = BLOBMSG_TYPE_STRING 
},
[SERVICE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING },
[SERVICE_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
[SERVICE_TXT] = { .name = "txt", .type = BLOBMSG_TYPE_ARRAY },
@@ -210,7 +212,7 @@ service_load_blob(struct blob_attr *b)
  {
struct blob_attr *txt, *_tb[__SERVICE_MAX];
struct service *s;
-   char *d_service, *d_id;
+   char *d_instance, *d_service, *d_id;
uint8_t *d_txt;
int rem2;
int txt_len = 0;
@@ -226,6 +228,7 @@ service_load_blob(struct blob_attr *b)
  
  	s = calloc_a(sizeof(*s),

_id, strlen(blobmsg_name(b)) + 1,
+   _instance, _tb[SERVICE_INSTANCE] ? 
strlen(blobmsg_get_string(_tb[SERVICE_INSTANCE])) + 1 : 0,
_service, strlen(blobmsg_get_string(_tb[SERVICE_SERVICE])) + 
1,
_txt, txt_len);
if (!s)
@@ -233,7 +236,10 @@ service_load_blob(struct blob_attr *b)
  
  	s->port = blobmsg_get_u32(_tb[SERVICE_PORT]);

s->id = strcpy(d_id, blobmsg_name(b));
-   s->instance = umdns_host_label;
+   if (_tb[SERVICE_INSTANCE])
+   s->instance = strcpy(d_instance, 
blobmsg_get_string(_tb[SERVICE_INSTANCE]));
+   else
+   s->instance = umdns_host_label;
s->service = strcpy(d_service, 
blobmsg_get_string(_tb[SERVICE_SERVICE]));
s->active = 1;
s->t = 0;



___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH V2] Support specifying instance name in JSON file

2017-05-12 Thread Rafał Miłecki
From: Rafał Miłecki 

So far we were using host label as the instance name for every service.
This change allows specifying it manually and fallbacks to the label for
backward compatibility.

Signed-off-by: Rafał Miłecki 
---
V2: Rebased on top of recent changes. This should work fine now thanks
to the commits:
26ce7dca8085d ("Allow filtering with instance name in service_reply")
49fdb9f7a5454 ("Support PTR queries for a specific service")
---
 service.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/service.c b/service.c
index 67e8f40..0a9e25d 100644
--- a/service.c
+++ b/service.c
@@ -34,6 +34,7 @@
 #include "announce.h"
 
 enum {
+   SERVICE_INSTANCE,
SERVICE_SERVICE,
SERVICE_PORT,
SERVICE_TXT,
@@ -55,6 +56,7 @@ struct service {
 };
 
 static const struct blobmsg_policy service_policy[__SERVICE_MAX] = {
+   [SERVICE_INSTANCE] = { .name = "instance", .type = BLOBMSG_TYPE_STRING 
},
[SERVICE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING },
[SERVICE_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
[SERVICE_TXT] = { .name = "txt", .type = BLOBMSG_TYPE_ARRAY },
@@ -210,7 +212,7 @@ service_load_blob(struct blob_attr *b)
 {
struct blob_attr *txt, *_tb[__SERVICE_MAX];
struct service *s;
-   char *d_service, *d_id;
+   char *d_instance, *d_service, *d_id;
uint8_t *d_txt;
int rem2;
int txt_len = 0;
@@ -226,6 +228,7 @@ service_load_blob(struct blob_attr *b)
 
s = calloc_a(sizeof(*s),
_id, strlen(blobmsg_name(b)) + 1,
+   _instance, _tb[SERVICE_INSTANCE] ? 
strlen(blobmsg_get_string(_tb[SERVICE_INSTANCE])) + 1 : 0,
_service, strlen(blobmsg_get_string(_tb[SERVICE_SERVICE])) + 
1,
_txt, txt_len);
if (!s)
@@ -233,7 +236,10 @@ service_load_blob(struct blob_attr *b)
 
s->port = blobmsg_get_u32(_tb[SERVICE_PORT]);
s->id = strcpy(d_id, blobmsg_name(b));
-   s->instance = umdns_host_label;
+   if (_tb[SERVICE_INSTANCE])
+   s->instance = strcpy(d_instance, 
blobmsg_get_string(_tb[SERVICE_INSTANCE]));
+   else
+   s->instance = umdns_host_label;
s->service = strcpy(d_service, 
blobmsg_get_string(_tb[SERVICE_SERVICE]));
s->active = 1;
s->t = 0;
-- 
2.11.0


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev