Пример #1
0
/*
 * copy a chunk containing only frequencies between flo and fhi into stream.
 */
void BandPassFilterFFT::band_pass(uint8_t *stream, double flo, double fhi)
{
	double band_data[2*samples];
	band_window(band_data, ffind(fhi)+1, ffind(flo));
	//writef(band_data, "test.dat");
	fft_inverse(band_data, stream);
}
Пример #2
0
void Animation_Start (void) {
	FILE *file = fopen(AnimationFileName,"r");
	FINFO file_info;
	file_info.fileID = 0;

	CurrentAnimationEffect = 0;
	DelayValue = 0;
	
	if (file != NULL) {
			if (ffind(AnimationFileName, &file_info) == 0) {
				AnimationFileSize = file_info.size;

				if (AnimationFileSize >= sizeof(LED_CUBE_Effect)) {
					ANIMATION_PLAY = TRUE;
					
					AnimationEffectsCount = (AnimationFileSize / sizeof(LED_CUBE_Effect));
					
					Animation_Read_Effect();					
				} else {
					ANIMATION_PLAY = FALSE;
					AnimationFileName = "";
				}
			} else {
				ANIMATION_PLAY = FALSE;
				AnimationFileName = "";
			}

		fclose(file);
	} else {
		ANIMATION_PLAY = FALSE;
		AnimationFileName = "";
	}

	SETTINGS_Save();
}
Пример #3
0
NxI32 deleteFiles(const String &str)
{
  WildCard *wild = createWildCard(str.c_str());
  StringVector list;
  if ( isWild(wild) )
  {
    FileFind ffind(wild);
    ffind.GetFiles(list);
  }
  else
  {
    list.push_back(str);
  }

  StringVector::iterator i;

  for (i=list.begin(); i!=list.end(); ++i)
  {
#ifdef WIN32
    DeleteFileA( (*i).c_str() );
#endif
#ifdef LINUX_GENERIC
    assert(0); // not implemented on unix yet, not needed though.
#endif
  }
  releaseWildCard(wild);

  NxI32 ret = list.size();

  return ret;
}
Пример #4
0
void SPI_FLASH_Delete_All_Files (void) {
	FINFO file_info;
	file_info.fileID = 0;
	
	while(ffind("*.*", &file_info) == 0) {
		fdelete((const char*)file_info.name); 
	}
}
Пример #5
0
void main()
  {
    int day, year;
    char weekday[10], month[12];

    ffind( stdin,
            "%s %s %d %d",
            weekday, month, &day, &year );
    printf( "\n%s, %s %d, %d\n",
            weekday, month, day, year );
  }
