void trieCheck(FILE *emailPool,FILE *checkedEmail,FILE *result) { /*printf("begin to check.\n");*/ int finResult[101] = {0}; int repeatTimes = 1; char *aimEmail[100] = {0}; int loadEmail = 0; for(;loadEmail<100;loadEmail++){ aimEmail[loadEmail] = (char *)malloc(sizeof(char) * 320); fgets(aimEmail[loadEmail],320,checkedEmail); } for(;repeatTimes<=25;repeatTimes++) { Trie *root = (Trie *)malloc(sizeof(Trie)); initial(root); char line[320] = {0}; int lineNum = 0; long int counter = 1; long int num = 0; /* printf("begin to add points.\n");*/ while(fgets(line,320,emailPool) && counter <= 400000){ if(checkstring(line)) { trieInsert(root,line); counter ++; } } /*printf("finish building Trie tree.\n");*/ loadEmail = 0; for(;loadEmail<100;loadEmail++){ if(checkstring(aimEmail[loadEmail])) { if(trieSearch(root,aimEmail[loadEmail]) && finResult[loadEmail+1] == 0) finResult[loadEmail+1] = 1; } } trieDel(root); } int Index = 1; int sum = 0; for(;Index <= 100; Index++){ if(finResult[Index] == 1){ sum++; fprintf(result,"yes\n",Index,aimEmail[Index-1]); } else fprintf(result,"no\n",Index,aimEmail[Index-1]); } //fprintf(result,"10 million Emails hits %d ,miss %d.\n",sum,100-sum); Index = 0; for(;Index < 100;Index++) free(aimEmail[Index]); }
int socketaddr_service(struct sockaddr_in *socketaddr, const char *service, const char *proto) { struct servent *serviceaddr; /* Need to allow numeric as well as textual data. */ /* 0: pass right through. */ if (strcmp(service, "0") == 0) socketaddr->sin_port = 0; else { /* nonzero port */ serviceaddr = getservbyname(service, proto); if (serviceaddr) { socketaddr->sin_port = serviceaddr->s_port; } else { /* name did not resolve, try number */ if (checkstring(service)) { /* and it's a text name, fail. */ LFATAL("socketaddr_service no lookup for %s/%s", service, proto); return -1; } if ((socketaddr->sin_port = htons((u_short) atoi(service))) == 0) { LFATAL("socketaddr_service : numeric conversion failed"); return -1; } } } return 0; }
int context::circle() { char r[200];int last=0; mst=0; default_queue.node.homedir="d:\\temp\\out"; while(1){ if (!bmodeminit()) return 7; init_circle(0); while(1){ if (f->cn->p = f->cn->getkey()) if (f->cn->p->EventType==KEY_EVENT&&f->cn->p->Event.KeyEvent.bKeyDown){ switch(f->cn->p->Event.KeyEvent.uChar.AsciiChar){ case 'a': case 'A': if (mst==0||mst==3) answer_node();break; case 'c': case 'C': if (mst==0) call_node();break; case 'r': case 'R': TestDialogItem();break; case 'x': if (mst==0&&(f->cn->p->Event.KeyEvent.dwControlKeyState&(LEFT_ALT_PRESSED))) return 0; break; } switch(f->cn->p->Event.KeyEvent.wVirtualKeyCode){ case VK_F1: ShowHelp();break; case VK_F2: MakeConfig();break; case VK_SPACE: case VK_ESCAPE: switch(mst){ case 0: time(&yo);if (v.circle>end_time-yo) init_circle(1);break; case 1: stop_call();break; case 2: stop_answer();break; case 3: f->conresult(15,"NO MORE RINGS",0);init_circle(0);break; } break; } } Sleep(10); if (mst!=-1){ time(&yo); if (current!=yo){ current=yo; if (yo>=end_time){ switch(mst){ case 0: init_circle(1);break; case 1: stop_call();Sleep(400);call_node();break; case 2: stop_answer();break; case 3: f->conresult(15,"NO MORE RINGS");init_circle(0);break; } continue; } int i = end_time - yo; sprintf(s,"%02i:%02i",i/60,i%60); f->conresult(15,s); } } if (int q=bmodemgetchar()){ if (q==13||q==10){ r[last]=0; if (last){ if (checkstring(v.ncarrier+"|"+v.no_dial+"|"+v.busy,r,'|')){ f->conresult(14,r); if (mst==1) Sleep(400),call_node(); else init_circle(0); } else if (v.ring==r){ if (mst!=3) ringno=0; next_ring(); } else if (!strncmp(r,v.connect,v.connect.GetLength())){ f->conresult(14,v.connect); if (mst==1) emsi_connect_out(r,default_queue); else emsi_connect_in(r); last=0; break; } last=0; } } else { if (last>198) last=0; r[last++]=q; } } } } }
int search_freedb (splt_state *state) { int fd, i, tot=0; char buffer[BUFFERSIZE], message[1024], junk[1024]; char *c, *e=NULL; FILE *output = NULL; struct sockaddr_in host; struct hostent *h; struct addr dest; cd_state *cdstate; if ((c=getenv("HOME"))!=NULL) sprintf(message, "%s/"PROXYCONFIG, c); else strncpy(message, PROXYCONFIG, strlen(PROXYCONFIG)); if (!(output=fopen(message, "r"))) { if (!(output=fopen(message, "w+"))) { fprintf(stderr, "\nWARNING Can't open config file "); perror(message); } else { fprintf (stderr, "Will you use a proxy? (y/n): "); fgets(junk, 200, stdin); if (junk[0]=='y') { fprintf (stderr, "Proxy Address: "); fgets(junk, 200, stdin); fprintf (output, "PROXYADDR=%s", junk); fprintf (stderr, "Proxy Port: "); fgets(junk, 200, stdin); fprintf (output, "PROXYPORT=%s", junk); fprintf (stderr, "Need authentication? (y/n): "); fgets(junk, 200, stdin); if (junk[0]=='y') { fprintf (output, "PROXYAUTH=1\n"); fprintf (stderr, "Would you like to save password (insecure)? (y/n): "); fgets(junk, 200, stdin); if (junk[0]=='y') { login (message); e = b64(message, strlen(message)); fprintf (output, "%s\n", e); memset(message, 0x00, strlen(message)); memset(e, 0x00, strlen(e)); free(e); } } } } } dest = useproxy(output, dest); if (output != NULL) fclose(output); do { fprintf (stdout, "\n\t____________________________________________________________]"); fprintf (stdout, "\r Search: ["); fgets(junk, 800, stdin); junk[strlen(junk)-1]='\0'; } while ((strlen(junk)==0)||(checkstring(junk)!=0)); i=0; while ((junk[i]!='\0')&&(i<800)) if (junk[i]==' ') junk[i++]='+'; else i++; fprintf (stderr, "\nConnecting to %s...\n", dest.hostname); if((h=gethostbyname(dest.hostname))==NULL) { herror(dest.hostname); exit(1); } memset(&host, 0x0, sizeof(host)); host.sin_family=AF_INET; host.sin_addr.s_addr=((struct in_addr *) (h->h_addr)) ->s_addr; host.sin_port=htons(dest.port); if((fd=socket(AF_INET, SOCK_STREAM, 0))==-1) { perror("socket"); exit(1); } if ((connect(fd, (void *)&host, sizeof(host)))==-1) { perror("connect"); exit(1); } if (dest.proxy) { sprintf(message,"GET http://www.freedb.org"SEARCH" "PROXYDLG, junk); if (dest.auth!=NULL) sprintf (message, "%s"AUTH"%s\n", message, dest.auth); strncat(message, "\n", 1); } else sprintf(message,"GET "SEARCH"\n", junk); if((send(fd, message, strlen(message), 0))==-1) { perror("send"); exit(1); } fprintf (stderr, "Host contacted. Waiting for answer...\n"); memset(buffer, 0x00, BUFFERSIZE); if ((cdstate = (cd_state *) malloc (sizeof(cd_state)))==NULL) { perror("malloc"); exit(1); } cdstate->foundcd = 0; do { tot=0; c = buffer; do { i = recv(fd, c, BUFFERSIZE-(c-buffer)-1, 0); if (i==-1) break; tot += i; buffer[tot]='\0'; c += i; } while ((i>0)&&(tot<BUFFERSIZE-1)&&((e=strstr(buffer, "</html>"))==NULL)); tot = find_cd(buffer, tot, cdstate); if (tot==-1) continue; if (tot==-2) break; } while ((i>0)&&(e==NULL)&&(cdstate->foundcd<MAXCD)); closesocket(fd); if (cdstate->foundcd<=0) { if (dest.proxy) { if (strstr(buffer, "HTTP/1.0")!=NULL) { if ((c = strchr (buffer, '\n'))!=NULL) buffer[c-buffer]='\0'; fprintf (stderr, "Proxy Reply: %s\n", buffer); } } if (cdstate->foundcd==0) return -1; if (cdstate->foundcd==-1) return -2; } if (cdstate->foundcd==MAXCD) fprintf (stderr, "\nMax cd number reached, this search may be too generic.\n"); fprintf (stdout, "\n"); do { i=0; fprintf (stdout, "Select cd #: "); fgets(message, 254, stdin); message[strlen(message)-1]='\0'; tot=0; if (message[tot]=='\0') i=-1; while(message[tot]!='\0') if (isdigit(message[tot++])==0) { fprintf (stdout, "Please "); i=-1; break; } if (i!=-1) i = atoi (message); } while ((i>=cdstate->foundcd) || (i<0)); state->id.genre = getgenre(cdstate->discs[i].category); if (dest.proxy) { sprintf(message, "GET "FREEDBHTTP"cmd=cddb+read+%s+%s&hello=nouser+mp3splt.net+"NAME"+"VER"&proto=5 "PROXYDLG, cdstate->discs[i].category, cdstate->discs[i].discid); if (dest.auth!=NULL) { sprintf (message, "%s"AUTH"%s\n", message, dest.auth); memset(dest.auth, 0x00, strlen(dest.auth)); free(dest.auth); } strncat(message, "\n", 1); } else { sprintf(message, "CDDB READ %s %s\n", cdstate->discs[i].category, cdstate->discs[i].discid); host.sin_port=htons(PORT2); } fprintf (stderr, "\nContacting "FREEDB" to query selected cd...\n"); if((fd=socket(AF_INET, SOCK_STREAM, 0))==-1) { perror("socket"); exit(1); } if ((connect(fd, (void *)&host, sizeof(host)))==-1) { perror("connect"); exit(1); } if (!dest.proxy) { i=recv(fd, buffer, BUFFERSIZE-1, 0); buffer[i]='\0'; if (strncmp(buffer,"201",3)!=0) return -4; if((send(fd, HELLO, strlen(HELLO), 0))==-1) { perror("send"); exit(1); } i=recv(fd, buffer, BUFFERSIZE-1, 0); buffer[i]='\0'; if (strncmp(buffer,"200",3)!=0) return -4; } if((send(fd, message, strlen(message), 0))==-1) { perror("send"); exit(1); } fprintf (stderr, "Host contacted. Waiting for answer...\n"); memset(buffer, 0x00, BUFFERSIZE); c = buffer; tot=0; do { i = recv(fd, c, BUFFERSIZE-(c-buffer)-1, 0); if (i==-1) break; tot += i; buffer[tot]='\0'; c += i; } while ((i>0)&&(tot<BUFFERSIZE-1)&&((e=strstr(buffer, "\n."))==NULL)); if (!dest.proxy) if((send(fd, "quit\n", 5, 0))==-1) { perror("send"); exit(1); } closesocket(fd); if (tot==0) return -4; if (e!=NULL) buffer[e-buffer+1]='\0'; if ((strstr(buffer, "database entry follows"))==NULL) { if ((c = strchr (buffer, '\n'))!=NULL) buffer[c-buffer]='\0'; fprintf (stderr, "Invalid server answer: %s\n", buffer); return -5; } else { if ((c = strchr (buffer, '#'))==NULL) return -5; if (!(output=fopen(CDDBFILE, "w"))) { perror(CDDBFILE); exit(1); } fprintf (output, c); fclose(output); } fprintf (stderr, "OK, "CDDBFILE" has been written.\n"); free(cdstate); return 0; }