-// files (-1 for URL)
+// files
.float url_fh;
+#define URL_FH_CURL -1
+#define URL_FH_STDOUT -2
// URLs
.string url_url;
url_fromid[id] = world;
// if we get here, we MUST have both buffers cleared
- if(e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != -1)
+ if(e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != URL_FH_CURL)
error("url_URI_Get_Callback: not a request waiting for data");
if(status == 0)
e = spawn();
e.classname = "url_fopen_file";
e.url_url = strzone(url);
- e.url_fh = -1;
+ e.url_fh = URL_FH_CURL;
e.url_wbuf = buf_create();
if(e.url_wbuf < 0)
{
e = spawn();
e.classname = "url_fopen_file";
e.url_url = strzone(url);
- e.url_fh = -1;
+ e.url_fh = URL_FH_CURL;
e.url_rbuf = -1;
e.url_wbuf = -1;
e.url_ready = rdy;
break;
}
}
+ else if(url == "-")
+ {
+ switch(mode)
+ {
+ case FILE_WRITE:
+ case FILE_APPEND:
+ e = spawn();
+ e.classname = "url_fopen_stdout";
+ e.url_fh = URL_FH_STDOUT;
+ rdy(e, pass, URL_READY_CANWRITE);
+ break;
+ case FILE_READ:
+ print("url_fopen: cannot open '-' for reading\n");
+ rdy(world, pass, URL_READY_ERROR);
+ break;
+ }
+ }
else
{
float fh;
{
float i;
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_rbuf == -1 || e.url_wbuf != -1) // not(post GET/POST request)
if(e.url_rbuf != -1 || e.url_wbuf == -1) // not(pre POST request)
remove(e);
}
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ remove(e);
+ }
else
{
// file
// with \n (blame FRIK_FILE)
string url_fgets(entity e)
{
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_rbuf == -1)
error("url_fgets: not readable in current state");
e.url_rbufpos += 1;
return s;
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ // stdout
+ return string_null;
+ }
else
{
// file
// without \n (blame FRIK_FILE)
void url_fputs(entity e, string s)
{
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_wbuf == -1)
error("url_fputs: not writable in current state");
bufstr_set(e.url_wbuf, e.url_wbufpos, s);
e.url_wbufpos += 1;
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ // stdout
+ print(s);
+ }
else
{
// file