#include "post.h" #include "cgi.h" #include "ieee.h" /* This function populates the inventory * * Note security is accomplished by * a) Using Database Passwords * b) Moving this executable into a SSL password protected directory * c) by the file itself (not implemented) ******/ int main() { int st,ss,sc,edit,total,new_num, old_num,tmp; char exec_buffer[1024], buf1[256], buf2[256]; /* We construct our tshirt inventory as key pairs as shown: * __=number * and then create database entries as indicated by the user ******/ get_data("meow"); printf("\n\n"); st=0; while (*shirt_type[st++]) { ss=0; while (*shirt_size[ss++]) { sc=0; while (*shirt_color[sc++]) { sprintf(buf1,"%s_%s_%s", shirt_type[st-1], shirt_size[ss-1], shirt_color[sc-1]); sprintf(buf2,"%s_%s_%s_o", shirt_type[st-1], shirt_size[ss-1], shirt_color[sc-1]); if ( !get_data(buf1) || !get_data(buf2) ) { printf("\n\n\nYikes! Yikes! Yikes! Your data appears to be corrupt.\n\n\n"); printf("I.E.


No Data\n"); printf("


\n"); printf("Technically this means '%s' != '%s'
",buf1,buf2); printf("Which means %s or %s should be blank", get_data(buf1), get_data(buf2)); printf("

Continuing anyway...

\n\n\n"); exit(56); } #ifdef CONSISTENCY_CHECK_WHICH_IS_NOT_DEFINED_AND_MAYBE_DOESNT_WORK sprintf(exec_buffer, "select stock from inventory where size='%s' and color='%s' and type='%s'" , shirt_size[ss-1], shirt_color[sc-1], shirt_type[st-1]); total=find_total(exec_buffer); tmp=0; while (buf2[tmp++]) if ( (buf2[tmp]=='_')&&(buf2[tmp+1]=='o')&&(!buf2[tmp+2]) ) buf2[tmp]=0; if (strcmp(buf2, total)) { printf( "Existing data inconcsistent with current data\n\n\n"); exit(57); } #endif /* Here we add or subtract to inventory by creating * positive or negative entried */ old_num=atoi(get_data(buf2)); new_num=atoi(get_data(buf1)); if (old_num != new_num) { new_num=new_num-old_num; /* Here we should check to see if we are adding * negative inventory.... presumably a big no no *****/ sprintf(exec_buffer, "insert into inventory (size, color, type, def_price, stock, ds) values ('%s','%s','%s','%s','%d',now())", shirt_size[ss-1], shirt_color[sc-1], shirt_type[st-1], shirt_type_price[st-1], new_num ); printf("Doing %s
\n\n",exec_buffer); /* Note, we should copy all execute buffers to ram, and * then execute when finished parsing *****/ exec (exec_buffer); } } } } printf("

Done... Presumably completed succedfully

\n\n"); printf("See inv.cgi"); printf(""); return(0); }