int main() { int choice; initscr(); do { choice = getchoice("Options:", current_cd[0] ? extended_menu : main_menu); switch (choice) { case 'q': break; case 'a': add_record(); break; case 'c': count_cds(); break; case 'f': find_cd(); break; case 'l': break; case 'u': break; } } while (choice != 'q'); endwin(); exit(0); }
int main() { int choice; initscr(); do { choice = getchoice("Options:", current_cd[0] ? extended_menu : main_menu); switch(choice) { case 'q': break; case 'a': add_record(); break; case 'c': count_cds(); break; case 'f': find_cd(); break; case 'l': list_tracks(); break; case 'r': remove_cd(); break; case 'u': update_cd(); break; } } while(choice != 'q'); endwin(); exit(EXIT_SUCCESS); }
int my_cd(char *str, t_struct *pile) { struct stat s; int n; char *tmp; n = 0; tmp = NULL; if ((str != NULL) && (*str == 0)) str = my_aff_param_list(pile->my_env, HOME); if (str == NULL) str = my_strdup(pile->home); if ((str != NULL) && (str[0] != '/') && (str[0] != '-') && str[0] != '.') tmp = my_strcat("./", str); else if (str != NULL) tmp = my_strdup(str); if ((str != NULL) && (str[0] != '-') && (stat(tmp, &s) < 0)) { msg_error(str, NO_FILE_DIR, pile); return (0); } if ((str != NULL) && ((str[0] == '-') || (check_perm(s, tmp) == 0))) find_cd(tmp, pile); else msg_error(str, ": Permission denied\n", pile); cd_check(tmp); return (0); }
zip * zip_open (const char *fname, int *err) { unsigned char buf[22]; zip *z; FILE *f; f = fopen (fname, "rb"); if (NULL == f) { *err = ZIP_EOPEN; return NULL; } z = malloc (sizeof (zip)); memset (z, 0, sizeof (zip)); z->f = f; if (find_cd (z)) { zip_close (z); *err = ZIP_NOSIG; return NULL; } fseek (f, z->cd_pos, SEEK_SET); if (fread (buf, 22, 1, f) != 1) { zip_close (z); *err = ZIP_EREAD; return NULL; } z->nr_files = get_word (buf + 10); if (get_word (buf + 8) != z->nr_files) { zip_close (z); *err = ZIP_NOMULTI; return NULL; } z->cd_size = get_long (buf + 12); z->cd_offset = get_long (buf + 16); z->rem_size = get_word (buf + 20); z->head_size = z->cd_pos - (z->cd_offset + z->cd_size); *err = list_files (z); if (*err != ZIP_OK) { zip_close (z); return NULL; } *err = ZIP_OK; return z; }
int main(int argc, const char *argv[]) { int choice; initscr(); do { choice = getchoice("Options:", current_cd[0] ? extended_menu : main_menu); switch (choice) { case 'q': break; case 'a': add_record(); break; case 'c': count_cds(); break; case 'f': find_cd(); break; case 'l': list_tracks(); break; case 'r': remove_cd(); break; case 'u': update_cd(); break; } } while (choice != 'q'); endwin(); return 0; }
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; }