bool parseCinematic(Cinematic * c, const char * data, size_t size) { const char * cinematicId = safeGetString(data, size); if(!cinematicId) { LogError << "Error parsing file magic number"; return false; } if(std::strcmp(cinematicId, "KFA")) { LogError << "Wrong magic number"; return false; } s32 version; if(!safeGet(version, data, size)) { LogError << "Error reading file version"; return false; } LogDebug("version " << version); if(version < CINEMATIC_VERSION_1_75) { LogError << "Too old version " << version << " expected at least " << CINEMATIC_VERSION_1_75; } if(version > CINEMATIC_VERSION_1_76) { LogError << "Wrong version " << version << " expected max " << CINEMATIC_VERSION_1_76; return false; } // Ignore a string. safeGetString(data, size); // Load bitmaps. s32 nbitmaps; if(!safeGet(nbitmaps, data, size)) { LogError << "Error reading bitmap count"; return false; } LogDebug(nbitmaps << " images:"); c->m_bitmaps.reserve(nbitmaps); for(int i = 0; i < nbitmaps; i++) { s32 scale = 0; if(!safeGet(scale, data, size)) { LogError << "Error reading bitmap scale"; return false; } const char * str = safeGetString(data, size); if(!str) { LogError << "Error reading bitmap path"; return false; } LogDebug(" - " << i << ": \"" << str << '"'); res::path path = fixTexturePath(str); LogDebug(" => " << path << " (scale x" << scale << ')'); CinematicBitmap * newBitmap = CreateCinematicBitmap(path, scale); if(newBitmap) { c->m_bitmaps.push_back(newBitmap); } } // Load sounds. s32 nsounds; if(!safeGet(nsounds, data, size)) { LogError << "Error reading sound count"; return false; } LogDebug(nsounds << " sounds:"); for(int i = 0; i < nsounds; i++) { if(version >= CINEMATIC_VERSION_1_76) { s16 ignored; if(!safeGet(ignored, data, size)) { LogError << "Error reading sound id"; return false; } } const char * str = safeGetString(data, size); if(!str) { LogError << "Error reading sound path"; return false; } LogDebug(" - " << i << ": \"" << str << '"'); std::pair<res::path, bool> path = fixSoundPath(str); LogDebug(" => " << path.first << (path.second ? " (speech)" : "")); AddSoundToList(path.first, path.second); } // Load track and keys. SavedCinematicTrack t; if(!safeGet(t, data, size)) { LogError << "Error reading track"; return false; } AllocTrack(t.startframe, t.endframe, t.fps); LogDebug(t.nbkey << " keyframes:"); for(int i = 0; i < t.nbkey; i++) { C_KEY k; int idsound; if(version <= CINEMATIC_VERSION_1_75) { C_KEY_1_75 k175; if(!safeGet(k175, data, size)) { LogError << "Error reading key v1.75"; return false; } k.angz = k175.angz; k.color = k175.color; k.colord = k175.colord; k.colorf = k175.colorf; k.frame = k175.frame; k.fx = k175.fx; k.numbitmap = k175.numbitmap; k.pos = k175.pos.toVec3(); k.speed = k175.speed; k.typeinterp = k175.typeinterp; k.force = k175.force; idsound = k175.idsound; k.idsound = -1; k.light = k175.light; k.posgrille = k175.posgrille.toVec3(); k.angzgrille = k175.angzgrille; k.speedtrack = k175.speedtrack; } else { C_KEY_1_76 k176; if(!safeGet(k176, data, size)) { LogError << "Error reading key v1.76"; return false; } k.angz = k176.angz; k.color = k176.color; k.colord = k176.colord; k.colorf = k176.colorf; k.frame = k176.frame; k.fx = k176.fx; k.numbitmap = k176.numbitmap; k.pos = k176.pos.toVec3(); k.speed = k176.speed; k.typeinterp = k176.typeinterp; k.force = k176.force; k.light = k176.light; k.posgrille = k176.posgrille.toVec3(); k.angzgrille = k176.angzgrille; k.speedtrack = k176.speedtrack; idsound = k176.idsound[0]; // 0 was the language code for 'French' k.idsound = k176.idsound[3]; // 3 was the language code for 'English' } if(k.force < 0) { k.force = 1; } FillKeyTemp(&k.pos, k.angz, k.frame, k.numbitmap, k.fx, k.typeinterp, k.color, k.colord, k.colorf, k.speed, k.idsound, k.force, &k.light, &k.posgrille, k.angzgrille, k.speedtrack); AddKeyLoad(&KeyTemp); LogDebug(" - " << i << ": frame " << k.frame << " image: " << k.numbitmap); if(k.idsound >= 0) { LogDebug(" + sound: " << k.idsound); } if(i == 0) { c->pos = k.pos; c->angz = k.angz; c->numbitmap = k.numbitmap; c->fx = k.fx; c->ti = c->tichoose = k.typeinterp; c->color = c->colorchoose = k.color; c->colord = c->colorchoosed = k.colord; c->colorflash = c->colorflashchoose = k.colorf; c->speed = c->speedchoose = k.speed; c->idsound = idsound; c->force = k.force; c->light = c->lightchoose = k.light; c->posgrille = k.posgrille; c->angzgrille = k.angzgrille; c->speedtrack = k.speedtrack; } } UpDateAllKeyLight(); SetCurrFrame(0); GereTrackNoPlay(c); c->projectload = true; LogDebug("loaded cinematic"); return true; }
/*% * If the client is allowed to perform a zone transfer, the next order of * business is to get all the nodes in the zone, so bind can respond to the * query. */ static isc_result_t mysql_allnodes(const char *zone, void *driverarg, void *dbdata, dns_sdlzallnodes_t *allnodes) { isc_result_t result; MYSQL_RES *rs = NULL; MYSQL_ROW row; unsigned int fields; unsigned int j; unsigned int len; char *tmpString; char *endp; int ttl; UNUSED(driverarg); /* run the query and get the result set from the database. */ result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); /* if we get "not implemented", send it along */ if (result == ISC_R_NOTIMPLEMENTED) return result; /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { if (rs != NULL) mysql_free_result(rs); isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " "result set for all nodes query"); return (ISC_R_FAILURE); } result = ISC_R_NOTFOUND; row = mysql_fetch_row(rs); /* get a row from the result set */ fields = mysql_num_fields(rs); /* how many columns in result set */ while (row != NULL) { if (fields < 4) { /* gotta have at least 4 columns */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver too few fields returned " "by all nodes query"); } /* convert text to int, make sure it worked right */ ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver ttl must be " "a postive number"); } if (fields == 4) { /* tell Bind about it. */ result = dns_sdlz_putnamedrr(allnodes, safeGet(row[2]), safeGet(row[1]), ttl, safeGet(row[3])); } else { /* * more than 4 fields, concatenate the last * ones together. figure out how long to make * string. */ for (j=3, len=0; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; } /* allocate memory, allow for NULL to term string */ tmpString = isc_mem_allocate(ns_g_mctx, len + 1); if (tmpString == NULL) { /* we need more ram. */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable " "to allocate memory for " "temporary string"); mysql_free_result(rs); return (ISC_R_FAILURE); } /* copy this field to tmpString */ strcpy(tmpString, safeGet(row[3])); /* concatonate the rest, with spaces between */ for (j=4; j < fields; j++) { strcat(tmpString, " "); strcat(tmpString, safeGet(row[j])); } /* tell Bind about it. */ result = dns_sdlz_putnamedrr(allnodes, safeGet(row[2]), safeGet(row[1]), ttl, tmpString); isc_mem_free(ns_g_mctx, tmpString); } /* if we weren't successful, log err msg */ if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "dns_sdlz_putnamedrr returned error. " "Error code was: %s", isc_result_totext(result)); result = ISC_R_FAILURE; break; } /* get next row from the result set */ row = mysql_fetch_row(rs); } /* free result set memory */ mysql_free_result(rs); return result; }
/*% * If the client is allowed to perform a zone transfer, the next order of * business is to get all the nodes in the zone, so bind can respond to the * query. */ isc_result_t dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) { isc_result_t result; mysql_instance_t *db = (mysql_instance_t *)dbdata; MYSQL_RES *rs = NULL; MYSQL_ROW row; unsigned int fields; unsigned int j; char *tmpString; char *endp; int ttl; result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); if (result == ISC_R_NOTIMPLEMENTED) return (result); /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { db->log(ISC_LOG_ERROR, "MySQL module unable to return " "result set for all nodes query"); goto cleanup; } result = ISC_R_NOTFOUND; fields = mysql_num_fields(rs); /* how many columns in result set */ row = mysql_fetch_row(rs); /* get a row from the result set */ while (row != NULL) { if (fields < 4) { db->log(ISC_LOG_ERROR, "MySQL module too few fields returned " "by all nodes query"); result = ISC_R_FAILURE; goto cleanup; } ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { db->log(ISC_LOG_ERROR, "MySQL module ttl must be " "a postive number"); result = ISC_R_FAILURE; goto cleanup; } if (fields == 4) { result = db->putnamedrr(allnodes, safeGet(row[2]), safeGet(row[1]), ttl, safeGet(row[3])); } else { unsigned int len = 0; /* * more than 4 fields, concatenate the last * ones together. */ for (j = 3; j < fields; j++) len += strlen(safeGet(row[j])) + 1; tmpString = malloc(len + 1); if (tmpString == NULL) { db->log(ISC_LOG_ERROR, "MySQL module unable to allocate " "memory for temporary string"); result = ISC_R_FAILURE; goto cleanup; } strcpy(tmpString, safeGet(row[3])); for (j = 4; j < fields; j++) { strcat(tmpString, " "); strcat(tmpString, safeGet(row[j])); } result = db->putnamedrr(allnodes, safeGet(row[2]), safeGet(row[1]), ttl, tmpString); free(tmpString); } if (result != ISC_R_SUCCESS) { db->log(ISC_LOG_ERROR, "putnamedrr returned error: %s", result); result = ISC_R_FAILURE; break; } row = mysql_fetch_row(rs); } cleanup: if (rs != NULL) mysql_free_result(rs); return (result); }
static isc_result_t mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs) { isc_result_t result = ISC_R_NOTFOUND; MYSQL_ROW row; unsigned int fields; unsigned int j; unsigned int len; char *tmpString; char *endp; int ttl; row = mysql_fetch_row(rs); /* get a row from the result set */ fields = mysql_num_fields(rs); /* how many columns in result set */ while (row != NULL) { switch(fields) { case 1: /* * one column in rs, it's the data field. use * default type of A record, and default TTL * of 86400 */ result = dns_sdlz_putrr(lookup, "a", 86400, safeGet(row[0])); break; case 2: /* * two columns, data field, and data type. * use default TTL of 86400. */ result = dns_sdlz_putrr(lookup, safeGet(row[0]), 86400, safeGet(row[1])); break; case 3: /* * three columns, all data no defaults. * convert text to int, make sure it worked * right. */ ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver ttl must be " "a postive number"); } result = dns_sdlz_putrr(lookup, safeGet(row[1]), ttl, safeGet(row[2])); break; default: /* * more than 3 fields, concatenate the last * ones together. figure out how long to make * string. */ for (j=2, len=0; j < fields; j++) { len += strlen(safeGet(row[j])) + 1; } /* * allocate string memory, allow for NULL to * term string */ tmpString = isc_mem_allocate(ns_g_mctx, len + 1); if (tmpString == NULL) { /* major bummer, need more ram */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable " "to allocate memory for " "temporary string"); mysql_free_result(rs); return (ISC_R_FAILURE); /* Yeah, I'd say! */ } /* copy field to tmpString */ strcpy(tmpString, safeGet(row[2])); /* * concat the rest of fields together, space * between each one. */ for (j=3; j < fields; j++) { strcat(tmpString, " "); strcat(tmpString, safeGet(row[j])); } /* convert text to int, make sure it worked right */ ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver ttl must be " "a postive number"); } /* ok, now tell Bind about it. */ result = dns_sdlz_putrr(lookup, safeGet(row[1]), ttl, tmpString); /* done, get rid of this thing. */ isc_mem_free(ns_g_mctx, tmpString); } /* I sure hope we were successful */ if (result != ISC_R_SUCCESS) { /* nope, get rid of the Result set, and log a msg */ mysql_free_result(rs); isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "dns_sdlz_putrr returned error. " "Error code was: %s", isc_result_totext(result)); return (ISC_R_FAILURE); } row = mysql_fetch_row(rs); /* get next row */ } /* free result set memory */ mysql_free_result(rs); /* return result code */ return result; }
/*% * The processing of result sets for lookup and authority are * exactly the same. So that functionality has been moved * into this function to minimize code. */ static isc_result_t mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup, MYSQL_RES *rs) { isc_result_t result = ISC_R_NOTFOUND; MYSQL_ROW row; unsigned int fields; unsigned int j; char *tmpString; char *endp; int ttl; fields = mysql_num_fields(rs); /* how many columns in result set */ row = mysql_fetch_row(rs); /* get a row from the result set */ while (row != NULL) { unsigned int len = 0; switch(fields) { case 1: /* * one column in rs, it's the data field. use * default type of A record, and default TTL * of 86400 */ result = db->putrr(lookup, "a", 86400, safeGet(row[0])); break; case 2: /* * two columns, data field, and data type. * use default TTL of 86400. */ result = db->putrr(lookup, safeGet(row[0]), 86400, safeGet(row[1])); break; case 3: /* * three columns, all data no defaults. * convert text to int, make sure it worked * right. */ ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { db->log(ISC_LOG_ERROR, "MySQL module ttl must be " "a postive number"); return (ISC_R_FAILURE); } result = db->putrr(lookup, safeGet(row[1]), ttl, safeGet(row[2])); break; default: /* * more than 3 fields, concatenate the last * ones together. figure out how long to make * string. */ for (j = 2; j < fields; j++) len += strlen(safeGet(row[j])) + 1; /* * allocate string memory, allow for NULL to * term string */ tmpString = malloc(len + 1); if (tmpString == NULL) { db->log(ISC_LOG_ERROR, "MySQL module unable to allocate " "memory for temporary string"); mysql_free_result(rs); return (ISC_R_FAILURE); } strcpy(tmpString, safeGet(row[2])); for (j = 3; j < fields; j++) { strcat(tmpString, " "); strcat(tmpString, safeGet(row[j])); } ttl = strtol(safeGet(row[0]), &endp, 10); if (*endp != '\0' || ttl < 0) { db->log(ISC_LOG_ERROR, "MySQL module ttl must be " "a postive number"); return (ISC_R_FAILURE); } result = db->putrr(lookup, safeGet(row[1]), ttl, tmpString); free(tmpString); } if (result != ISC_R_SUCCESS) { mysql_free_result(rs); db->log(ISC_LOG_ERROR, "putrr returned error: %d", result); return (ISC_R_FAILURE); } row = mysql_fetch_row(rs); } mysql_free_result(rs); return (result); }