Browse Source

new forms.html

release/v0.1
jl777 9 years ago
parent
commit
cc8cb32691
  1. 4
      crypto777/OS_portable.h
  2. 8
      crypto777/iguana_OS.c
  3. 4
      iguana/field.html
  4. 12
      iguana/footer.html
  5. 19
      iguana/formfooter.html
  6. 16
      iguana/formheader.html
  7. 5024
      iguana/forms.html
  8. 49
      iguana/header.html
  9. 177
      iguana/iguana_json.c
  10. 4
      iguana/main.c
  11. 2
      pnacl_main.h

4
crypto777/OS_portable.h

@ -198,8 +198,8 @@ int32_t OS_openmap(struct OS_mappedptr *mp);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname);
void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,long size);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep);
void *OS_filestr(int64_t *allocsizep,char *fname);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);

8
crypto777/iguana_OS.c

@ -769,10 +769,10 @@ void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,lo
return(M->fileptr);
}
void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep)
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep)
{
FILE *fp;
int64_t filesize,buflen = *allocsizep;
long filesize,buflen = *allocsizep;
char *buf = *bufp;
*lenp = 0;
if ( (fp= fopen(OS_compatible_path(fname),"rb")) != 0 )
@ -805,9 +805,9 @@ void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep)
return(buf);
}
void *OS_filestr(int64_t *allocsizep,char *fname)
void *OS_filestr(long *allocsizep,char *fname)
{
int64_t filesize = 0; char *buf = 0;
long filesize = 0; char *buf = 0;
*allocsizep = 0;
return(OS_loadfile(fname,&buf,&filesize,allocsizep));
}

4
iguana/field.html

@ -0,0 +1,4 @@
<div class=\"form-group\">
<label for=\"%s\">%s</label>
<textarea class=\"form-control\" name=\"%s\" rows=\"1\" cols=\"%s\" %s></textarea>
</div>

12
iguana/footer.html

@ -0,0 +1,12 @@
</div>
</div>
<!-- API fileds -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body></html>

19
iguana/formfooter.html

@ -0,0 +1,19 @@
</div>
<div class=\"col-md-6\">
<div class=\"form-group\">
<label for=\"broadcast\">Response</label>
<figure class=\"highlight\" for=\"%s\" disabled=\"\">
<pre>
<code id=\"%s\" class=\"language-html\" data-lang=\"javascript\"></code>
</pre>
</figure>
</div>
</div>
</div>
<input type=\"submit\" value=\"%s\" class=\"btn btn-default\">
</form>
</div>
</div>
</div>

16
iguana/formheader.html

@ -0,0 +1,16 @@
<div class=\"panel panel-default\">
<div class=\"panel-heading\" role=\"tab\" id=\"heading-%s\">
<h4 class=\"panel-title\">
<a class=\"collapsed\" role=\"button\" data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapse-%s\" aria-expanded=\"false\" aria-controls=\"collapse-%s\">
%s %s
</a>
</h4>
</div>
<div id=\"collapse-%s\" class=\"panel-collapse collapse\" role=\"tabpanel\" aria-labelledby=\"heading-%s\">
<div class=\"panel-body\">
<form action=\"http://127.0.0.1:7778/api/%s/%s\" oninput=\"%s\">
<div class=\"row\">
<div class=\"col-md-6\">

5024
iguana/forms.html

File diff suppressed because it is too large

49
iguana/header.html

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>SuperNET API></title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar navbar-default" role="navigation">
<div class="container" style="min-width: 90%;">
<div class="navbar-header">
<a class="navbar-brand" href="#">SuperNET API</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://phabricator.supernet.org/w/" target="_blank" style="margin-left:20px;">Developer Wiki</a></li>
</ul>
</div>
</div>
</div>
<!-- Navigation Bar -->
<!-- API fileds -->
<div class="container" style="min-width: 90%">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

177
iguana/iguana_json.c

