static void cleanup(void) { while (timeout_list) { struct timeout *t = timeout_list->data; gtk_timeout_remove(t->id); stop_timeout(t); } cddb_quit(); }
int main(int argc,char **argv) { int i; char version[BUFSIZ],*prog,*ver; cdsock_t sock; struct cddb_host host; struct cddb_hello hello; struct cddb_serverlist list; if(argc>1) { printf("usage: %s\n",argv[0]); return 0; } /* Connect */ cddb_init_cddb_host(&host); host.host_server.server_name=cddb_strdup("freedb.freedb.org"); host.host_server.server_port=8880; host.host_protocol=CDDB_MODE_CDDBP; printf ("Connecting to server: %s %d\n",host.host_server.server_name,host.host_server.server_port); if((sock=cddb_connect(&host,NULL))==INVALID_CDSOCKET) { printf("%s\n",cddb_message); cddb_free_cddb_host(&host); return 0; } printf("%s\n",cddb_message); /* Initiaite */ cd_version(version,BUFSIZ); prog=version; ver=strchr(version,' '); *ver++='\0'; /* Initialize data objects */ cddb_init_cddb_hello(&hello); cddb_init_cddb_serverlist(&list); hello.hello_user=cddb_strdup("anonymous"); hello.hello_hostname=cddb_strdup("localhost"); hello.hello_program=cddb_strdup(prog); hello.hello_version=cddb_strdup(ver); printf ("\nInitiating connection: %s %s %s %s\n",hello.hello_user,hello.hello_hostname,hello.hello_program,hello.hello_version); if(cddb_handshake(sock,&hello)!=1) { goto quit; } printf("%s\n",cddb_message); printf("\nSetting protocol level to %d\n",CDDB_PROTOCOL_LEVEL); if(cddb_proto(sock)!=1) { goto quit; } printf("%s\n",cddb_message); /* Get sites */ printf("\nRequesting site list\n"); if(cddb_sites(sock,host.host_protocol,&list)!=1) { goto quit; } printf("%s\n",cddb_message); printf("\nSites:\n"); for(i=0;i<list.list_len;i++) { printf("%s %d %s %s %s %s\n", list.list_host[i].host_server.server_name, list.list_host[i].host_server.server_port, (list.list_host[i].host_protocol==CDDB_MODE_CDDBP)?"CDDBP":"HTTP", list.list_host[i].host_latitude, list.list_host[i].host_longitude, list.list_host[i].host_description); } cddb_quit(sock,host.host_protocol); printf("%s\n",cddb_message); cddb_free_cddb_host(&host); cddb_free_cddb_hello(&hello); cddb_free_cddb_serverlist(&list); return 0; quit: printf("%s\n",cddb_message); cddb_quit(sock,host.host_protocol); printf("%s\n",cddb_message); cddb_free_cddb_host(&host); cddb_free_cddb_hello(&hello); cddb_free_cddb_serverlist(&list); return 0; }
FXbool CDDBInfo::getRemoteInfo(disc_data* info) { cdsock_t sock; char http_string[512]; int http_string_len=sizeof(http_string); FXbool success=FALSE; if(!querystring.empty()) { sock=cddb_connect(&host,pserver,&hello,http_string,&http_string_len); if(sock!=-1) { if(settings.cddbproto==CDDB_PROTOCOL_CDDBP) { // Send handshake if(!cddb_handshake(sock,&hello)||!cddb_proto(sock)) { cddb_quit(sock,CDDB_MODE_CDDBP); return FALSE; } } FXint result=cddb_query(querystring.text(),sock,(settings.cddbproto==CDDB_PROTOCOL_CDDBP)?CDDB_MODE_CDDBP:CDDB_MODE_HTTP,&query,http_string); if(result!=-1&&query.query_match!=QUERY_NOMATCH) { choice=0; if(query.query_matches>1&&settings.promptmultiple&&signal!=NULL) { setStatus(CDINFO_INTERACT); // Signal to main thread that input is requested signal->signal(); // Wait for GUI operation to complete FXMutex mtx; mtx.lock(); condition.wait(mtx); } if(settings.cddbproto==CDDB_PROTOCOL_HTTP) { cddb_quit(sock,CDDB_MODE_HTTP); sock=cddb_connect(&host,pserver,&hello,http_string,&http_string_len); } if(sock!=-1) result=cddb_read(query.query_list[choice].list_category,query.query_list[choice].list_id,sock,(settings.cddbproto==CDDB_PROTOCOL_CDDBP)?CDDB_MODE_CDDBP:CDDB_MODE_HTTP,info,http_string); else result=-1; if(result!=-1) { success = TRUE; if(settings.localcopy) { // Save entry in home directory FXString localpath=FXStringFormat("%s%c%s",FXSystem::getHomeDirectory().text(),PATHSEP,".cddb"); // Create CDDB direcotry if it does not exist if(!FXStat::exists(localpath)) FXDir::create(localpath); //Write to the local database cddb_write_local(localpath.text(),&hello,&discinfo,info,"Generated by fxcd"); } } } cddb_quit(sock,(settings.cddbproto==CDDB_PROTOCOL_CDDBP)?CDDB_MODE_CDDBP:CDDB_MODE_HTTP); } } return success; }