Пример #6
0
U32 http_finfo (U8 *fname) {
  /* Read last modification time of a file. Return lm time in UTC format. */
  FINFO *info;
  U32 utc;

  info = (FINFO *)alloc_mem (sizeof (FINFO));
  info->fileID = 0;
  utc = 0;
  if (ffind ((const char *)fname, info) == 0) {
    /* File found, save creation date in UTC format. */
    utc = http_date (&info->time);
  }
  free_mem ((OS_FRAME *)info);
  return (utc);
}
Пример #7
0
fpargs() {
	register int i;
	
	switch(args[0]) {
	case 'p':
	case '\0':
		fprint();
		break;
case 'w':
		i = fline;
		fback(WINDOW/2);
		fprintn(WINDOW);
		ffind(i);
		break;
	case 'z':
		fprintn(WINDOW);
		break;
	}
}
Пример #8
0
int
do_symbolic(
        int argc,
        char **argv )
{
	int i, nsyms, isflag;
	unsigned long j;
	struct symarray syms[50];
	struct memtbl *tbl;
	char *p;
	char *type = NULL;
        char * errmsg;

	nsyms = 0;
	isflag = 0;
	for (i = 1; (i < argc) && argv[i]; i++) {
		if (argv[i][0] == '-') {
			for (j = 1; argv[i][j]; j++) {
				switch(argv[i][j]) {
				case 'm':
					isflag = 1;
					break;
				case 't':
					if (argv[i][j + 1])
						type = argv[i] + j + 1;
					else
						type = argv[++i];
					j = strlen(argv[i]) - 1;
					break;
				}
			}
		}
		else {
			syms[nsyms++].str = argv[i];
			if (nsyms == 50)
				break;
		}
	}
	if ((type == NULL) || (!nsyms)) {
		XK_USAGE(argv[0]);
	}
	if (p = strchr(type, '.')) {
		*p = '\0';
		if ((tbl = all_tbl_search(type, 0)) == NULL) {
			*p = '.';
                        errmsg = strdup(GetSharedMsg(DT_UNDEF_TYPE));
			printerrf(argv[0], errmsg, type, NULL, NULL,
                                  NULL, NULL, NULL, NULL, NULL);
                        free(errmsg);
			return(SH_FAIL);
		}
		if ((tbl = ffind(tbl, p + 1, NULL)) == NULL) {
                        errmsg=strdup(GETMESSAGE(13,1, 
                           "Unable to locate a field named '%s' for the type '%s'"));
			printerrf(argv[0], errmsg, p + 1, type, NULL,
                                  NULL, NULL, NULL, NULL, NULL);
                        free(errmsg);
			*p = '.';
			return(SH_FAIL);
		}
		*p = '.';
	}
	else if ((tbl = all_tbl_search(type, 0)) == NULL) {
                errmsg = strdup(GetSharedMsg(DT_UNDEF_TYPE));
		printerrf(argv[0], errmsg, type, NULL, NULL,
                          NULL, NULL, NULL, NULL, NULL);
                free(errmsg);
		return(SH_FAIL);
	}
		
	for (i = 0; i < nsyms; i++) {
		if (!fdef(syms[i].str, &j)) {
                        errmsg=strdup(GETMESSAGE(13,2, 
                               "The name '%s' has not been defined"));
			printerrf(argv[0], errmsg, syms[i].str,
                                  NULL, NULL, NULL, NULL, NULL, NULL, NULL);
                        free(errmsg);
			return(SH_FAIL);
		}
		syms[i].str = strdup(syms[i].str);
		syms[i].addr = j;
	}
	add_symbolic(isflag, tbl, syms, nsyms);
	return(SH_SUCC);
}
Пример #9
0
docommand() {
	register char	*p;
	register int	i;
	register ADDR	addr, bkaddr;
	struct proct 	*procp;
	char s[4];
	
	cntval = 1;
	adrflg = 0;
	errflg = 0;

	if (scallf) {
		doscall();
		setcur(1);
		lastcom = NOCOM;
		return;
	}
	
	if (reflag) {  /* search for regular expression */
		dore();
		lastcom = PRCOM;
		return;
	}
	
	if (cmd == '\0') {
		if (integ != 0 && var[0] != '\0') {
			error("Invalid command (1)");
			return;
		}
		if (integ != 0) { /* print line number */
			ffind(integ);
			fprint();
			lastcom = PRCOM;
			return;
		}
		if (var[0] != 0) {
			printf("Unexpected null command\n");
			return;
		}
	}
		
	switch (cmd) {
	
	case 'Y':
		debug = !debug;
		break;

	case 'V':
		version();
		break;

	case 'M':
		if (args[0]) {
			setmap(args);
		} else {
			printmap("? map", &txtmap);
			printmap("/ map", &datmap);
		}
		break;

	case 'x':
		printregs();
		break;

	case 'X':
		printpc();
		break;

	case 'a':
		if (integ) {
			cpstr(args, "l\n");
		} else if (proc[0]) {
			cpall(args, "T\n");
		} else {
			error("Bad arguments");
			break;
		}
		goto setbrk;
		break;	

	case 'l':
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'T':
		prfrx(1);
		lastcom = NOCOM;
		break;
		
	case 't':
		prframe();
		lastcom = NOCOM;
		break;
		
	case 'e':
		p = args;
		if (*p == '\0') {
#ifndef FLEXNAMES
			printf("%.16s() in \"%s\"\n",
				curproc()->pname, curfile);
#else
			printf("%s() in \"%s\"\n",
				curproc()->pname, curfile);
#endif
			break;
		}

		while (*p != '\0')
			if (*p++ == '.') goto l1;
		/* argument is procedure name */
		procp = findproc(args);
		if ((procp->pname[0] != '\0') && (procp->sfptr != badfile)) {
			finit(adrtofilep(procp->paddr)->sfilename);
			ffind(procp->lineno);
		}
		else printf("Can't find %s\n", args);
#ifndef FLEXNAMES
		printf("%.16s() in \"%s\"\n", curproc()->pname, curfile);
#else
		printf("%s() in \"%s\"\n", curproc()->pname, curfile);
#endif
		lastcom = PRCOM;
		break;
		
	l1:	/* argument is filename */
		finit(args);
		printf("\"%s\"\n", curfile);
		lastcom = PRCOM;
		break;
		
	case 'p':
		if (integ) ffind(integ);
		fprint();
		lastcom = PRCOM;
		break;
		
	case 'q':
		exit(0);
		
	case 'w':
		if (integ) ffind(integ);
		i = fline;
		fback(WINDOW/2);
		fprintn(WINDOW);
		ffind(i);
		lastcom = PRCOM;
		break;
		
	case 'Q':
		prdebug();
		break;

	case 'z':
		if (integ) ffind(integ);
		fprintn(WINDOW);
		lastcom = PRCOM;
		break;

	case '-':
		fback(integ ? integ : 1);
		fpargs();
		lastcom = PRCOM;
		break;

	case '+':
		fforward(integ ? integ : 1);
		fpargs();
		lastcom = PRCOM;
		break;

	case '\n':
		switch (lastcom) {
		case PRCOM:
			fforward(1);
			fprint();
			break;
		case DSCOM:
			oaddr += oincr ? oincr : typetosize(otype, WORDSIZE);
			printf("0x%x/ ", oaddr);
			dispf((ADDR) oaddr, odesc,
			    oclass == N_RSYM ? oclass : N_GSYM, otype, 0, 0, DSP);
			break;
		case DSICOM:
			dot += oincr;
			prisploc();
			dispi(dot, odesc, N_GSYM, 0, 0);
			break;
		}
		break;

	case '\004':
		if (!isatty(0))
			exit(0);
		switch (lastcom) {
		case PRCOM:
			fforward(1);
			printf("\b");
			fprintn(WINDOW);
			lastcom = PRCOM;
			break;
		case DSICOM:
			printf("\b");
			for (i=0; i<WINDOW; i++) {
				dot += oincr;
				prisploc();
				if (dispi(dot, odesc, N_GSYM, 0, 0) == -1)
					break;
			}
			break;
		case DSCOM:
			printf("\b");
			for (i=0; i<WINDOW; i++) {
				oaddr += oincr ?
					oincr : typetosize(otype, WORDSIZE);
				printf("0x%x/ ", oaddr);
				if (dispf((ADDR) oaddr, odesc,
					oclass == N_RSYM ? oclass :
					N_GSYM, otype, 0, 0, DSP) == -1)
					break;
			}
			break;
		default:
			printf("\n");
		}
		break;

	case 'r':
		if (args[0] == '\0') getargs();
	case 'R':
		signo = 0;
		cpstr(oldargs, args);
		if (debug) error("calling dopcs");
		if (integ) cntval = integ;
		if (!executing) {
			executing = TRUE;
			if (integ) cntval = integ;
			dopcs('r');
			executing = FALSE;
		}
		if (debug) error("exiting dopcs");
		bkaddr = -1;
		goto f1;

	case 'c':
		signo = 0;
	case 'C':
		if (proc[0] != '\0' || integ != 0) {
			setdot();
			if (dot == -1) {
				error("Cannot set temporary breakpoint");
				break;
			}
			dopcs('b');
			bkaddr = dot;
		} else
			bkaddr = -1;
		integ = atoi(args);

f1:		if (debug) error("calling dopcs");
		if (integ) cntval = integ;
		dopcs('c');
		if (debug) error("exiting dopcs");
		if (bkaddr != -1) {
			ADDR dotsave;
			dotsave = dot;
			dot = bkaddr;
			dopcs('d');
			dot = dotsave;
		}
		if (!signo) printf("Breakpoint");
		printf(" at\n");
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'S':
	case 's':
		signo = 0;
		integ = atoi(args);
		singstep(integ ? integ : 1, cmd);
		if (signo) printf("\n");
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case 'g':
		if (pid == 0  ||  signo) {
			error("Not stopped at breakpoint");
			break;
		}
		setdot();
		if (dot == -1) {
			error("Bad address");
			break;
		}
		adrflg = 1;
		integ = atoi(args);
		if (integ) cntval = integ;
		dopcs('c');
		if (!signo) printf("Breakpoint");
		printf(" at\n");
		setcur(1);
		lastcom = NOCOM;
		break;

	case 'k':
		if (scallx) {
	 		userpc = dot = *(ADDR *)(((ADDR)&u)+PC) = pcs;
	 		*(ADDR *)(((ADDR)&u)+FP) = fps;
	 		*(ADDR *)(((ADDR)&u)+AP) = aps;
			if (bkpts)
				bkpts->flag = flagss;
			scallx = 0;
			error("Procedure killed");
			longjmp(env, 0);
		} else {
			dopcs('k');
			printf("\n");
			lastcom = NOCOM;
			break;
		}

	case 'B':
		prbkpt();
		break;

	case 'b':
	setbrk:
		if (proc[0] == '\0' && integ == 0) {
			integ = fline;
		}
		setdot();
		if (dot == -1 || dot == 0) {
			error("Cannot set breakpoint");
			break;
		}
		dopcs('b');
		s[0] = ' ';
		s[1] = cmd;
		s[2] = '\n';
		s[3] = 0;
		s[1] = cmd;
		printbkpt(s, adrtoprocp(dot), dot);
		break;
		
	case 'd':
		if (proc[0] == '\0' && integ == 0) {
			idbkpt();
			break;
		}
		setdot();
		if (dot == -1) {
			error("Non existent breakpoint");
			break;
		}
		dopcs('d');
		break;
		
	case 'D':
		dabkpt();
		error("All breakpoints deleted");
		break;

	case 'm':
		addr = varaddr(proc[0] ? proc : curproc()->pname, var);
		printf("stopped with value %d\n", monex(addr, 'd'));
		setcur(1);
		lastcom = NOCOM;
		break;
		
	case '?':
		if (!(var[0] == '.' && var[1] == '\0'))
			setdot();
		if (errflg) {
			error(errflg);
			break;
		}
		prisploc();
		dispi(dot, args[0] ? args : "i", N_GSYM, 0, 0);
		lastcom = DSICOM;
		break;

	case '/':
		if (var[0] == '.' && var[1] == '\0') {
			if (integ == 0) integ = oaddr;
			dispf((ADDR) integ, args[0] ? args : odesc,
			    oclass == N_RSYM ? oclass : N_GSYM, otype, 0, 0, DSP);
			oaddr = integ;
		} else
		if (integ && (var[0] == '\0')) {
			dispf((ADDR) integ, args, N_GSYM, 0, 0, 0, DSP);
			oaddr = integ;
			cpstr(odesc, args);
			oclass = N_GSYM;
			otype = 0;
		} else
			dispvar(proc, var, args);
		lastcom = DSCOM;
		break;
		
	case '=':
		if (var[0] == '\0') {
			if (proc[0]) {
				addr = getaddr(proc, integ);
				if (addr == -1) {
					error("Unknown address");
					break;
				}
			}
			else
				addr = integ;
			dispf(addr, args[0] ? args : "x", 0, -1, 0, 0, DSP);
		} else 
			findvar(proc, var, args[0] ? args : "x", 2);
		break;

	case '!':
		if (var[0] == '\0')
			addr = getaddr(proc, integ);
		else
			addr = varaddr(proc, var);
		if (addr == -1) 
			error("Unknown variable");
		else {
			if (number(args[0]) || eqany(args[0], ".-")) {
				char *p;
				double atof();
				union {
					struct{
						int w1, w2;
					} ww;
					double d;
				} dbl;

				p = (args[0] == '-') ? args+1 : args;
				for (; *p != '.' && *p != 'e'; p++) {
					if (!number(*p)) goto l2;
				}
				dbl.d = atof(args);
				putval(addr, 'd', dbl.ww.w1);
				if (typetodesc(sl_type,0)[0] == 'g')
					putval(addr+WORDSIZE, 'd', dbl.ww.w2);
				break;
			}
l2:			if (percentflag)
				*(ADDR *)(((ADDR)&u)+addr) = argvalue(args);
			else if (sl_class == N_RSYM && addr < 16)
				putreg(addr,typetodesc(sl_type,subflag)[0],
						argvalue(args));
			else
				putval(addr,typetodesc(sl_type,subflag)[0],
						argvalue(args));
		}
		lastcom = NOCOM;
		break;

	case '"':
		printf(args);
		break;
	}
}
Пример #10
0
int main() {
  char lstr[8][64];
  char buffer[80];
  char verb[80];
  char wd[512];
  int len;
  int prog;
  int selected_sbuffer = 0;

  while (1) {
    iwrites("wsh-");
    fgetwd(wd);
    iwrites(wd);
    iwrites("> ");
    ireads(buffer, 80);
    len = sfindc(buffer, ' ');
    if (len < 0)
      len = slength(buffer);
    scopy(verb, buffer, len);
    if (!scompare(verb, "help")) {
      iwrites("\ncat: print file contents\ncd: change directories\necho: print a string\nhelp: display this message\nls: list files\npwd: print current working directory\nloads: load a string to be used with all commands which act upon strings\nprintf: write to a pre-existing file\nprints: print the currently loaded string\nrms: unload the currently loaded string\ncons: concatenate a string to the end of the currently loaded string\nloadfs: load the contents of a file into the String Buffer\nchsf: switch to the next String Buffer\nchsb: switch to the previous String Buffer\npsb: print the currently selected String Buffer\nreboot: reboot the operating system\n\n");
    }
    else if (!scompare(verb, "ls")) {
      ls();
    }
    else if (!scompare(verb, "cd")) {
      cd(buffer + len + 1);
    }
    else if (!scompare(verb, "cat")) {
      /* Mrew? */
      cat(buffer + len + 1);
    }
    else if  (!scompare(verb, "echo")){
      echo(buffer + len + 1);
    }
    else if  (!scompare(verb, "pwd")){
      pwd();
    }
    else if (!scompare(verb, "reboot")) {
      ireboot();
    }
    else if (!scompare(verb, "printf")) {
      printf(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "loads")) {
      loads(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "prints")) {
      iwrites(lstr[selected_sbuffer]);
      iwrites("\n");
    }
    else if (!scompare(verb, "rms")) {
      scopy(lstr[selected_sbuffer], "\0", 1);
    }
    else if (!scompare(verb, "loadfs")) {
      loadfs(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "cons")) {
      cons(buffer + len + 1, lstr[selected_sbuffer]);
    }
    else if (!scompare(verb, "chsf")) {
      selected_sbuffer = chsf(selected_sbuffer);
    }
    else if (!scompare(verb, "psb")) {
      psb(selected_sbuffer);
    }
    else if (!scompare(verb, "chsb")) {
      selected_sbuffer = chsb(selected_sbuffer);
    }
    /*
    else if (!scompare(verb, "mk")) {
      mk(buffer + len + 1);
    }
    */
    else if (sfindc(verb, '/') == -1) {
      prog = fget("/bin/");
      if (!prog) {
        iwrites("Error: unable to locate bin directory\n");
        continue;
      }
      prog = ffind(prog, verb);
      if (!prog) {
        iwrites("Error: unrecognized command \"");
        iwrites(verb);
        iwrites("\"\n");
        continue;
      }
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else if (prog = fget(verb)) {
      if (fgettype(prog) == 2)
        iexec(prog);
      else {
        iwrites("Error: file is not executable\n");
        continue;
      }
    }
    else {
      iwrites("Error: executable not found\n");
      continue;
    }
  }
}
Пример #11
0
/*----------------------------------------------------------------------------
 *        Print a Flash Memory Card Directory
 *---------------------------------------------------------------------------*/
static void cmd_dir (char *par) {
  U32 fsize,files,dirs,i;
  char temp[32],*mask,*next,ch;
  FINFO info;

  mask = get_entry (par, &next);
  if (mask == NULL) {
    mask = "*.*";
  }

  printf ("\nFile System Directory...");
  files = 0;
  dirs  = 0;
  fsize = 0;
  info.fileID  = 0;
  while (ffind (mask,&info) == 0) {
    if (info.attrib & ATTR_DIRECTORY) {
      i = 0;
      while (strlen((const char *)info.name+i) > 41) {
        ch = info.name[i+41];
        info.name[i+41] = 0;
        printf ("\n%-41s", &info.name[i]);
        info.name[i+41] = ch;
        i += 41;
      }
      printf ("\n%-41s    <DIR>       ", &info.name[i]);
      printf ("  %02d.%02d.%04d  %02d:%02d",
               info.time.day, info.time.mon, info.time.year,
               info.time.hr, info.time.min);
      dirs++;
    }
    else {
      dot_format (info.size, &temp[0]);
      i = 0;
      while (strlen((const char *)info.name+i) > 41) {
        ch = info.name[i+41];
        info.name[i+41] = 0;
        printf ("\n%-41s", &info.name[i]);
        info.name[i+41] = ch;
        i += 41;
      }
      printf ("\n%-41s %14s ", &info.name[i], temp);
      printf ("  %02d.%02d.%04d  %02d:%02d",
               info.time.day, info.time.mon, info.time.year,
               info.time.hr, info.time.min);
      fsize += info.size;
      files++;
    }
  }
  if (info.fileID == 0) {
    printf ("\nNo files...");
  }
  else {
    dot_format (fsize, &temp[0]);
    printf ("\n              %9d File(s)    %21s bytes", files, temp);
  }
  dot_format (ffree(""), &temp[0]);
  if (dirs) {
    printf ("\n              %9d Dir(s)     %21s bytes free.\n", dirs, temp);
  }
  else {
    printf ("\n%56s bytes free.\n",temp);
  }
}
Пример #12
0
U16 ftp_ffind (U8 code, U8 *buf, U8 *mask, U16 buflen) {
  /* This function is called by the FTP server to find file names and other */
  /* file information. The output data is stored in ascii format to output  */
  /* buffer 'buf' Parameter 'code' specifies requested file information.    */
  /* Values for 'code':                                                     */
  /*    0 - read file size                                                  */
  /*    1 - read last-modified time of a file                               */
  /*    2 - list file names only (first call)                               */
  /*    3 - list file directory in extended format (first call)             */
  /*    4 - list file names only (repeated call)                            */
  /*    5 - list file directory in extended format (repeated call)          */
  static FINFO info;
  U32 rlen,v;
  U8 *tp;

  if (code < 4) {
    /* First call to ffind, initialize the info. */
    info.fileID = 0;
  }

  rlen = 0;
next:
  if ((ftp_get_user_id() == 0 && ffind ((char *)mask, &info) == 0) || (ftp_get_user_id() > 0 && ffind ("*.ani", &info) == 0)) {
    /* File found, print file information. */
    if (info.name[0] == '.') {
      if ((info.name[1] == 0) || (info.name[1] == '.' && info.name[2]) == 0) {
        /* Ignore the '.' and '..' folders. */
        goto next;
      }
    }
    switch (code) {
      case 0:
        /* Return file size as decimal number. */
        rlen = sprintf ((char *)buf,"%d\r\n", info.size);
        break;

      case 1:
        /* Return last-modified time in format "YYYYMMDDhhmmss". */
        rlen  = sprintf ((char *)buf,"%04d%02d%02d",
                         info.time.year, info.time.mon, info.time.day);
        rlen += sprintf ((char *)&buf[rlen],"%02d%02d%02d\r\n",
                         info.time.hr, info.time.min, info.time.sec);
        break;

      case 2:
      case 4:
        /* List file names only. */
        rlen = sprintf ((char *)buf,"%s\r\n", info.name);
        break;

      case 3:
      case 5:
        /* List directory in extended format. */
        rlen  = sprintf ((char *)buf,"%02d-%02d-%02d", 
                         info.time.mon, info.time.day, info.time.year%100);
        /* Convert time to "AM/PM" format. */
        v = info.time.hr % 12;
        if (v == 0) v = 12;
        if (info.time.hr < 12) tp = (U8*)"AM";
        else                   tp = (U8*)"PM";
        rlen += sprintf ((char *)&buf[rlen],"  %02d:%02d%s",v,info.time.min,tp);
        if (info.attrib & ATTR_DIRECTORY) {
          rlen += sprintf ((char *)&buf[rlen],"%-21s","       <DIR>");
        }
        else {
          rlen += sprintf ((char *)&buf[rlen],"%21d", info.size);
        }
        rlen += sprintf ((char *)&buf[rlen]," %s\r\n", info.name);
        break;
    }
  }
  return (rlen);
}
Пример #13
0
U16 cgi_func (U8 *env, U8 *buf, U16 buflen, U32 *pcgi) {
  U16 len = 0;
	static FINFO file_info;
	static int file_number;
	char file_size[16];
	char currentTimeDate[20];
	ADMIN *admin;
	USER *user;
	
  switch (env[0]) {
    // directory.cgi
    case 'A':
			// List of files
			switch (env[2]) {
				case 'A':
					if (PCGIBUF(pcgi)->number == 0) {
						// First Call, set initial value for 'ffind' function.
						file_info.fileID = 0;
						file_number = 0;
						
						if (finit(NULL) != 0) {
							// No card or failed to initialize.
							break;
						}
					}
					
					switch (PCGIBUF(pcgi)->row) {
						case 0:
							if (ffind("*.*", &file_info) == 0) {
								file_size_format(file_info.size, file_size);
								
								len += sprintf((char *)buf+len, "<tr align='center' bgcolor='#DCDCDC'><td>%d.</td>"
																								"<td align='left'><a href='%s'>%s</a></td>"
																								"<td>%s</td>",
															(file_number + 1), // Number
															file_info.name, file_info.name, // Name
															file_size); // File size

								file_number++;
								PCGIBUF(pcgi)->row++;
								PCGIBUF(pcgi)->number++;
								len |= 0x8000;
							}
							break;
						default:
							len += sprintf((char *)buf+len, "<form method='post'><td><input type='submit' value='Delete'><input type='hidden' name='file_delete' value='%s'/></td></form></tr>",
															file_info.name); // Name

							PCGIBUF(pcgi)->row = 0;
							PCGIBUF(pcgi)->number++;
							len |= 0x8000;
							break;
					}
					break;
			}
      break;
		// index.cgi
		case 'B':
			switch (env[2]) {
				case 'A':
					if (PCGIBUF(pcgi)->number == 0) {
						// First Call, set initial value for 'ffind' function.
						file_info.fileID = 0;
						file_number = 0;
						
						if (finit(NULL) != 0) {
							// No card or failed to initialize.
							break;
						}
					}
					
					switch (PCGIBUF(pcgi)->row) {
						case 0:
							if (ffind("*.ani", &file_info) == 0) {
								file_size_format(file_info.size, file_size);
								
								len += sprintf((char *)buf+len, "<tr align='center'><td class=\"table_data_row\">%d.</td>"
																								"<td align='left' class=\"table_data_row\"><a href='%s'>%s</a></td>"
																								"<td class=\"table_data_row\">%s</td>"
																								"<td class=\"table_data_row\">%d</td>",
															(file_number + 1), // Number
															file_info.name, file_info.name, // Name
															file_size,	// File size
															(file_info.size / sizeof(LED_CUBE_Effect))); // Count

								file_number++;
								PCGIBUF(pcgi)->row++;
								PCGIBUF(pcgi)->number++;
								len |= 0x8000;
							}
							break;
						default:
							len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Delete'><input type='hidden' name='ani_file_delete' value='%s'/></td></form>", file_info.name);
						
							if (ANIMATION_PLAY && strcmp(AnimationFileName, (const char *)file_info.name) == 0) {
								len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Stop'><input type='hidden' name='animation_stop' value='yes'/></td></form></tr>");
							} else {
								len += sprintf((char *)buf+len, "<form method='post'><td class=\"table_data_row\"><input type='submit' value='Start'><input type='hidden' name='animation_start' value='%s'/></td></form></tr>", file_info.name);
							}
							
							PCGIBUF(pcgi)->row = 0;
							PCGIBUF(pcgi)->number++;
							len |= 0x8000;
							break;
					}
					break;
			}
			break;
		// time.cgi
		case 'C':
			switch (env[2]) {
				case 'A':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									strftime(currentTimeDate, sizeof(currentTimeDate), SETTINGS_DATA[TIME_FORMAT], RTC_Get_TimeInfo(RTC_Get_Time()));
									len += sprintf((char *)buf+len, (const char *)&env[8], currentTimeDate);
									break;
								case '1':
									strftime(currentTimeDate, sizeof(currentTimeDate), SETTINGS_DATA[DATE_FORMAT], RTC_Get_TimeInfo(RTC_Get_Time()));
									len += sprintf((char *)buf+len, (const char *)&env[8], currentTimeDate);
									break;
							}
							break;
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									len += sprintf((char *)buf+len, (const char *)&env[8], SETTINGS_DATA[TIME_FORMAT]);
									break;
								case '1':
									len += sprintf((char *)buf+len, (const char *)&env[8], SETTINGS_DATA[DATE_FORMAT]);
									break;
							}
							break;
						case '1': // Time zone offset
							switch (env[6]) {
								case '0':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -12) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -11) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -10) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -9) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -8) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '5': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -7) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '6': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -6) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '7': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -5) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '8': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -4) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '9': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -3) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
								case '1':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -2) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == -1) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 0) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 1) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 2) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '5': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 3) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '6': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 4) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '7': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 5) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '8': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 6) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '9': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 7) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
								case '2':
									switch (env[8]) {
										case '0': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 8) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '1': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 9) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '2': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 10) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '3': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 11) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
										case '4': if(TIME_ZONE_OFFSET_SELECTED_VALUE == 12) len += sprintf((char *)buf+len, HTML_ATTRIBUTE_SELECTED); break;
									}
									break;
							}
							break;
					}
					break;
				case 'C':
					switch (env[4]) {
						case '0':
							switch (env[6]) {
								case '0':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[0]);
									break;
								case '1':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[1]);
									break;
								case '2':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[2]);
									break;
								case '3':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_1[3]);
									break;
								case '4':
									if(SNTP_Server_IP_1_WORKS) {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_green.png\" class=\"sntp_status_led\"/>");
									} else {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_red.png\" class=\"sntp_status_led\"/>");
									}
									break;
								case '5':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[0]);
									break;
								case '6':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[1]);
									break;
								case '7':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[2]);
									break;
								case '8':
									len += sprintf((char *)buf+len, (const char *)&env[8], SNTP_Server_IP_2[3]);
									break;
								case '9':
									if(SNTP_Server_IP_2_WORKS) {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_green.png\" class=\"sntp_status_led\"/>");
									} else {
										len += sprintf((char *)buf+len,  "<img src=\"status_led_red.png\" class=\"sntp_status_led\"/>");
									}
									break;
							}
							break;
					}
					break;
			}
			break;
		// admins.cgi
		case 'D':
			switch (env[2]) {
				case 'A':
					// Repeat for all admins
					if(PCGIBUF(pcgi)->number < ADMINS_Count() && ADMINS_Count() > 0) {
						//admin = malloc(sizeof(ADMIN));
						admin = &Admins[PCGIBUF(pcgi)->number];

						switch (PCGIBUF(pcgi)->row) {
							case 0:
								len += sprintf((char *)buf+len, "<table class='table_data' style=\"cursor: pointer;\">"
																								"<tr align='left'><td class='table_data_header' onclick=\"toggleTable('table_admin_%d')\">ADMIN %d - %s</td></tr>"
																								"</table>", PCGIBUF(pcgi)->number,
																				(PCGIBUF(pcgi)->number+1), admin->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 1:
								len += sprintf((char *)buf+len, "<table class='table_data' id='table_admin_%d' style=\"display: none;\"><tr align='left'><form method='post'><td class='table_data_row' width='40%%'>Username *</td><td class='table_data_row'><input type='text' name='username' maxlength='%d' value='%s'/></td></tr>",
																PCGIBUF(pcgi)->number, ADMIN_USERNAME_MAX_LENGTH, admin->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 2:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Password *</td><td class='table_data_row'><input type='text' name='password' maxlength='%d' value='%s'/></td></tr>",
																ADMIN_PASSWORD_MAX_LENGTH, admin->Password);
								PCGIBUF(pcgi)->row++;
								break;
							case 3:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>E-mail *</td><td class='table_data_row'><input type='text' name='email' maxlength='%d' value='%s'/></td></tr>",
																ADMIN_EMAIL_MAX_LENGTH, admin->Email);
								PCGIBUF(pcgi)->row++;
								break;
							case 4: // save button
								len += sprintf((char *)buf+len, "<tr>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='save_admin' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 5:
								len += sprintf((char *)buf+len, "<input type='button' value='Save' onclick=\"confirmForm(this.form, 'Are you sure you want to save admin?')\"/>"
																								"</td></form></tr>");
								
								if(ADMINS_Count() > 1) {	
									PCGIBUF(pcgi)->row++;
								} else {
									PCGIBUF(pcgi)->row += 3;
								}
								break;
							case 6: // delete button
								len += sprintf((char *)buf+len, "<tr>"
																								"<form method='post'>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='delete_admin' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 7:
								len += sprintf((char *)buf+len, "<input type='button' value='Delete' onclick=\"confirmForm(this.form, 'Are you sure you want to delete admin?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							default:
								len += sprintf((char *)buf+len, "</table><br>");
								PCGIBUF(pcgi)->row = 0;
								PCGIBUF(pcgi)->number++;
								break;
						}

						len |= 0x8000;
						
						//free(admin);
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_USERNAME_MAX_LENGTH);
							break;
						case '1':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_PASSWORD_MAX_LENGTH);
							break;
						case '2':
							len += sprintf((char *)buf+len, (const char *)&env[6], ADMIN_EMAIL_MAX_LENGTH);
							break;
					}
					break;
			}
			break;
		// users.cgi
		case 'E':
			switch (env[2]) {
				// Users list
				case 'A':				
					// Repeat for all users
					if (PCGIBUF(pcgi)->number < USERS_Count() && USERS_Count() > 0) {
						user = &Users[PCGIBUF(pcgi)->number];

						switch (PCGIBUF(pcgi)->row) {
							case 0:
								len += sprintf((char *)buf+len, "<table class='table_data' style=\"cursor: pointer;\">"
																								"<tr align='left'><td class='table_data_header' onclick=\"toggleTable('table_user_%d')\">USER %d - %s</td></tr>"
																								"</table>", PCGIBUF(pcgi)->number, (PCGIBUF(pcgi)->number+1), user->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 1:
								len += sprintf((char *)buf+len, "<table class='table_data' id='table_user_%d' style=\"display: none;\"><tr align='left'><form method='post'><td class='table_data_row' width='40%%'>Username *</td><td class='table_data_row'><input type='text' name='username' maxlength='%d' value='%s'/></td></tr>",
																PCGIBUF(pcgi)->number, USER_USERNAME_MAX_LENGTH, user->Username);
								PCGIBUF(pcgi)->row++;
								break;
							case 2:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Password *</td><td class='table_data_row'><input type='text' name='password' maxlength='%d' value='%s'/></td></tr>",
																USER_PASSWORD_MAX_LENGTH, user->Password);
								PCGIBUF(pcgi)->row++;
								break;
							case 3:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>First name *</td><td class='table_data_row'><input type='text' name='first_name' maxlength='%d' value='%s'/></th></tr>",
																sizeof(user->First_Name), user->First_Name);
								PCGIBUF(pcgi)->row++;
								break;
							case 4:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>Last name *</td><td class='table_data_row'><input type='text' name='last_name' maxlength='%d' value='%s'/></td></tr>",
																sizeof(user->Last_Name), user->Last_Name);
								PCGIBUF(pcgi)->row++;
								break;
							case 5:
								len += sprintf((char *)buf+len, "<tr align='left'><td class='table_data_row'>E-mail *</td><td class='table_data_row'><input type='text' name='email' maxlength='%d' value='%s'/></td></tr>",
																sizeof(user->Email), user->Email);
								PCGIBUF(pcgi)->row++;
								break;
							case 6: // save button
								len += sprintf((char *)buf+len, "<tr>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='save_user' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 7:
								len += sprintf((char *)buf+len, "<input type='button' value='Save' onclick=\"confirmForm(this.form, 'Are you sure you want to save user?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							case 8: // delete button
								len += sprintf((char *)buf+len, "<tr>"
																								"<form method='post'>"
																								"<td class='table_data_footer' colspan='2' align='center'>"
																								"<input type='hidden' name='delete_user' value='%d'/>",
																PCGIBUF(pcgi)->number);
								PCGIBUF(pcgi)->row++;
								break;
							case 9:
								len += sprintf((char *)buf+len, "<input type='button' value='Delete' onclick=\"confirmForm(this.form, 'Are you sure you want to delete user?')\"/>"
																								"</td></form></tr>");
								PCGIBUF(pcgi)->row++;
								break;
							default:
								len += sprintf((char *)buf+len, "</table><br>");
								PCGIBUF(pcgi)->row = 0;
								PCGIBUF(pcgi)->number++;
								break;
						}

						len |= 0x8000;
					}
					break;
				case 'B':
					switch (env[4]) {
						case '0':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_USERNAME_MAX_LENGTH);
							break;
						case '1':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_PASSWORD_MAX_LENGTH);
							break;
						case '2':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_FIRST_NAME_MAX_LENGTH);
							break;
						case '3':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_LAST_NAME_MAX_LENGTH);
							break;
						case '4':
							len += sprintf((char *)buf+len, (const char *)&env[6], USER_EMAIL_MAX_LENGTH);
							break;
					}
					break;
			}
			break;
		// Network Settings
		case 'F':
			switch (env[2]) {
				case '0':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.IpAdr[0],
                        LocM.IpAdr[1],LocM.IpAdr[2],LocM.IpAdr[3]);
					break;
				case '1':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.NetMask[0],
                        LocM.NetMask[1],LocM.NetMask[2],LocM.NetMask[3]);
					break;
				case '2':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.DefGW[0],
                        LocM.DefGW[1],LocM.DefGW[2],LocM.DefGW[3]);
					break;
				case '3':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.PriDNS[0],
                        LocM.PriDNS[1],LocM.PriDNS[2],LocM.PriDNS[3]);
					break;
				case '4':
					len = sprintf((char *)buf,(const char *)&env[4],LocM.SecDNS[0],
                        LocM.SecDNS[1],LocM.SecDNS[2],LocM.SecDNS[3]);
					break;
			}
			break;
		// Footer
		case 'Z':
			if (http_get_user_id() == 0) { // Manufacturer
				len += sprintf((char *)buf+len, "<a href='index.cgi'>Home</a> &#149; "
																				"<a href='admins.cgi'>Admins Settings</a> &#149; "
																				"<a href='users.cgi'>Users Settings</a> &#149; "
																				"<a href='time.cgi'>Time Settings</a>  &#149; "
																				"<a href='network.cgi'>Network Settings</a>  &#149; "
																				"<a href='directory.cgi'>Directory</a><br>");
			} else if (http_get_user_id() > 0 && http_get_user_id() <= ADMINS_Count()) { // Admin
				len += sprintf((char *)buf+len, "<a href='index.cgi'>Home</a> &#149; "
																				"<a href='users.cgi'>Users Settings</a> &#149; "
																				"<a href='time.cgi'>Time Settings</a>  &#149; "
																				"<a href='network.cgi'>Network Settings</a><br>");
			}
			break;
  }

  return (len);
}
Пример #14
0
void cgi_process_data (U8 code, U8 *dat, U16 len) {
  /* This function is called by HTTP server to process the returned Data    */
  /* for the CGI Form POST method. It is called on SUBMIT from the browser. */
  /* Parameters:                                                            */
  /*   code  - callback context code                                        */
  /*           0 = www-url-encoded form data                                */
  /*           1 = filename for file upload (0-terminated string)           */
  /*           2 = file upload raw data                                     */
  /*           3 = end of file upload (file close requested)                */
  /*           4 = any xml encoded POST data (single or last stream)        */
  /*           5 = the same as 4, but with more xml data to follow          */
  /*               Use http_get_content_type() to check the content type    */  
  /*   dat   - pointer to POST received data                                */
  /*   len   - received data length  */ 
  static FILE *f = NULL;
  U32 n;
  U8 *var,*p;
	
	BOOL format_flash = FALSE;
	BOOL settings_save = FALSE;
	
	BOOL sntp_time_configurations_load = FALSE;
	RTC_Time rtc_time;
	BOOL rtc_save = FALSE;
	BOOL add_admin = FALSE, add_user = FALSE;
	
	BOOL save_user = FALSE, delete_user = FALSE, delete_users = FALSE;
	BOOL save_admin = FALSE, delete_admin = FALSE;
	
	int admin_number = 0;
	int user_number = 0;
	USER *user = malloc(sizeof(USER));
	ADMIN *admin = malloc(sizeof(ADMIN));

	static FINFO file_info;

	//ADMIN *admin = malloc(sizeof(ADMIN));
	//USER *user = malloc(sizeof(USER));
	
  switch (code) {
    case 0:
      /* Url encoded form data received. */
      break;
    case 1:
      /* Filename for file upload received as encoded by the browser. */
      /* It might contain an absolute path to a file from the sending */
      /* host. Open a file for writing. */
      var = dat;
      /* Remove path info from filename, keep only the name. */
      for (p = dat; *p; p++) {
        if (*p == '\\') var = p + 1;
      }
      if (*var == 0) {
        /* Send was clicked but a filename was not selected. */
        return;
      }
      /* Filename is OK, initialize the card. */
      if (finit(NULL) != 0) {
        f = NULL;
        return;
      }
      /* Files will be stored to the root directory of SD card. */
      f = fopen ((const char *)var,"w");
      return;
    case 2:
      /* File content data received. Write data to a file. */
      /* This function will be called several times with   */
      /* code 2 when a big file is being uploaded.         */
      if (f != NULL) {
        /* Write in 512 byte blocks. This is the optimal way for */
        /* the FAT FS with caching enabled. For cache buffer     */
        /* size of 4KB the file write speed is 1.2 MByte/sec.    */
        while ((n = len) > 0) {
          if (n > 512) n = 512;
          fwrite (dat,1,n,f);
          dat += n;
          len -= n;
        }
      }
      return;
    case 3:
      /* File upload finished. Close a file. */
      if (f != NULL) {
        fclose (f);
      }
      return;
    default:
      /* Ignore all other codes. */
      return;
  }

  if (len == 0) {
    /* No data or all items (radio, checkbox) are off. */
    return;
  }
	
  var = (U8 *)alloc_mem (40);

  do {
    /* Parse all returned parameters. */
    dat = http_get_var (dat, var, 40);
    if (var[0] != 0) {
			if (str_scomp(var, (const U8*)"file_delete=") == TRUE) { // FILE DELETE
        fdelete((const char *)var+12);
      } else if (str_scomp(var, (const U8*)"format_flash=yes") == TRUE) { // FORMAT FLASH
        format_flash = TRUE;
      } else if (str_scomp(var, (const U8*)"ani_file_delete=") == TRUE) { // ANIMATION FILE DELETE
				if (fdelete((const char *)var+16) == 0) {
					if (ANIMATION_PLAY && strcmp(AnimationFileName, (const char *)var+16) == 0) {
						Animation_Stop();
					}
				}
			} else if (str_scomp(var, (const U8*)"delete_all_ani=yes") == TRUE) {
				while (ffind("*.ani", &file_info) == 0) {
					fdelete((const char*)file_info.name);
				}
			}
			
			// USERS & ADMINS COMMANDS
			if(str_scomp(var, (const U8*)"delete_user="******"%d", &user_number);
				delete_user = TRUE;
			} else if(str_scomp(var, (const U8*)"delete_users=") == TRUE) {
				delete_users = TRUE;
      } else if(str_scomp(var, (const U8*)"save_user="******"%d", &user_number);
				save_user = TRUE;
			} else if (str_scomp(var, (const U8*)"add_user=yes") == TRUE) {
				add_user = TRUE;
			}
			
			if(str_scomp(var, (const U8*)"delete_admin=") == TRUE) {
				sscanf((const char *)var+12, "%d", &admin_number);
				delete_admin = TRUE;
      } else if(str_scomp(var, (const U8*)"save_admin=") == TRUE) {
				sscanf((const char *)var+10, "%d", &admin_number);
				save_admin = TRUE;
			} else if (str_scomp(var, (const U8*)"add_admin=yes") == TRUE) {
				add_admin = TRUE;
			}
			
			if(str_scomp(var, (const U8*)"username="******"password="******"first_name=") == TRUE) {
				strcpy(user->First_Name, (const char *)var+11);
			} else if(str_scomp(var, (const U8*)"last_name=") == TRUE) {
				strcpy(user->Last_Name, (const char *)var+10);
			} else if(str_scomp(var, (const U8*)"email=") == TRUE) {
				strcpy(user->Email, (const char *)var+6);
				strcpy(admin->Email, (const char *)var+6);
			}
			
			// SNTP TIME COMMANDS
			if(str_scomp(var, (const U8*)"sntp_time_load=yes") == TRUE) {
				sntp_time_configurations_load = TRUE;
				settings_save = TRUE;
			} else if(str_scomp(var, (const U8*)"sntp_ip_1_0=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_1[0]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_1_1=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_1[1]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_1_2=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_1[2]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_1_3=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_1[3]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_2_0=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_2[0]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_2_1=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_2[1]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_2_2=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_2[2]);
			} else if(str_scomp(var, (const U8*)"sntp_ip_2_3=") == TRUE) {
				sscanf((const char *)var+12, "%d", (int*)&SNTP_Server_IP_2[3]);
			}
			
			// TIME COMMANDS
			if(str_scomp(var, (const U8*)"time_format=") == TRUE) {
				strcpy(SETTINGS_DATA[TIME_FORMAT], (const char *)var+12);
				settings_save = TRUE;
			} else if(str_scomp(var, (const U8*)"date_format=") == TRUE) {
				strcpy(SETTINGS_DATA[DATE_FORMAT], (const char *)var+12);
				settings_save = TRUE;
			} else if(str_scomp(var, (const U8*)"timezone_offset_select=") == TRUE) {
				TIME_ZONE_OFFSET_SELECTED_VALUE = atoi((const char *)var+23);
				settings_save = TRUE;
			}

			// MANUAL TIME COMMANDS
			if(str_scomp(var, (const U8*)"manual_time=") == TRUE) {
				sscanf((const char *)var+12, "%d:%d", (int*)&rtc_time.Hour, (int*)&rtc_time.Min);
				rtc_save = TRUE;
				settings_save = TRUE;
			} else if(str_scomp(var, (const U8*)"manual_date=") == TRUE) {
				sscanf((const char *)var+12, "%d-%d-%d", (int*)&rtc_time.Year, (int*)&rtc_time.Mon, (int*)&rtc_time.Mday);
				rtc_save = TRUE;
				settings_save = TRUE;
			}
			
			// ANIMATION
			if(str_scomp(var, (const U8*)"animation_start=") == TRUE) {
				AnimationFileName = (char *)malloc(strlen((const char *)var)-15);
				strcpy(AnimationFileName, (const char *)var+16);
				Animation_Start();
			} else if(str_scomp(var, (const U8*)"animation_stop=yes") == TRUE) {
				Animation_Stop();
			}
    }
  } while (dat);
  free_mem ((OS_FRAME *)var);
	
	if (format_flash == TRUE) {
		SPI_FLASH_Delete_All_Files();
	} else if (sntp_time_configurations_load == TRUE) {
		SNTP_Load_Time();
	} else if (rtc_save == TRUE) {
		TIME_ZONE_OFFSET_SELECTED_VALUE = 0;		
		RTC_Set_Time(rtc_time);
	} else if(save_user == TRUE) {
		if(USERS_Check_User(user) == USER_Warning_OK) {
			strcpy((&Users[user_number])->Username, user->Username);
			strcpy((&Users[user_number])->Password, user->Password);
			strcpy((&Users[user_number])->First_Name, user->First_Name);
			strcpy((&Users[user_number])->Last_Name, user->Last_Name);
			strcpy((&Users[user_number])->Email, user->Email);

			USERS_Save();
		}
	}	else if(save_admin == TRUE) {
		if(ADMINS_Check_Admin(admin) == ADMIN_Warning_OK) {
			strcpy((&Admins[admin_number])->Username, admin->Username);
			strcpy((&Admins[admin_number])->Password, admin->Password);
			strcpy((&Admins[admin_number])->Email, admin->Email);

			ADMINS_Save();
		}
	} else if(delete_user == TRUE) {
		USERS_Remove_User_By_Index(user_number);
	} else if(delete_admin == TRUE) {
		ADMINS_Remove_Admin_By_Index(admin_number);
	} else if (add_admin == TRUE) {
		ADMINS_Add_Admin(admin);
	} else if (add_user == TRUE) {
		USERS_Add_User(user);
	} else if(delete_users == TRUE) {
		USERS_Remove_All();
	}
	
	if (settings_save == TRUE) {
		SETTINGS_Save();
	}
	
	free(user);
	free(admin);
}