Skip to content

Commit

Permalink
Implemented %http-header
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Phillips committed Aug 28, 2024
1 parent 31435c6 commit fc8eaf1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
13 changes: 12 additions & 1 deletion microemacs/doc/m5var013.5
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
.so me.tni
.TH %http-cookies 5
.XI %http-cookies - "Set HTTP request cookies"
.XI %http-header - "Set additional HTTP request headers"
.SH NAME
.Me "|%http-cookies"
%http-cookies \- Set HTTP request cookies
.br
.Me "|%http-header"
%http-header \- Set additional HTTP request headers
.Me $a
.SH SYNOPSIS
\fB%http-cookies\fR "\fIcookie=value; ...\fR"; Default is undefined
.br
\fB%http-header\fR "\fIHeader1: value1\\r\\n ...\fR"; Default is undefined
.SH DESCRIPTION
If the \fB%http-cookies\fR variable is set all HTTP file loading requests,
using commands like
Expand All @@ -23,8 +30,12 @@ value will be updated.
.PP
If the variable is not defined then no \fBCookie:\fR request header is sent and all response \fBSet-Cookie:\fR headers
are ignored.
.PP
If the \fB%http-header\fR variable is set, all HTTP file loading requests are sent with the variable value appended to
the end of the URL request header. The value is prefixed and suffixed with a '\fC\\r\\n\fR' newline, therefore if the value
starts, ends or contains double newline character sequences the URL request will be invalid.
.SH NOTES
The variable should take the form of "<name1>=<value1>; <name2>=<value2>; ...; <name#>=<value#>" with no trailing ';',
The \fB%http-cookies\fR variable should take the form of "<name1>=<value1>; <name2>=<value2>; ...; <name#>=<value#>" with no trailing ';',
names and values should be URL encoded.
.PP
As with variables like
Expand Down
1 change: 1 addition & 0 deletions microemacs/doc/m5var014.5
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Both variables cannot be used at the same time.
.na
.Ht %http-flags 5 ,
.Ht %http-cookies 5 ,
.Ht %http-header 5 ,
.Ht %http-proxy-addr 5 ,
.Ht find-file 2 ,
.Ht ftp 3 .
Expand Down
1 change: 1 addition & 0 deletions microemacs/doc/m5var049.5
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ must be compiled in for Windows versions.
.SH "SEE ALSO"
.na
.Ht %http-cookies 5 ,
.Ht %http-header 5 ,
.Ht %http-post-data 5 ,
.Ht %http-post-file 5 ,
.Ht %http-proxy-addr 5 ,
Expand Down
2 changes: 1 addition & 1 deletion microemacs/src/eextrn.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ extern int searchBuffer(int f, int n);

int
meSockHttpOpen(meIo *io, meUShort flags, meUByte *host, meInt port, meUByte *user, meUByte *pass, meUByte *file, meCookie *cookie,
meInt fdLen, meUByte *frmData, meUByte *postFName, meUByte *rbuff);
meUByte *hdr, meInt fdLen, meUByte *frmData, meUByte *postFName, meUByte *rbuff);


int
Expand Down
11 changes: 6 additions & 5 deletions microemacs/src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ ffFtpFileOpen(meIo *io, meUInt rwflag, meUByte *url, meBuffer *bp)
}

