diff mbox series

moongose_interface, upload_handler, json return message

Message ID 20200328133033.10511-1-dkomljenovic@zoho.com
State Rejected
Headers show
Series moongose_interface, upload_handler, json return message | expand

Commit Message

'Darko Komljenovic' via swupdate March 28, 2020, 1:30 p.m. UTC
If image upload successful return status, file name and size in json

Signed-off-by: Darko Komljenovic <dkomljenovic@zoho.com>
---
 mongoose/mongoose_interface.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Stefano Babic March 30, 2020, 8:21 a.m. UTC | #1
Hi Darko,

On 28/03/20 14:30, 'Darko Komljenovic' via swupdate wrote:
> If image upload successful return status, file name and size in json
> 

It is not clear to me which issue should be addressed with this. This is
an internal interface and it is interpreted just by the web-app. Which
is the intention here ?

Best regards,
Stefano Babic

> Signed-off-by: Darko Komljenovic <dkomljenovic@zoho.com>
> ---
>  mongoose/mongoose_interface.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
> index 4d2ab52..e3a990d 100644
> --- a/mongoose/mongoose_interface.c
> +++ b/mongoose/mongoose_interface.c
> @@ -347,10 +347,15 @@ static void upload_handler(struct mg_connection *nc, int ev, void *p)
>  		ipc_end(fus->fd);
>  
>  		mg_send_response_line(nc, 200,
> -			"Content-Type: text/plain\r\n"
> +			"Content-Type: application/json\r\n"
>  			"Connection: close");
>  		mg_send(nc, "\r\n", 2);
> -		mg_printf(nc, "Ok, %s - %d bytes.\r\n", mp->file_name, (int) fus->len);
> +		mg_printf(nc,	"{\r\n"
> +						"\t\"status\": \"OK\",\r\n" 
> +						"\t\"file-name\": \"%s\",\r\n" 
> +						"\t\"size\": \"%d bytes\"\r\n"
> +						"}\r\n"
> +						, mp->file_name, (int) fus->len);
>  		nc->flags |= MG_F_SEND_AND_CLOSE;
>  
>  		mp->user_data = NULL;
>
pharaon2502@gmail.com March 30, 2020, 9:29 a.m. UTC | #2
So when we POST our image to swupdate/upload, then we can wait for the 
return message, which was before

Ok, <image-name> <image-size>

Hi,

With this we get it the response in json format, so it is easier to make a 
tool which just POSTs the image to the swupdate/upload and then just read 
the JSON return for information.

{
    "status": "OK",
    "file-name": "<name>",
    "size": "<size> bytes"
}

BR,
Darko

On Monday, March 30, 2020 at 10:26:18 AM UTC+2, Stefano Babic wrote:
>
> Hi Darko, 
>
> On 28/03/20 14:30, 'Darko Komljenovic' via swupdate wrote: 
> > If image upload successful return status, file name and size in json 
> > 
>
> It is not clear to me which issue should be addressed with this. This is 
> an internal interface and it is interpreted just by the web-app. Which 
> is the intention here ? 
>
> Best regards, 
> Stefano Babic 
>
> > Signed-off-by: Darko Komljenovic <dkomlj...@zoho.com <javascript:>> 
> > --- 
> >  mongoose/mongoose_interface.c | 9 +++++++-- 
> >  1 file changed, 7 insertions(+), 2 deletions(-) 
> > 
> > diff --git a/mongoose/mongoose_interface.c 
> b/mongoose/mongoose_interface.c 
> > index 4d2ab52..e3a990d 100644 
> > --- a/mongoose/mongoose_interface.c 
> > +++ b/mongoose/mongoose_interface.c 
> > @@ -347,10 +347,15 @@ static void upload_handler(struct mg_connection 
> *nc, int ev, void *p) 
> >                  ipc_end(fus->fd); 
> >   
> >                  mg_send_response_line(nc, 200, 
> > -                        "Content-Type: text/plain\r\n" 
> > +                        "Content-Type: application/json\r\n" 
> >                          "Connection: close"); 
> >                  mg_send(nc, "\r\n", 2); 
> > -                mg_printf(nc, "Ok, %s - %d bytes.\r\n", mp->file_name, 
> (int) fus->len); 
> > +                mg_printf(nc,        "{\r\n" 
> > +                                                "\t\"status\": 
> \"OK\",\r\n" 
> > +                                                "\t\"file-name\": 
> \"%s\",\r\n" 
> > +                                                "\t\"size\": \"%d 
> bytes\"\r\n" 
> > +                                                "}\r\n" 
> > +                                                , mp->file_name, (int) 
> fus->len); 
> >                  nc->flags |= MG_F_SEND_AND_CLOSE; 
> >   
> >                  mp->user_data = NULL; 
> > 
>
> -- 
> ===================================================================== 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk 
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany 
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de 
> <javascript:> 
> ===================================================================== 
>
Stefano Babic March 30, 2020, 9:46 a.m. UTC | #3
Hi Darko,