@ -213,26 +213,150 @@ int32_t agentform(FILE *fp,char *form,int32_t max,char *agent,cJSON *methoditem)
return((int32_t)strlen(form));
}
/*<form action="action_page.asp"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>*/
char *SuperNET_htmlstr(FILE *fp,char *htmlstr,int32_t max,char *agentstr)
#define HTML_EMIT(str,n) memcpy(&retbuf[size],str,n), size += (n)
int32_t template_emit(char *retbuf,int32_t maxsize,char *template,char *varname,char *value)
{
int32_t i,n,len,size = 0; cJSON *helpjson,*item,*array; char *str;
int32_t offset,valuelen,varnamelen,position,size = 0; char *match;
offset = 0;
valuelen = (int32_t)strlen(value);
varnamelen = (int32_t)strlen(varname);
while ( (match= strstr(varname,&template[offset])) != 0 )
{
position = (int32_t)((long)match - (long)&template[offset]);
printf("found match.(%s) at %d offset.%d\n",varname,position,offset);
if ( size + (valuelen + position) > maxsize )
return(-1);
HTML_EMIT(&template[offset],position), offset += position + varnamelen;
HTML_EMIT(value,valuelen);
}
HTML_EMIT(&template[offset],strlen(&template[offset])+1);
return(size);
}
#define MAX_TEMPLATESIZE 32768
int32_t templates_emit(char *retbuf,int32_t maxsize,char *template,char *agent,char *method,char *fieldnames,char *fieldnames2)
{
char buf[MAX_TEMPLATESIZE+4096];
strcpy(buf,template);
template_emit(retbuf,maxsize,buf,"$AGENT",agent), strcpy(buf,retbuf);
template_emit(retbuf,maxsize,buf,"$METHOD",method), strcpy(buf,retbuf);
template_emit(retbuf,maxsize,buf,"$FIELDNAMES",fieldnames), strcpy(buf,retbuf);
return(template_emit(retbuf,maxsize,buf,"$FIELDNAMES2",fieldnames2));
}
int32_t pretty_form(FILE *fp,char *formheader,char *formfooter,char *fieldtemplate,char *agent,cJSON *methoditem)
{
cJSON *item,*fieldsarray; int32_t j,m,formsize,fieldsize,iter,width,size = 0;
char *methodstr,*typestr,*fieldname;
char outstr[2048],outstr2[2048],str[2],widthstr[16];
if ( (methodstr= jstr(methoditem,"method")) == 0 )
methodstr = "method";
if ( agent == 0 )
agent = "agent";
outstr[0] = outstr2[0] = str[1] = 0;
formsize = fieldsize = 0;
if ( (fieldsarray= jarray(&m,methoditem,"fields")) != 0 )
{
for (iter=0; iter<2; iter++)
{
if ( iter == 1 )
fprintf(fp,formheader,methodstr,methodstr,methodstr,agent,methodstr,methodstr,methodstr,agent,methodstr,outstr);
for (j=0; j<m; j++)
{
item = jitem(fieldsarray,j);
fieldname = get_cJSON_fieldname(item);
// printf("item.(%s) %s\n",jprint(item,0),jstr(item,fieldname));
if ( iter == 0 )
{
if ( j > 0 )
{
strcat(outstr,"+");
strcat(outstr2," ");
}
strcat(outstr,fieldname);
strcat(outstr2,fieldname);
}
else
{
if ( (typestr= jstr(item,fieldname)) != 0 )
{
if ( strcmp(typestr,"string") == 0 )
width = 44;
else if ( strcmp(typestr,"hash") == 0 )
width = 65;
else if ( strcmp(typestr,"int") == 0 )
width = 12;
else if ( strcmp(typestr,"float") == 0 )
width = 24;
else if ( strcmp(typestr,"u64bits") == 0 )
width = 24;
else width = 0;
}
sprintf(widthstr,"%d",width);
fprintf(fp,fieldtemplate,fieldname,fieldname,fieldname,widthstr,fieldname);
}
}
if ( iter == 1 )
fprintf(fp,formfooter,outstr2,methodstr,methodstr);
}
}
return(size);
}
int32_t pretty_forms(char *fname,char *agentstr)
{
char *str,*header,*footer,*formheader,*formfooter,*field; long allocsize; FILE *fp;
int32_t i,n,len,err=0,size = 0; cJSON *helpjson,*array,*item;
header = OS_filestr(&allocsize,"header.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
footer = OS_filestr(&allocsize,"footer.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
formheader = OS_filestr(&allocsize,"formheader.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
formfooter = OS_filestr(&allocsize,"formfooter.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
field = OS_filestr(&allocsize,"field.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
fp = fopen(fname,"w");
if ( fp != 0 && err == 0 && header != 0 && footer != 0 && formheader != 0 && formfooter != 0 && field != 0 )
{
//HTML_EMIT(header,strlen(header));
fprintf(fp,"%s\n",header);
if ( (helpjson= SuperNET_helpjson()) != 0 )
{
if ( (array= jarray(&n,helpjson,"API")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
str = jstr(item,"agent");
if ( agentstr == 0 || agentstr[0] == 0 || (str != 0 && strcmp(str,agentstr) == 0) )
{
len = pretty_form(fp,formheader,formfooter,field,str!=0?str:"agent",item);
size += len;
} //else printf("agentstr.%p (%s) (%s) str.%p \n",agentstr,agentstr,str,str);
}
}
free_json(helpjson);
}
fprintf(fp,"%s\n",footer);
fclose(fp);
//HTML_EMIT(footer,strlen(footer));
}
if ( header != 0 ) free(header);
if ( footer != 0 ) free(footer);
if ( formheader != 0 ) free(formheader);
if ( formfooter != 0 ) free(formfooter);
if ( field != 0 ) free(field);
return(size);
}
#undef HTML_EMIT
char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr)
{
int32_t i,n,len,size = 0; cJSON *helpjson,*item,*array; char *str; FILE *fp = 0;
htmlstr[0] = 0;
sprintf(htmlstr,"<!DOCTYPE HTML><html> <head><title>SuperUGLY GUI></title></head> <body> ");
if ( fp != 0 )
fprintf(fp,"%s\n",htmlstr);
if ( pretty_forms(fname,agentstr) != 0 )
{
printf("%s\n",htmlstr);
return(htmlstr);
}
sprintf(htmlstr,"<!DOCTYPE HTML><html> <head><title>SuperUGLY GUI></title></head> <body> ");
size = (int32_t)strlen(htmlstr);
if ( (helpjson= SuperNET_helpjson()) != 0 )
{
@ -244,7 +368,7 @@ char *SuperNET_htmlstr(FILE *fp,char *htmlstr,int32_t max,char *agentstr)
str = jstr(item,"agent");
if ( agentstr == 0 || agentstr[0] == 0 || (str != 0 && strcmp(str,agentstr) == 0) )
{
len = agentform(fp,&htmlstr[size],max - size,str!=0?str:"agent",item);
len = agentform(fp,&htmlstr[size],maxsize - size,str!=0?str:"agent",item);
size += len;
} //else printf("agentstr.%p (%s) (%s) str.%p \n",agentstr,agentstr,str,str);
}
@ -252,8 +376,6 @@ char *SuperNET_htmlstr(FILE *fp,char *htmlstr,int32_t max,char *agentstr)
free_json(helpjson);
}
strcat(htmlstr,"<br><br/></body></html><br><br/>");
if ( fp != 0 )
fprintf(fp,"<br><br/></body></html><br><br/>\n");
printf("<br><br/></body></html><br><br/>\n");
return(htmlstr);
}
@ -549,19 +671,18 @@ ZERO_ARGS(SuperNET,help)
TWO_STRINGS(SuperNET,html,agentform,htmlfile)
{
char *htmlstr; cJSON *retjson; FILE *fp; int32_t max = 4*1024*1024;
char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024;
if ( htmlfile == 0 || htmlfile[0] == 0 )
htmlfile = "uglyform.html";
if ( (fp= fopen(htmlfile,"w")) == 0 )
printf("error opening htmlfile.(%s)\n",htmlfile);
htmlfile = "forms.html";
//if ( (fp= fopen(htmlfile,"w")) == 0 )
// printf("error opening htmlfile.(%s)\n",htmlfile);
htmlstr = malloc(max);
htmlstr = SuperNET_htmlstr(fp,htmlstr,max,agentform);
htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",htmlstr);
jaddstr(retjson,"htmlfile",htmlfile);
free(htmlstr);
if ( fp != 0 )
fclose(fp);
//if ( fp != 0 )
// fclose(fp);
return(jprint(retjson,1));
}

4
iguana/main.c

@ -270,7 +270,7 @@ void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func
void iguana_main(void *arg)
{
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; int64_t allocsize;
FILE *fp; cJSON *json; uint8_t *space,secretbuf[512]; uint32_t r; long allocsize;
char helperstr[64],fname[512],*wallet2,*wallet2str,*tmpstr,*confstr,*helperargs,*ipaddr,*coinargs=0,*secret,*jsonstr = arg;
int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub;
memset(&MYINFO,0,sizeof(MYINFO));
@ -461,7 +461,7 @@ void iguana_main(void *arg)
iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,iguana_coinadd("BTCD"),IGUANA_PERMTHREAD);
if ( coinargs != 0 )
iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
else if ( 0 )
else if ( 1 )
{
#ifdef __APPLE__
sleep(1);

2
pnacl_main.h

@ -24,7 +24,7 @@ void PNACL_message(const char* format, ...);
#endif
void OS_init();
void *OS_filestr(int64_t *allocsizep,char *fname);
void *OS_filestr(long *allocsizep,char *fname);
char *clonestr(char *);
void CHROMEAPP_MAIN(void *arg);

Loading…
Cancel
Save