const char * get_property (const char *filename, const char *propname, int mode) { char line[MAXBUFSIZE], *p = NULL; FILE *fh; const char *value_s = NULL; if ((fh = fopen (filename, "r")) != 0) // opening the file in text mode { // avoids trouble on DOS while (fgets (line, sizeof line, fh) != NULL) if ((value_s = get_property_from_string (line, propname, PROPERTY_SEPARATOR, PROPERTY_COMMENT)) != NULL) break; fclose (fh); } p = getenv2 (propname); if (*p != 0) // getenv2() never returns NULL value_s = p; if (value_s) if (mode == PROPERTY_MODE_FILENAME) { static char tmp[FILENAME_MAX]; realpath2 (value_s, tmp); value_s = tmp; } return value_s; }
const char * get_property (const char *filename, const char *propname, int mode) { char line[MAXBUFSIZE], *p = NULL; FILE *fh; const char *value_s = NULL; if ((fh = fopen (filename, "r")) != 0) // opening the file in text mode { // avoids trouble under DOS while (fgets (line, sizeof line, fh) != NULL) if ((value_s = get_property_from_string (line, propname, PROPERTY_SEPARATOR, PROPERTY_COMMENT))) break; fclose (fh); } p = getenv2 (propname); if (*p == 0) // getenv2() never returns NULL { if (!value_s) value_s = NULL; // value_s won't be changed // after this func (=ok) } else value_s = p; if (value_s) if (mode == PROPERTY_MODE_FILENAME) { static char tmp[FILENAME_MAX]; #ifdef __CYGWIN__ fix_character_set (value_s); #endif realpath2 (value_s, tmp); value_s = tmp; } return value_s; }
static int quh_cddb_in_open (st_quh_nfo_t * file) { int x = 0; char buf[MAXBUFSIZE]; int t = 0, n = 0; char buf2[MAXBUFSIZE]; char *p = NULL; st_http_header_t http_header; char http_header_s[NET_MAXHTTPHEADERSIZE]; if (!inited) { if (!quh_get_object_s (quh.filter_chain, QUH_OPTION)) quh_set_object_s (quh.filter_chain, QUH_OPTION, "http://freedb.freedb.org/~cddb/cddb.cgi"); #ifdef USE_TCP net = net_init (NET_TCP|NET_CLIENT, 5); #endif inited = 1; } *buf = 0; if (!file->indices) { strcpy (buf, "Failed: Input has no indices"); quh_set_object_s (quh.filter_chain, QUH_OUTPUT, buf); return 0; } for (x = 0; x < file->indices; x++) { // add to cddb_sum n += cddb_sum (file->index_pos[x] / file->channels / file->size / file->rate); if (x == 0) t = (file->raw_size / file->channels / file->size / file->rate) - (file->index_pos[x] / file->channels / file->size / file->rate) - ((file->index_pos[x] / file->channels / file->size / file->rate) % 60); } cddb_id = (n % 0xff) << 24 | t << 8 | file->indices; #ifdef USE_TCP net_open (net, cddb_host, 80); sprintf (buf, "%s%s?cmd=cddb+query+%08lx+%d+", cddb_host, cddb_uri, cddb_id, file->indices); for (x = 0; x < file->indices; x++) sprintf (strchr (buf, 0), "%ld+", (file->index_pos[x] / 2352) + 150); sprintf (strchr (buf, 0), "%ld&hello=anonymous+localhost+%s+%s&proto=6", ((file->raw_size / 2352) + 150) / 75, "Quh", QUH_VERSION_S); net_build_http_request (http_header_s, buf, "Quh", 0, NET_METHOD_GET, 0); net_write (net, http_header_s, strlen (http_header_s)); net_parse_http_response (&http_header, net); // before: classical 9b10f50b Wayne Marshall / Symphonie // after: classical+9b10f50b while (net_gets (net, buf, MAXBUFSIZE)) { // 200 classical 9e10cb0b Wayne Marshall / Organ Transcriptions if (!strncmp (buf, "200 ", 4)) { strtrim_s (buf, "200 ", NULL); p = strchr (buf, ' '); if (p) *p = '+'; p = strchr (buf, ' '); if (p) *p = 0; strncpy (buf2, buf, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0; break; } // 211 Found inexact matches, list follows (until terminating .') // classical 9b10f50b Wayne Marshall / Symphonie // . if (!strncmp (buf, "211 ", 4)) if (net_gets (net, buf, MAXBUFSIZE)) { p = strchr (buf, ' '); if (p) *p = '+'; p = strchr (buf, ' '); if (p) *p = 0; strncpy (buf2, buf, MAXBUFSIZE)[MAXBUFSIZE - 1] = 0; break; } } // we don't use the http keep alive flag net_close (net); net_open (net, cddb_host, 80); sprintf (buf, "%s%s?cmd=cddb+read+%s&hello=anonymous+localhost+%s+%s&proto=6", cddb_host, cddb_uri, buf2, "Quh", QUH_VERSION_S); p = net_build_http_request (buf, "Quh", 0, NET_METHOD_GET, 0); net_write (net, p, strlen (p)); net_parse_http_response (net); x = 0; while (net_gets (net, buf, MAXBUFSIZE)) if (!strncmp (buf, "TTITLE", 6)) { sprintf (buf2, "TTITLE%d", x); p = (char *) get_property_from_string (buf, buf2, '=', '#'); if (p) strncpy (file->index_name[x], p, QUH_INDEX_NAME_LEN)[QUH_INDEX_NAME_LEN - 1] = 0; else *(file->index_name[x]) = 0; #ifdef DEBUG printf ("%s\n\n", file->index_name[x]); #endif x++; if (x == file->indices) break; } net_close (net); #endif // USE_TCP *buf = 0; sprintf (strchr (buf, 0), "DiscId: 0x%08lx\n", cddb_id); if (file->indices) for (x = 1 ; x < file->indices + 1; x++) { unsigned long len = (x < file->indices ? file->index_pos[x] : file->raw_size) - file->index_pos[x - 1]; sprintf (strchr (buf, 0), "%0*d:", misc_digits (QUH_MAXINDEX), x); sprintf (strchr (buf, 0), " %s", file->index_name[x - 1]); sprintf (strchr (buf, 0), "%s", quh_bytes_to_units (file, len, QUH_UNITS_CLOCK)); if (x < file->indices) strcat (buf, "\n"); } quh_set_object_s (quh.filter_chain, QUH_OUTPUT, buf); return 0; }