On 30.03.20 11:29, pharaon2502@gmail.com wrote:
> So when we POST our image to swupdate/upload, then we can wait for the
> return message, which was before
> 
> Ok, <image-name> <image-size>

Anyway, this interface is not published and restricted to the internal
Webserver. It is thought to work with the web-app in tree.

> 
> Hi,
> 
> With this we get it the response in json format, so it is easier to make
> a tool which just POSTs the image to the swupdate/upload and then just
> read the JSON return for information.
> 
> {
>     "status": "OK",
>     "file-name": "<name>",
>     "size": "<size> bytes"
> }
> 

Examples of such tools are already available, see for example
examples/client/swupdate-client.py in Python. The status is not
retrieved by the control interface, that should work as muxh as
"standard" as possible. To get thje status, the tool should open a
websocket connection to the Webserver and it gets JSON messages. See
also for a in-tree example handlers/swuforward_handler.c.

Best regards,
Stefano Babic

> BR,
> Darko
> 
> On Monday, March 30, 2020 at 10:26:18 AM UTC+2, Stefano Babic wrote:
> 
>     Hi Darko,
> 
>     On 28/03/20 14:30, 'Darko Komljenovic' via swupdate wrote:
>     > If image upload successful return status, file name and size in json
>     >
> 
>     It is not clear to me which issue should be addressed with this.
>     This is
>     an internal interface and it is interpreted just by the web-app. Which
>     is the intention here ?
> 
>     Best regards,
>     Stefano Babic
> 
>     > Signed-off-by: Darko Komljenovic <dkomlj...@zoho.com <javascript:>>
>     > ---
>     >  mongoose/mongoose_interface.c | 9 +++++++--
>     >  1 file changed, 7 insertions(+), 2 deletions(-)
>     >
>     > diff --git a/mongoose/mongoose_interface.c
>     b/mongoose/mongoose_interface.c
>     > index 4d2ab52..e3a990d 100644
>     > --- a/mongoose/mongoose_interface.c
>     > +++ b/mongoose/mongoose_interface.c
>     > @@ -347,10 +347,15 @@ static void upload_handler(struct
>     mg_connection *nc, int ev, void *p)
>     >                  ipc_end(fus->fd);
>     >  
>     >                  mg_send_response_line(nc, 200,
>     > -                        "Content-Type: text/plain\r\n"
>     > +                        "Content-Type: application/json\r\n"
>     >                          "Connection: close");
>     >                  mg_send(nc, "\r\n", 2);
>     > -                mg_printf(nc, "Ok, %s - %d bytes.\r\n",
>     mp->file_name, (int) fus->len);
>     > +                mg_printf(nc,        "{\r\n"
>     > +                                                "\t\"status\":
>     \"OK\",\r\n"
>     > +                                                "\t\"file-name\":
>     \"%s\",\r\n"
>     > +                                                "\t\"size\": \"%d
>     bytes\"\r\n"
>     > +                                                "}\r\n"
>     > +                                                , mp->file_name,
>     (int) fus->len);
>     >                  nc->flags |= MG_F_SEND_AND_CLOSE;
>     >  
>     >                  mp->user_data = NULL;
>     >
> 
>     -- 
>     =====================================================================
>     DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>     HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>     Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email:
>     sba...@denx.de <javascript:>
>     =====================================================================
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+unsubscribe@googlegroups.com
> <mailto:swupdate+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/2760f5cf-6bee-4551-8b8b-5216fc5d8a09%40googlegroups.com
> <https://groups.google.com/d/msgid/swupdate/2760f5cf-6bee-4551-8b8b-5216fc5d8a09%40googlegroups.com?utm_medium=email&utm_source=footer>.
diff mbox series

Patch

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 4d2ab52..e3a990d 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -347,10 +347,15 @@  static void upload_handler(struct mg_connection *nc, int ev, void *p)
 		ipc_end(fus->fd);
 
 		mg_send_response_line(nc, 200,
-			"Content-Type: text/plain\r\n"
+			"Content-Type: application/json\r\n"
 			"Connection: close");
 		mg_send(nc, "\r\n", 2);
-		mg_printf(nc, "Ok, %s - %d bytes.\r\n", mp->file_name, (int) fus->len);
+		mg_printf(nc,	"{\r\n"
+						"\t\"status\": \"OK\",\r\n" 
+						"\t\"file-name\": \"%s\",\r\n" 
+						"\t\"size\": \"%d bytes\"\r\n"
+						"}\r\n"
+						, mp->file_name, (int) fus->len);
 		nc->flags |= MG_F_SEND_AND_CLOSE;
 
 		mp->user_data = NULL;