00001
00008 #include <gtk/gtk.h>
00009
00010 #include <stdio.h>
00011 #include <unistd.h>
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015 #include <strings.h>
00016 #include <sys/socket.h>
00017 #include <sys/types.h>
00018 #include <netinet/in.h>
00019 #include <time.h>
00020 #include <signal.h>
00021 #include <poll.h>
00022 #include <pthread.h>
00023 #include <mysql/mysql.h>
00024
00025 #define BUFFER_SIZE 4096
00026
00027 #define SERVER_PORT 1300
00028 #define NUM_CLIENTS 1000
00029 char to_client[2];
00030
00031 #define LEN 1000
00032 int NUM_QS;
00033 int TOTAL_QS;
00034 int LISTEN_PORT;
00035 int listen_file_descriptor;
00036 int connection_file_descriptor[NUM_CLIENTS];
00037 char combine[1000];
00038 MYSQL_ROW sqlrow,temp;
00039 MYSQL_RES *result1;
00040 int ucount,fcount,scount,pucount,pfcount,pscount;
00041 char name[1000],cn[1000],dob[100],addr[1000],hob[1000],email[100],uname[1000],pass1[20],pass2[20],nemail[100],pass[20],nuname[1000],username[1000];
00042 char back[10][1000];
00043
00044 GtkWidget *ntext,*nlabel,*nlabel_search,*nlabel_user,*nlabel_details;
00045 GtkWidget *ncombo_user,*ncombo_details,*ncombo_search;
00046 GtkWidget *NAME,*CN,*DOB,*ADDR,*HOB,*EMAIL,*UNAME,*PASS,*NUNAME,*PASS1,*PASS2,*NEMAIL,*USERNAME;
00047 GtkWidget *dialog,*window2,*button2,*filew,*image;
00048 GtkWidget *combo_user,*combo_details,*combo_search;
00049 char ch;
00050 int mainscreen,enterdetails;
00051 int argc1;
00052 char *argv1[];
00053 int success = 0;
00054 char exe[1000];
00055 char sea[1000],ou[1000],oud[1000];
00056
00057
00062 void close_properly (int signal)
00063 {
00064 int return_value;
00065 int i;
00066 printf ("Shutting down...\n");
00067 return_value = close (listen_file_descriptor);
00068 if (return_value < 0)
00069 {
00070 perror ("Cannot close listening socket 1.");
00071 exit (EXIT_FAILURE);
00072 }
00073 printf ("Shutdown complete.\n");
00074 exit (0);
00075 }
00082 void *display(void *arg)
00083 {
00084 char* pname;
00085 while(1)
00086 {
00087 char input_data[LEN],input_pass[LEN];
00088 int characters_read;
00089 int client;
00090 char *username,*password,*name,*birth,*address,*contact,*hobbies,*email,*con_pass;
00091 client=(int)arg;
00092 char decide;
00093 characters_read=read(connection_file_descriptor[client],input_data,BUFFER_SIZE-1);
00094 input_data[characters_read]='\0';
00095
00096 decide = input_data[characters_read-1];
00097 input_data[characters_read-1] = '\0';
00098 if(decide=='e')
00099 {
00100 printf("read value is %s\n",input_data);
00101 username=strtok(input_data,"|");
00102 password = strtok(NULL,"|");
00103 signin_program(username,password,client);
00104 }
00105 else if(decide=='n')
00106 {
00107 printf("read value is %s\n",input_data);
00108 name=strtok(input_data,"|");
00109 contact = strtok(NULL,"|");
00110 birth = strtok(NULL,"|");
00111 address = strtok(NULL,"|");
00112 hobbies = strtok(NULL,"|");
00113 email = strtok(NULL,"|");
00114 username = strtok(NULL,"|");
00115 password = strtok(NULL,"|");
00116 con_pass = strtok(NULL,"|");
00117 signup_program(name,contact,birth,address,hobbies,email,username,password,con_pass,client);
00118
00119
00120 }
00121 else if(decide=='s')
00122 {
00123 printf("read value is %s\n",input_data);
00124 name=strtok(input_data,"|");
00125 contact = strtok(NULL,"|");
00126 birth = strtok(NULL,"|");
00127 address = strtok(NULL,"|");
00128 hobbies = strtok(NULL,"|");
00129 email = strtok(NULL,"|");
00130 username = strtok(NULL,"|");
00131 pname = strtok(NULL,"|");
00132 submit_program(pname,username,name,contact,birth,address,hobbies,email,client);
00133 }
00134 else if(decide=='l')
00135 {
00136 pthread_exit(NULL);
00137 return;
00138 }
00139
00140 else if(decide=='a')
00141 {
00142 name=strtok(input_data,"|");
00143 username = strtok(NULL,"|");
00144 add_program(name,username,client);
00145 }
00146 else if(decide=='d')
00147 {
00148 name=strtok(input_data,"|");
00149 pname = strtok(NULL,"|");
00150 delete_program(name,pname,client);
00151 }
00152 else if(decide=='u')
00153 {
00154 name=strtok(input_data,"|");
00155 contact = strtok(NULL,"|");
00156 birth = strtok(NULL,"|");
00157 address = strtok(NULL,"|");
00158 hobbies = strtok(NULL,"|");
00159 email = strtok(NULL,"|");
00160 username = strtok(NULL,"|");
00161 pname = strtok(NULL,"|");
00162 update_program(pname,username,name,contact,birth,address,hobbies,email,client);
00163 }
00164 else if(decide=='S')
00165 {
00166
00167 name=strtok(input_data,"|");
00168 contact = strtok(NULL,"|");
00169 search_program(name,contact,client);
00170 }
00171 else if(decide=='w')
00172 {
00173 users_program(client);
00174 }
00175 else if(decide=='f')
00176 {
00177 name=strtok(input_data,"|");
00178 printf("doubt name=%s\n",name);
00179 user_fnds_program(name,client);
00180 }
00181 else if(decide=='g')
00182 {
00183 name=strtok(input_data,"|");
00184 printf("doubt name=%s\n",name);
00185 fnds_program(name,client);
00186 }
00187
00188 }
00189 }
00199 int main( int argc,
00200 char *argv[] )
00201 {
00202 struct sockaddr_in server_address;
00203 int return_value,i;
00204 struct sigaction act1;
00205 pthread_t child[NUM_CLIENTS];
00206 void *child_return_value;
00207 char input_data[LEN];
00208 int characters_read;
00209 LISTEN_PORT=SERVER_PORT;
00210 act1.sa_handler = close_properly;
00211 sigemptyset (&act1.sa_mask);
00212 act1.sa_flags = 0;
00213 sigaction (SIGINT, &act1, 0);
00214
00215 listen_file_descriptor = socket (AF_INET, SOCK_STREAM, 0);
00216 if (listen_file_descriptor < 0)
00217 {
00218 fprintf (stderr, "%s: cannot open socket.\n", argv[0]);
00219 exit (EXIT_FAILURE);
00220 }
00221 bzero (&server_address, sizeof (server_address));
00222 server_address.sin_family = AF_INET;
00223 server_address.sin_addr.s_addr = htonl (INADDR_ANY);
00224 server_address.sin_port = htons (LISTEN_PORT);
00225 return_value =bind (listen_file_descriptor, (struct sockaddr *) &server_address,sizeof (server_address));
00226 if (return_value < 0)
00227 {
00228 perror ("Cannot bind");
00229 exit (EXIT_FAILURE);
00230 }
00231 return_value = listen (listen_file_descriptor, 5);
00232 if (return_value < 0)
00233 {
00234 perror ("Cannot listen");
00235 exit (EXIT_FAILURE);
00236 }
00237 while (1)
00238 {
00239
00240 for(i=0;i<100;i++)
00241 {
00242 connection_file_descriptor[i] = accept (listen_file_descriptor, (struct sockaddr *) NULL, NULL);
00243
00244
00245
00246 if (connection_file_descriptor[i] < 0)
00247 {
00248 perror ("accept() failed.");
00249 exit (EXIT_FAILURE);
00250 }
00251 else
00252 {
00253 return_value = pthread_create(&child[i], NULL, display, (void*)i);
00254
00255 if(return_value !=0)
00256 {
00257 perror("Thread 1 creation failed");
00258 exit(EXIT_FAILURE);
00259 }
00260
00261 }
00262 }
00263
00264
00265
00266
00267 for(i=0;i<NUM_CLIENTS;i++)
00268 {
00269 return_value = close (connection_file_descriptor[i]);
00270 if (return_value < 0)
00271 {
00272 perror ("close failed");
00273 exit (EXIT_FAILURE);
00274 }
00275 }
00276 }
00277
00278 return 0;
00279 }
00280
00296 void signup_program (char* name,char* contact,char* birth,char* address, char* hobbies, char* email,char* user_name, char* pass, char* conpass,int client)
00297 {
00298 MYSQL *connection1;
00299 int result,result1;
00300 int count=0;
00301 char sql_statement[1000];
00302
00303 connection1 = mysql_init(NULL);
00304 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00305 {
00306
00307 if(user_name==NULL||pass==NULL||conpass==NULL)
00308 {
00309 strcpy(to_client,"1");
00310 write(connection_file_descriptor[client],to_client,strlen(to_client));
00311
00312 }
00313 else if(strcmp(pass,conpass)==0)
00314 {
00315 sprintf(sql_statement, "select * from logins where user_name ='%s'", user_name);
00316 result = mysql_query(connection1, sql_statement);
00317 result1 = mysql_use_result (connection1);
00318 printf("result=%d,%d\n",result,result1);
00319 if (result)
00320 {
00321 while ((sqlrow = mysql_fetch_row (result1)))
00322 {
00323 count = 0;
00324 while (count < mysql_field_count (connection1))
00325 {
00326
00327 count++;
00328 }
00329
00330 }
00331 if (mysql_errno (connection1))
00332 {
00333 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00334 }
00335 }
00336 mysql_free_result(result1);
00337
00338 if(result==0)
00339 {
00340
00341 sprintf(sql_statement, "INSERT into logins values('%s','%s')", user_name,pass);
00342
00343 result1= mysql_query (connection1, sql_statement);
00344 g_print("res %d",result1);
00345 if(result1==0)
00346 {
00347 sprintf(sql_statement, "INSERT into records values('%s','%s','%s','%s','%s','%s','%s')", user_name,name,contact,birth,address,hobbies,email);
00348 result1= mysql_query (connection1, sql_statement);
00349 sprintf(sql_statement, "create table %s(user_name varchar(50) PRIMARY KEY,name varchar(30),contact_no varchar(20),date_of_birth varchar(20), address varchar(100), hobbies varchar(100),email_id varchar(30))",user_name);
00350 result1= mysql_query (connection1, sql_statement);
00351 printf("result1=%d",result1);
00352 if (mysql_errno (connection1))
00353 {
00354 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00355 }
00356 result1 = mysql_use_result (connection1);
00357 mysql_free_result(result1);
00358 strcpy(to_client,"0");
00359 write(connection_file_descriptor[client],to_client,strlen(to_client));
00360
00361 }
00362 else
00363 {
00364 strcpy(to_client,"2");
00365 write(connection_file_descriptor[client],to_client,strlen(to_client));
00366
00367 }
00368
00369 mysql_close (connection1);
00370 }
00371 }
00372 else if(strcmp(pass,conpass)!=0)
00373 {
00374 strcpy(to_client,"3");
00375 write(connection_file_descriptor[client],to_client,strlen(to_client));
00376
00377 }
00378 }
00379 else
00380 {
00381 fprintf (stderr, "Connection failed\n");
00382 if (mysql_errno (connection1))
00383 {
00384 fprintf (stderr, "Connection error %d: %s\n",
00385 mysql_errno (connection1),
00386 mysql_error (connection1));
00387 }
00388 }
00389
00390
00391 return 0;
00392 }
00393
00403 void signin_program (char* user_name, char* pass,int client)
00404 {
00405 MYSQL *connection1;
00406 int result,result1;
00407 char* password[100];
00408 int count=0;
00409 int tempsql;
00410 char sql_statement[1000];
00411 connection1 = mysql_init(NULL);
00412 mainscreen=0;
00413 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00414 {
00415 printf ("user_name=%s pass=%s\n",user_name,pass);
00416 if(user_name==NULL||pass==NULL)
00417 {
00418 strcpy(to_client,"1");
00419 write(connection_file_descriptor[client],to_client,strlen(to_client));
00420
00421 }
00422 else
00423 {
00424 sprintf(sql_statement, "select * from logins where user_name ='%s'", user_name);
00425 result = mysql_query(connection1, sql_statement);
00426 result1 = mysql_use_result (connection1);
00427 tempsql = result1;
00428 printf("result=%d,%d\n",result,result1);
00429 if(result == 0)
00430 {
00431 while ((sqlrow = mysql_fetch_row (result1)))
00432 {
00433 count++;temp = sqlrow;
00434 }
00435 printf("noofresults=%d\n",count);
00436 if(count)
00437 {
00438
00439
00440 count = 1;
00441 strcpy(password,temp[1]);
00442 printf("pass=%s conform=%s\n",password,pass);
00443
00444 if(strcmp(password,pass)==0)
00445 {
00446 printf("yes\n");
00447 strcpy(to_client,"0");
00448 write(connection_file_descriptor[client],to_client,strlen(to_client));
00449
00450 mainscreen=1;
00451
00452 }
00453 else
00454 {
00455 strcpy(to_client,"1");
00456 write(connection_file_descriptor[client],to_client,strlen(to_client));
00457
00458 }
00459 }
00460 else
00461 {
00462 strcpy(to_client,"1");
00463 write(connection_file_descriptor[client],to_client,strlen(to_client));
00464
00465 }
00466 mysql_free_result(result1);
00467 }
00468 }
00469 }
00470 else
00471 {
00472 fprintf (stderr, "Connection failed\n");
00473 if (mysql_errno (connection1))
00474 {
00475 fprintf (stderr, "Connection error %d: %s\n",
00476 mysql_errno (connection1),
00477 mysql_error (connection1));
00478 }
00479 }
00480
00481 mysql_close (connection1);
00482
00483 return 0;
00484 }
00485
00501 submit_program(char* uname,char* user_name,char* name, char* contact, char* birth, char* address, char* hobbies,char* email,int client)
00502 {
00503 MYSQL *connection1;
00504 int result;
00505 char sql_statement[1000];
00506 connection1 = mysql_init(NULL);
00507 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00508 {
00509
00510 if(user_name == NULL || name==NULL|| contact==NULL||birth==NULL||address==NULL||hobbies==NULL||email==NULL)
00511 {
00512 strcpy(to_client,"1");
00513 write(connection_file_descriptor[client],to_client,strlen(to_client));
00514
00515 }
00516 else
00517 {
00518 sprintf(sql_statement, "insert into %s values('%s','%s','%s','%s','%s','%s','%s')",uname, user_name,name,contact,birth,address,hobbies,email);
00519 result = mysql_query(connection1, sql_statement);
00520 if (result==0)
00521 {
00522 sprintf(sql_statement, "insert into records values('%s','%s','%s','%s','%s','%s','%s')", user_name,name,contact,birth,address,hobbies,email);
00523 result = mysql_query(connection1, sql_statement);
00524
00525 system(exe);
00526 strcpy(to_client,"0");
00527 write(connection_file_descriptor[client],to_client,strlen(to_client));
00528
00529
00530 }
00531 else
00532 {
00533 strcpy(to_client,"2");
00534 write(connection_file_descriptor[client],to_client,strlen(to_client));
00535
00536
00537 }
00538
00539 mysql_close (connection1);
00540 }
00541
00542 }
00543 else
00544 {
00545 fprintf (stderr, "Connection failed\n");
00546 if (mysql_errno (connection1))
00547 {
00548 fprintf (stderr, "Connection error %d: %s\n",
00549 mysql_errno (connection1),
00550 mysql_error (connection1));
00551 }
00552 }
00553
00554
00555 return 0;
00556 }
00563 users_program(int client)
00564 {
00565 MYSQL *connection1;
00566 int return_value,result;
00567 unsigned int field_count;
00568 connection1=mysql_init (NULL);
00569 int i;
00570
00571 pucount=ucount;
00572 ucount=0;
00573
00574 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00575 {
00576
00577
00578 return_value = mysql_query (connection1, "select * from logins");
00579
00580 if (return_value)
00581 {
00582
00583 }
00584 else
00585 {
00586 result = mysql_use_result (connection1);
00587 if (result)
00588 {
00589 strcpy(combine,"");
00590 while ((sqlrow = mysql_fetch_row (result)))
00591 {
00592 field_count = 0;
00593
00594 {
00595
00596 if(strcmp(combine,"")==0)
00597 strcat(combine,sqlrow[0]);
00598 else
00599 {
00600 strcat(combine,"|");
00601 strcat(combine,sqlrow[0]);
00602 }
00603
00604
00605 field_count++;
00606
00607 }
00608 printf ("\n");
00609 }
00610 write(connection_file_descriptor[client],combine,strlen(combine));
00611 if (mysql_errno (connection1))
00612 {
00613 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00614 }
00615 }
00616
00617 mysql_free_result(result);
00618 }
00619 mysql_close (connection1);
00620 }
00621 else
00622 {
00623 fprintf (stderr, "Connection failed\n");
00624 if (mysql_errno (connection1))
00625 {
00626 fprintf (stderr, "Connection error %d: %s\n",
00627 mysql_errno (connection1),
00628 mysql_error (connection1));
00629 }
00630
00631 }
00632
00633 g_print("Count value is %d pucount %d\n",ucount,pucount);
00634 return 0;
00635 }
00643 user_fnds_program(char* user_name,int client)
00644 {
00645
00646 MYSQL *connection1;
00647 int return_value,result;
00648 unsigned int field_count;
00649 char sql_statement[1000];
00650 pfcount=fcount;
00651 fcount=0;
00652 connection1=mysql_init (NULL);
00653 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00654 {
00655
00656 if(user_name!=NULL)
00657 {
00658
00659 sprintf(sql_statement, "select * from %s",user_name);
00660 return_value = mysql_query(connection1, sql_statement);
00661
00662 if (return_value)
00663 {
00664 printf ("select failed as : %s\n", mysql_error (connection1));
00665 }
00666 else
00667 {
00668 result = mysql_use_result (connection1);
00669 strcpy(combine,"");
00670 if (result)
00671 {
00672
00673 while ((sqlrow = mysql_fetch_row (result)))
00674 {
00675 field_count = 0;
00676
00677 {
00678 if(strcmp(combine,"")==0)
00679 strcat(combine,sqlrow[0]);
00680 else
00681 {
00682 strcat(combine,"|");
00683 strcat(combine,sqlrow[0]);
00684 }
00685
00686 field_count++;
00687 fcount++;
00688 }
00689
00690 }
00691
00692 if (mysql_errno (connection1))
00693 {
00694 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00695 }
00696 }
00697 printf("passing string_%s_ha\n",combine);
00698 if(strlen(combine)>0)
00699 {
00700 write(connection_file_descriptor[client],combine,strlen(combine));
00701 }
00702 else
00703 {
00704 printf("less than\n");
00705 strcpy(combine,"NO|");
00706 write(connection_file_descriptor[client],combine,strlen(combine));
00707 }
00708 mysql_free_result(result);
00709 }
00710 mysql_close (connection1);
00711 }
00712 else
00713 {
00714 sprintf(sql_statement, "select atleast one user name");
00715 dialog = gtk_message_dialog_new (NULL,
00716 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
00717 sql_statement);
00718 gtk_dialog_run (GTK_DIALOG (dialog));
00719 gtk_widget_destroy (dialog);
00720 }
00721 }
00722 else
00723 {
00724 fprintf (stderr, "Connection failed\n");
00725 if (mysql_errno (connection1))
00726 {
00727 fprintf (stderr, "Connection error %d: %s\n",
00728 mysql_errno (connection1),
00729 mysql_error (connection1));
00730 }
00731 exit(EXIT_FAILURE);
00732 }
00733 g_print("fcount value is %d pfcount %d\n",fcount,pfcount);
00734
00735 return 0;
00736 }
00745 add_program(char* oud,char* uname,int client)
00746 {
00747 MYSQL *connection1;
00748 int result,return_value=0;
00749 unsigned int field_count;
00750 int dup=0;
00751 char name[100],cont[100],add[100],birth[100],hob[100],email[100];
00752 char sql_statement[1000];
00753 connection1 = mysql_init(NULL);
00754 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00755 {
00756 if(oud!=NULL)
00757 {
00758 printf("Add program:%srr\n",uname);
00759 sprintf(sql_statement, "select * from records where user_name='%s'",oud);
00760 result = mysql_query(connection1, sql_statement);
00761 result1 = mysql_use_result (connection1);
00762 if ((sqlrow = mysql_fetch_row (result1)))
00763 {
00764 strcpy(name,sqlrow[1]);
00765 strcpy(cont,sqlrow[2]);
00766 strcpy(birth,sqlrow[3]);
00767 strcpy(add,sqlrow[4]);
00768 strcpy(hob,sqlrow[5]);
00769 strcpy(email,sqlrow[6]);
00770 dup =1;
00771 }
00772
00773 mysql_free_result(result1);
00774 if(dup==1)
00775 {
00776 sprintf(sql_statement, "insert into %s values('%s','%s','%s','%s','%s','%s','%s')", uname,oud,name,cont,birth,add,hob,email);
00777 result = mysql_query(connection1, sql_statement);
00778 if (mysql_errno (connection1))
00779 {
00780 fprintf (stderr, "Connection error %d: %s\n",
00781 mysql_errno (connection1),
00782 mysql_error (connection1));
00783 }
00784
00785 printf("add result reey:%d\n",result);
00786 if (result==0)
00787 {
00788 strcpy(to_client,"0");
00789 write(connection_file_descriptor[client],to_client,strlen(to_client));
00790 return 0;
00791
00792 }
00793 else
00794 {
00795 strcpy(to_client,"1");
00796 write(connection_file_descriptor[client],to_client,strlen(to_client));
00797 return 0;
00798
00799 }
00800
00801 }
00802
00803 else
00804 {
00805 strcpy(to_client,"2");
00806 write(connection_file_descriptor[client],to_client,strlen(to_client));
00807 return 0;
00808
00809 }
00810
00811 mysql_close (connection1);
00812 }
00813 else
00814 {
00815 strcpy(to_client,"3");
00816 write(connection_file_descriptor[client],to_client,strlen(to_client));
00817 return 0;
00818
00819 }
00820 }
00821 else
00822 {
00823 fprintf (stderr, "Connection failed\n");
00824 if (mysql_errno (connection1))
00825 {
00826 fprintf (stderr, "Connection error %d: %s\n",
00827 mysql_errno (connection1),
00828 mysql_error (connection1));
00829 }
00830
00831 }
00832 printf("\nending\n");
00833
00834 return 0;
00835 }
00843 fnds_program(char* uname,int client)
00844 {
00845 MYSQL *connection1;
00846 int return_value,result;
00847 unsigned int field_count;
00848 char sql_statement[1000];
00849 connection1=mysql_init (NULL);
00850 int i;
00851
00852 ucount=0;
00853
00854 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00855 {
00856
00857 sprintf(sql_statement, "select * from %s", uname);
00858 return_value = mysql_query(connection1, sql_statement);
00859
00860
00861 if (return_value)
00862 {
00863
00864 }
00865 else
00866 {
00867 strcpy(combine,"");
00868 result = mysql_use_result (connection1);
00869 if (result)
00870 {
00871 while ((sqlrow = mysql_fetch_row (result)))
00872 {
00873 if(strcmp(combine,"")==0)
00874 strcat(combine,sqlrow[0]);
00875 else
00876 {
00877 strcat(combine,"|");
00878 strcat(combine,sqlrow[0]);
00879 }
00880 field_count = 0;
00881
00882 {
00883
00884
00885 field_count++;
00886
00887 }
00888 printf ("\n");
00889 }
00890 if (mysql_errno (connection1))
00891 {
00892 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00893 }
00894 }
00895 if(strlen(combine)>0)
00896 {
00897 write(connection_file_descriptor[client],combine,strlen(combine));
00898 }
00899 else
00900 {
00901 printf("less than\n");
00902 strcpy(combine,"NO|");
00903 write(connection_file_descriptor[client],combine,strlen(combine));
00904 }
00905 mysql_free_result(result);
00906 }
00907 mysql_close (connection1);
00908 }
00909 else
00910 {
00911 fprintf (stderr, "Connection failed\n");
00912 if (mysql_errno (connection1))
00913 {
00914 fprintf (stderr, "Connection error %d: %s\n",
00915 mysql_errno (connection1),
00916 mysql_error (connection1));
00917 }
00918 exit(EXIT_FAILURE);
00919 }
00920
00921 return 0;
00922 }
00938 update_program(char* uname,char* user_name,char* name, char* contact, char* birth, char* address, char* hobbies,char* email,int client)
00939 {
00940 printf("update values uname %s user_name %s\n",uname,user_name);
00941 MYSQL *connection1;
00942 int result,count=0,result1;
00943 char sql_statement[1000];
00944 connection1=mysql_init(NULL);
00945 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
00946 {
00947
00948 if(user_name!=NULL)
00949 {
00950 printf ("Connectionvjgfvkgvkugklbu success\n");
00951 sprintf(sql_statement, "update %s set name='%s', contact_no='%s', date_of_birth='%s' ,address='%s', hobbies='%s', email_id='%s' where user_name='%s'",uname, name,contact, birth,address,hobbies,email,user_name);
00952 result = mysql_query(connection1, sql_statement);
00953 if (mysql_errno (connection1))
00954 {
00955 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
00956 }
00957 printf("update result=%d\n",result);
00958 result1 = mysql_affected_rows(connection1);
00959 printf("update result1=%d\n",result1);
00960
00961 if (!result)
00962 {
00963 if(result1!=0)
00964 {
00965
00966 strcpy(to_client,"0");
00967 write(connection_file_descriptor[client],to_client,strlen(to_client));
00968
00969 }
00970 else
00971 {
00972 printf("11111111111111");
00973 strcpy(to_client,"1");
00974 write(connection_file_descriptor[client],to_client,strlen(to_client));
00975 }
00976
00977 }
00978 else
00979 {
00980
00981 strcpy(to_client,"1");
00982 write(connection_file_descriptor[client],to_client,strlen(to_client));
00983
00984 }
00985 mysql_close (connection1);
00986 }
00987 else
00988 {
00989 strcpy(to_client,"2");
00990 write(connection_file_descriptor[client],to_client,strlen(to_client));
00991
00992 }
00993 }
00994 else
00995 {
00996 fprintf (stderr, "Connection failed\n");
00997 if (mysql_errno (connection1))
00998 {
00999 fprintf (stderr, "Connection error %d: %s\n", mysql_errno (connection1), mysql_error (connection1));
01000 }
01001 }
01002
01003 }
01012 delete_program(char* uname,char* user_name,int client)
01013 {
01014 printf("delete values uname %s user_name %s\n",uname,user_name);
01015 MYSQL *connection1;
01016 int result,count=0;
01017 int dum=0;
01018 char sql_statement[1000];
01019 connection1=mysql_init(NULL);
01020 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
01021 {
01022 printf("aaaaaaaaaaaaaaaaaaaaaa=%s\n",user_name);
01023 if(user_name!=NULL)
01024 {
01025
01026 sprintf(sql_statement, "select * from %s where user_name = '%s'",user_name,uname);
01027 result = mysql_query(connection1, sql_statement);
01028 printf("delete result=%d",result);
01029
01030 result1 = mysql_use_result(connection1);
01031 if(result1>0)
01032 dum =1;
01033 mysql_free_result(result1);
01034 printf("result1 delete: %d\n",result1);
01035 if (!result)
01036 {
01037 if(dum==1)
01038 {
01039 sprintf(sql_statement, "delete from %s where user_name = '%s'",user_name,uname);
01040 result = mysql_query(connection1, sql_statement);
01041 printf("delete success=%d\n",result);
01042
01043
01044
01045
01046
01047
01048 strcpy(to_client,"0");
01049 write(connection_file_descriptor[client],to_client,strlen(to_client));
01050
01051 }
01052 else
01053 {
01054 printf("ddddddddd\n");
01055 strcpy(to_client,"1");
01056 write(connection_file_descriptor[client],to_client,strlen(to_client));
01057
01058 }
01059 }
01060 else
01061 {
01062 strcpy(to_client,"2");
01063 write(connection_file_descriptor[client],to_client,strlen(to_client));
01064
01065 }
01066
01067 mysql_close (connection1);
01068 }
01069 else
01070 {
01071 strcpy(to_client,"3");
01072 write(connection_file_descriptor[client],to_client,strlen(to_client));
01073
01074 }
01075 }
01076 else
01077 {
01078 fprintf (stderr, "Connection failed\n");
01079 if (mysql_errno (connection1))
01080 {
01081 fprintf (stderr, "Connection error %d: %s\n", mysql_errno (connection1), mysql_error (connection1));
01082 }
01083 }
01084
01085 }
01094 search_program(char* uname,char* user_name,int client)
01095 {
01096 MYSQL *connection1;
01097 int return_value;
01098 char sql_statement[1000];
01099 int result,result1,count=0;
01100 unsigned int field_count;
01101 connection1=mysql_init (NULL);
01102 strcpy(combine,"");
01103 if (mysql_real_connect (connection1, "localhost", "iiit123", "iiit123", "autograph", 0, NULL, 0))
01104 {
01105 if(user_name!=NULL)
01106 {
01107 sprintf(sql_statement, "select * from %s where user_name='%s'",uname,user_name);
01108 result = mysql_query(connection1, sql_statement);
01109 printf("search result=%d",result);
01110 if (result)
01111 {
01112 printf ("select failed as : %s\n", mysql_error (connection1));
01113 }
01114 else
01115 {
01116 result1 = mysql_use_result (connection1);
01117 if (result1)
01118 {
01119 while ((sqlrow = mysql_fetch_row (result1)))
01120 {
01121
01122 field_count = 0;
01123 while (field_count < mysql_field_count (connection1))
01124 {
01125 printf ("%s %d\n", sqlrow[field_count],field_count);
01126
01127 field_count++;
01128 }
01129
01130
01131
01132 printf ("sadds \n");
01133
01134 strcat(combine,sqlrow[0]);
01135 strcat(combine,"|");
01136 strcat(combine,sqlrow[1]);
01137 strcat(combine,"|");
01138 strcat(combine,sqlrow[2]);
01139 strcat(combine,"|");
01140 strcat(combine,sqlrow[3]);
01141 strcat(combine,"|");
01142 strcat(combine,sqlrow[4]);
01143 strcat(combine,"|");
01144 strcat(combine,sqlrow[5]);
01145 strcat(combine,"|");
01146 strcat(combine,sqlrow[6]);
01147 strcat(combine,"0");
01148 printf("Before write %s\n",combine);
01149 write(connection_file_descriptor[client],combine,strlen(combine));
01150 strcpy(combine,"");
01151
01152 printf("write completed\n");
01153
01154 }
01155 if (mysql_errno (connection1))
01156 {
01157 printf ("Error occurred while retrieving data : %s\n", mysql_error (connection1));
01158 }
01159 }
01160 mysql_free_result(result1);
01161 }
01162 mysql_close (connection1);
01163 }
01164 else
01165 {
01166 strcpy(to_client,"1");
01167 write(connection_file_descriptor[client],to_client,strlen(to_client));
01168
01169 }
01170 }
01171 else
01172 {
01173 fprintf (stderr, "Connection failed\n");
01174 if (mysql_errno (connection1))
01175 {
01176 fprintf (stderr, "Connection error %d: %s\n",
01177 mysql_errno (connection1),
01178 mysql_error (connection1));
01179 }
01180
01181 }
01182
01183
01184 return 0;
01185 }
01186
01187