static int
ffHttpFileOpen(meIo *io, meUInt rwflag, meUByte *url, meCookie *cookie, meInt fdLen, meUByte *frmData, meUByte *postFName, meBuffer *bp)
ffHttpFileOpen(meIo *io, meUInt rwflag, meUByte *url, meCookie *cookie, meUByte *hdr, meInt fdLen, meUByte *frmData, meUByte *postFName, meBuffer *bp)
{
meUByte buff[meBUF_SOCK_SIZE_MAX], urlBuff[meBUF_SIZE_MAX], *hst, *prt, *usr, *psw, *ups=NULL, *fl, *dd, cc;
meUShort flags;
Expand Down Expand Up @@ -734,7 +734,7 @@ ffHttpFileOpen(meIo *io, meUInt rwflag, meUByte *url, meCookie *cookie, meInt fd
if(ffUrlGetInfo(io,&hst,&prt,&usr,&psw) <= 0)
return meFALSE;

if((ii=meSockHttpOpen(io,flags,hst,ii,usr,psw,fl,cookie,fdLen,frmData,postFName,buff)) < 0)
if((ii=meSockHttpOpen(io,flags,hst,ii,usr,psw,fl,cookie,hdr,fdLen,frmData,postFName,buff)) < 0)
return meFALSE;

if(ii == 0)
Expand Down Expand Up @@ -783,7 +783,7 @@ ffHttpFileOpen(meIo *io, meUInt rwflag, meUByte *url, meCookie *cookie, meInt fd
return meABORT;
return mlwrite(MWABORT|MWPAUSE,(meUByte *)"[Redirection loop to %s]",buff);
}
return ffHttpFileOpen(io,rwflag,dd,cookie,0,NULL,NULL,bp);
return ffHttpFileOpen(io,rwflag,dd,cookie,hdr,0,NULL,NULL,bp);
}
io->length = io->urlLen;
if(((rwflag & (meRWFLAG_READ|meRWFLAG_INSERT)) == meRWFLAG_READ) && (bp != NULL))
Expand Down Expand Up @@ -868,8 +868,9 @@ ffUrlFileOpen(meIo *io, meUInt rwflag, meUByte *url, meBuffer *bp)
{
meCookie *cookie;
meVariable *vp;
meUByte *s1, *s2, *cv;
meUByte *s1, *s2, *cv, *hdr;
meInt s1l;
hdr = ((vp = getUsrLclCmdVarP((meUByte *)"http-header",usrVarList)) == NULL) ? NULL:vp->value;
if(((vp = getUsrLclCmdVarP((meUByte *)"http-post-data",usrVarList)) == NULL) || ((s1=vp->value) == NULL) || ((s1l=meStrlen(s1)) == 0))
{
s1 = NULL;
Expand All @@ -894,7 +895,7 @@ ffUrlFileOpen(meIo *io, meUInt rwflag, meUByte *url, meBuffer *bp)
ffUrlCookie.buffLen = meStrlen(cv);
}
}
ii = ffHttpFileOpen(io,rwflag,url,cookie,s1l,s1,s2,bp);
ii = ffHttpFileOpen(io,rwflag,url,cookie,hdr,s1l,s1,s2,bp);
if((cookie != NULL) && (ffUrlCookie.value != cv))
vp->value = ffUrlCookie.value;
if(s1 != NULL)
Expand Down
6 changes: 4 additions & 2 deletions microemacs/src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ meSockReadLine(meIo *io, meUByte *buff)

int
meSockHttpOpen(meIo *io, meUShort flags, meUByte *host, meInt port, meUByte *user, meUByte *pass, meUByte *file, meCookie *cookie,
meInt fdLen, meUByte *frmData, meUByte *postFName, meUByte *rbuff)
meUByte *hdr, meInt fdLen, meUByte *frmData, meUByte *postFName, meUByte *rbuff)
{
meUByte *ss;
meInt pfs, ret, err, ll;
Expand Down Expand Up @@ -1601,6 +1601,8 @@ meSockHttpOpen(meIo *io, meUShort flags, meUByte *host, meInt port, meUByte *use
if(cookie->buffLen < 0)
cookie = NULL;
}
if((hdr != NULL) && (hdr[0] != '\0'))
ss += sprintf((char *) ss,"\r\n%s",hdr);
if(io->urlOpts & meSOCKOPT_LOG_DETAILS)
{
ss[0] = '\n';
Expand Down Expand Up @@ -1643,7 +1645,7 @@ meSockHttpOpen(meIo *io, meUShort flags, meUByte *host, meInt port, meUByte *use
if(io->urlOpts & meSOCKOPT_LOG_DETAILS)
ffSUrlLogger(io,meSOCKOPT_LOG_DETAILS,(meUByte *) "meSock Info: Closing connection as server shutdown");
meSockClose(io,1);
return meSockHttpOpen(io,flags,host,port,user,pass,file,cookie,fdLen,frmData,postFName,rbuff);
return meSockHttpOpen(io,flags,host,port,user,pass,file,cookie,hdr,fdLen,frmData,postFName,rbuff);
}
#endif
if(io->urlOpts & meSOCKOPT_LOG_ERROR)
Expand Down

0 comments on commit fc8eaf1

Please sign in to comment.