static void pushvalue(lua_State *L, const void *v, int type, const struct document * doc) { switch (type) { case VALUE_NIL: lua_pushnil(L); break; case VALUE_INTEGER: lua_pushinteger(L, (int32_t)getuint32(v)); break; case VALUE_REAL: lua_pushnumber(L, getfloat(v)); break; case VALUE_BOOLEAN: lua_pushboolean(L, getuint32(v)); break; case VALUE_TABLE: create_proxy(L, doc, getuint32(v)); break; case VALUE_STRING: lua_pushstring(L, (const char *)doc + doc->strtbl + getuint32(v)); break; default: luaL_error(L, "Invalid type %d at %p", type, v); } }
int pof_turret (uint8_t *buf, int len, POF_MODEL *model){ int nr_banks; int nr_slots; int n; int i; MODEL *sm; /* Number of turrets */ nr_banks = getuint32 (buf); buf += 4; len -= 4; for (i=0; i<nr_banks; i++){ /* Subobject Number */ n = getuint32 (buf); buf += 8; len -= 8; ASSERT_PRINTF (n >= 0 && n < model->nr_submodels, "Turret Submodel out of range\n"); sm = &model->submodels[n]; sm->axis = getvec3d (buf); nr_slots = getuint32 (buf + 12); buf += 16 + nr_slots * 12; len -= 16 + nr_slots * 12; if (sm->movetype == 1){ sm->movetype = 2; } } return 0; }
int pofdecode (uint8_t *buf, int len, POF_MODEL *model){ uint32_t ftype; uint32_t htype; uint32_t hlen; off_t offset; int i; ftype = getuint32 (buf); ASSERT_PRINTF (ftype == getuint32 ("PSPO"), "Not a POF model\n"); model->version = getuint32 (buf + 4); DEBUG_PRINTF ("# POF version %d\n", model->version); for (offset = 8; (htype = getuint32 (buf + offset)) != 0 && (hlen = getuint32 (buf + offset + 4)) >= 4 && offset < len; offset += hlen + 8){ for (i=0; pof_fcc_handler[i].fcc != NULL && getuint32 (pof_fcc_handler[i].fcc) != htype; i++); if (pof_fcc_handler[i].handler (buf + offset + 8, hlen, model)){ return -1; } } return 0; }
int pof_textures (uint8_t *buf, int len, POF_MODEL *model){ int i, j, l, p, lt, n; char **tmp; /* Number of textures */ n = getuint32 (buf); buf += 4; len -= 4; DEBUG_PRINTF ("# %d Textures:\n", n); /* Allocate and zero string pointer list */ tmp = malloc (n * sizeof(char *)); ASSERT_PERROR (tmp != NULL, "Unable to allocate memory for texture name list\n"); memset (tmp, 0, n * sizeof(char *)); /* Get the texture names */ for (i = 0; i < n; i++){ l = getuint32 (buf); buf += 4; len -= 4; tmp[i] = malloc (l + 1); ASSERT_PERROR (tmp[i] != NULL, "Unable to allocate memory for texture name\n"); memset (tmp[i], 0, l + 1); strncpy (tmp[i], buf, l); /* strtolower */ for (j=0; tmp[i][j] != 0; j++){ tmp[i][j] = tolower (tmp[i][j]); } DEBUG_PRINTF ("# %10d: %s\n", i, tmp[i]); buf += l; len -= l; } DEBUG_PRINTF ("# End of Textures\n\n"); model->nr_textures = n; model->textures = tmp; return 0; }
void proxy_copy(const char *tag, char *sequence, char *name, int myrights, int usinguid, struct backend *s) { char mytag[128]; struct d { char *idate; char *flags; unsigned int seqno, uid; struct d *next; } *head, *p, *q; int c; /* find out what the flags & internaldate for this message are */ proxy_gentag(mytag, sizeof(mytag)); prot_printf(backend_current->out, "%s %s %s (Flags Internaldate)\r\n", tag, usinguid ? "Uid Fetch" : "Fetch", sequence); head = (struct d *) xmalloc(sizeof(struct d)); head->flags = NULL; head->idate = NULL; head->seqno = head->uid = 0; head->next = NULL; p = head; /* read all the responses into the linked list */ for (/* each FETCH response */;;) { unsigned int seqno = 0, uidno = 0; char *flags = NULL, *idate = NULL; /* read a line */ c = prot_getc(backend_current->in); if (c != '*') break; c = prot_getc(backend_current->in); if (c != ' ') { /* protocol error */ c = EOF; break; } /* check for OK/NO/BAD/BYE response */ if (!isdigit(c = prot_getc(backend_current->in))) { prot_printf(imapd_out, "* %c", c); pipe_to_end_of_response(backend_current, 0); continue; } /* read seqno */ prot_ungetc(c, backend_current->in); c = getuint32(backend_current->in, &seqno); if (seqno == 0 || c != ' ') { /* we suck and won't handle this case */ c = EOF; break; } c = chomp(backend_current->in, "fetch ("); if (c == EOF) { c = chomp(backend_current->in, "exists\r"); if (c == '\n') { /* got EXISTS response */ prot_printf(imapd_out, "* %d EXISTS\r\n", seqno); continue; } } if (c == EOF) { /* XXX the "exists" check above will eat "ex" */ c = chomp(backend_current->in, "punge\r"); if (c == '\n') { /* got EXPUNGE response */ prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno); continue; } } if (c == EOF) { c = chomp(backend_current->in, "recent\r"); if (c == '\n') { /* got RECENT response */ prot_printf(imapd_out, "* %d RECENT\r\n", seqno); continue; } } /* huh, don't get this response */ if (c == EOF) break; for (/* each fetch item */;;) { /* looking at the first character in an item */ switch (c) { case 'f': case 'F': /* flags? */ c = chomp(backend_current->in, "lags"); if (c != ' ') { c = EOF; } else c = prot_getc(backend_current->in); if (c != '(') { c = EOF; } else { flags = grab(backend_current->in, ')'); c = prot_getc(backend_current->in); } break; case 'i': case 'I': /* internaldate? */ c = chomp(backend_current->in, "nternaldate"); if (c != ' ') { c = EOF; } else c = prot_getc(backend_current->in); if (c != '"') { c = EOF; } else { idate = grab(backend_current->in, '"'); c = prot_getc(backend_current->in); } break; case 'u': case 'U': /* uid */ c = chomp(backend_current->in, "id"); if (c != ' ') { c = EOF; } else c = getuint32(backend_current->in, &uidno); break; default: /* hmm, don't like the smell of it */ c = EOF; break; } /* looking at either SP seperating items or a RPAREN */ if (c == ' ') { c = prot_getc(backend_current->in); } else if (c == ')') break; else { c = EOF; break; } } /* if c == EOF we have either a protocol error or a situation we can't handle, and we should die. */ if (c == ')') c = prot_getc(backend_current->in); if (c == '\r') c = prot_getc(backend_current->in); if (c != '\n') { c = EOF; free(flags); free(idate); break; } /* if we're missing something, we should echo */ if (!flags || !idate) { char sep = '('; prot_printf(imapd_out, "* %d FETCH ", seqno); if (uidno) { prot_printf(imapd_out, "%cUID %d", sep, uidno); sep = ' '; } if (flags) { prot_printf(imapd_out, "%cFLAGS %s", sep, flags); sep = ' '; } if (idate) { prot_printf(imapd_out, "%cINTERNALDATE %s", sep, flags); sep = ' '; } prot_printf(imapd_out, ")\r\n"); if (flags) free(flags); if (idate) free(idate); continue; } /* add to p->next */ p->next = xmalloc(sizeof(struct d)); p = p->next; p->idate = idate; p->flags = editflags(flags); p->uid = uidno; p->seqno = seqno; p->next = NULL; } if (c != EOF) { prot_ungetc(c, backend_current->in); /* we should be looking at the tag now */ pipe_until_tag(backend_current, tag, 0); } if (c == EOF) { /* uh oh, we're not happy */ fatal("Lost connection to selected backend", EC_UNAVAILABLE); } /* start the append */ prot_printf(s->out, "%s Append {" SIZE_T_FMT "+}\r\n%s", tag, strlen(name), name); prot_printf(backend_current->out, "%s %s %s (Rfc822.peek)\r\n", mytag, usinguid ? "Uid Fetch" : "Fetch", sequence); for (/* each FETCH response */;;) { unsigned int seqno = 0, uidno = 0; /* read a line */ c = prot_getc(backend_current->in); if (c != '*') break; c = prot_getc(backend_current->in); if (c != ' ') { /* protocol error */ c = EOF; break; } /* check for OK/NO/BAD/BYE response */ if (!isdigit(c = prot_getc(backend_current->in))) { prot_printf(imapd_out, "* %c", c); pipe_to_end_of_response(backend_current, 0); continue; } /* read seqno */ prot_ungetc(c, backend_current->in); c = getuint32(backend_current->in, &seqno); if (seqno == 0 || c != ' ') { /* we suck and won't handle this case */ c = EOF; break; } c = chomp(backend_current->in, "fetch ("); if (c == EOF) { /* not a fetch response */ c = chomp(backend_current->in, "exists\r"); if (c == '\n') { /* got EXISTS response */ prot_printf(imapd_out, "* %d EXISTS\r\n", seqno); continue; } } if (c == EOF) { /* not an exists response */ /* XXX the "exists" check above will eat "ex" */ c = chomp(backend_current->in, "punge\r"); if (c == '\n') { /* got EXPUNGE response */ prot_printf(imapd_out, "* %d EXPUNGE\r\n", seqno); continue; } } if (c == EOF) { /* not an exists response */ c = chomp(backend_current->in, "recent\r"); if (c == '\n') { /* got RECENT response */ prot_printf(imapd_out, "* %d RECENT\r\n", seqno); continue; } } if (c == EOF) { /* huh, don't get this response */ break; } /* find seqno in the list */ p = head; while (p->next && seqno != p->next->seqno) p = p->next; if (!p->next) break; q = p->next; p->next = q->next; for (/* each fetch item */;;) { int sz = 0; switch (c) { case 'u': case 'U': c = chomp(backend_current->in, "id"); if (c != ' ') { c = EOF; } else c = getuint32(backend_current->in, &uidno); break; case 'r': case 'R': c = chomp(backend_current->in, "fc822"); if (c == ' ') c = prot_getc(backend_current->in); if (c != '{') { /* NIL? */ eatline(backend_current->in, c); c = EOF; } else c = getint32(backend_current->in, &sz); if (c == '}') c = prot_getc(backend_current->in); if (c == '\r') c = prot_getc(backend_current->in); if (c != '\n') c = EOF; if (c != EOF) { /* append p to s->out */ prot_printf(s->out, " (%s) \"%s\" {%d+}\r\n", q->flags, q->idate, sz); while (sz) { char buf[2048]; int j = (sz > (int) sizeof(buf) ? (int) sizeof(buf) : sz); j = prot_read(backend_current->in, buf, j); if(!j) break; prot_write(s->out, buf, j); sz -= j; } c = prot_getc(backend_current->in); } break; /* end of case */ default: c = EOF; break; } /* looking at either SP seperating items or a RPAREN */ if (c == ' ') { c = prot_getc(backend_current->in); } else if (c == ')') break; else { c = EOF; break; } } /* if c == EOF we have either a protocol error or a situation we can't handle, and we should die. */ if (c == ')') c = prot_getc(backend_current->in); if (c == '\r') c = prot_getc(backend_current->in); if (c != '\n') { c = EOF; break; } /* free q */ free(q->idate); free(q->flags); free(q); } if (c != EOF) { char *appenduid, *b; int res; /* pushback the first character of the tag we're looking at */ prot_ungetc(c, backend_current->in); /* nothing should be left in the linked list */ assert(head->next == NULL); /* ok, finish the append; we need the UIDVALIDITY and UIDs to return as part of our COPYUID response code */ prot_printf(s->out, "\r\n"); /* should be looking at 'mytag' on 'backend_current', 'tag' on 's' */ pipe_until_tag(backend_current, mytag, 0); res = pipe_until_tag(s, tag, 0); if (res == PROXY_OK) { if (myrights & ACL_READ) { appenduid = strchr(s->last_result.s, '['); /* skip over APPENDUID */ if (appenduid) { appenduid += strlen("[appenduid "); b = strchr(appenduid, ']'); if (b) *b = '\0'; prot_printf(imapd_out, "%s OK [COPYUID %s] %s\r\n", tag, appenduid, error_message(IMAP_OK_COMPLETED)); } else prot_printf(imapd_out, "%s OK %s\r\n", tag, s->last_result.s); } else { prot_printf(imapd_out, "%s OK %s\r\n", tag, error_message(IMAP_OK_COMPLETED)); } } else { prot_printf(imapd_out, "%s %s", tag, s->last_result.s); } } else { /* abort the append */ prot_printf(s->out, " {0+}\r\n\r\n"); pipe_until_tag(backend_current, mytag, 0); pipe_until_tag(s, tag, 0); /* report failure */ prot_printf(imapd_out, "%s NO inter-server COPY failed\r\n", tag); } /* free dynamic memory */ while (head) { p = head; head = head->next; if (p->idate) free(p->idate); if (p->flags) free(p->flags); free(p); } }
int proxy_catenate_url(struct backend *s, struct imapurl *url, FILE *f, unsigned long *size, const char **parseerr) { char mytag[128]; int c, r = 0, found = 0; unsigned int uidvalidity = 0; *size = 0; *parseerr = NULL; /* select the mailbox (read-only) */ proxy_gentag(mytag, sizeof(mytag)); prot_printf(s->out, "%s Examine {" SIZE_T_FMT "+}\r\n%s\r\n", mytag, strlen(url->mailbox), url->mailbox); for (/* each examine response */;;) { /* read a line */ c = prot_getc(s->in); if (c != '*') break; c = prot_getc(s->in); if (c != ' ') { /* protocol error */ c = EOF; break; } c = chomp(s->in, "ok [uidvalidity"); if (c == EOF) { /* we don't care about this response */ eatline(s->in, c); continue; } /* read uidvalidity */ c = getuint32(s->in, &uidvalidity); if (c != ']') { c = EOF; break; } eatline(s->in, c); /* we don't care about the rest of the line */ } if (c != EOF) { prot_ungetc(c, s->in); /* we should be looking at the tag now */ eatline(s->in, c); } if (c == EOF) { /* uh oh, we're not happy */ fatal("Lost connection to backend", EC_UNAVAILABLE); } if (url->uidvalidity && (uidvalidity != url->uidvalidity)) { *parseerr = "Uidvalidity of mailbox has changed"; r = IMAP_BADURL; goto unselect; } /* fetch the bodypart */ proxy_gentag(mytag, sizeof(mytag)); prot_printf(s->out, "%s Uid Fetch %lu Body.Peek[%s]\r\n", mytag, url->uid, url->section ? url->section : ""); for (/* each fetch response */;;) { unsigned int seqno; next_resp: /* read a line */ c = prot_getc(s->in); if (c != '*') break; c = prot_getc(s->in); if (c != ' ') { /* protocol error */ c = EOF; break; } /* read seqno */ c = getuint32(s->in, &seqno); if (seqno == 0 || c != ' ') { /* we suck and won't handle this case */ c = EOF; break; } c = chomp(s->in, "fetch ("); if (c == EOF) { /* not a fetch response */ eatline(s->in, c); continue; } for (/* each fetch item */;;) { unsigned uid, sz = 0; switch (c) { case 'u': case 'U': c = chomp(s->in, "id"); if (c != ' ') { c = EOF; } else { c = getuint32(s->in, &uid); if (uid != url->uid) { /* not our response */ eatline(s->in, c); goto next_resp; } } break; case 'b': case 'B': c = chomp(s->in, "ody["); while (c != ']') c = prot_getc(s->in); if (c == ']') c = prot_getc(s->in); if (c == ' ') c = prot_getc(s->in); if (c == '{') { c = getuint32(s->in, &sz); if (c == '}') c = prot_getc(s->in); if (c == '\r') c = prot_getc(s->in); if (c != '\n') c = EOF; } else if (c == 'n' || c == 'N') { c = chomp(s->in, "il"); r = IMAP_BADURL; *parseerr = "No such message part"; } if (c != EOF) { /* catenate to f */ found = 1; *size = sz; while (sz) { char buf[2048]; int j = (sz > sizeof(buf) ? sizeof(buf) : sz); j = prot_read(s->in, buf, j); if(!j) break; fwrite(buf, j, 1, f); sz -= j; } c = prot_getc(s->in); } break; /* end of case */ default: /* probably a FLAGS item */ eatline(s->in, c); goto next_resp; } /* looking at either SP separating items or a RPAREN */ if (c == ' ') { c = prot_getc(s->in); } else if (c == ')') break; else { c = EOF; break; } } /* if c == EOF we have either a protocol error or a situation we can't handle, and we should die. */ if (c == ')') c = prot_getc(s->in); if (c == '\r') c = prot_getc(s->in); if (c != '\n') { c = EOF; break; } } if (c != EOF) { prot_ungetc(c, s->in); /* we should be looking at the tag now */ eatline(s->in, c); } if (c == EOF) { /* uh oh, we're not happy */ fatal("Lost connection to backend", EC_UNAVAILABLE); } unselect: /* unselect the mailbox */ proxy_gentag(mytag, sizeof(mytag)); prot_printf(s->out, "%s Unselect\r\n", mytag); for (/* each unselect response */;;) { /* read a line */ c = prot_getc(s->in); if (c != '*') break; c = prot_getc(s->in); if (c != ' ') { /* protocol error */ c = EOF; break; } /* we don't care about this response */ eatline(s->in, c); } if (c != EOF) { prot_ungetc(c, s->in); /* we should be looking at the tag now */ eatline(s->in, c); } if (c == EOF) { /* uh oh, we're not happy */ fatal("Lost connection to backend", EC_UNAVAILABLE); } if (!r && !found) { r = IMAP_BADURL; *parseerr = "No such message in mailbox"; } return r; }
int pof_header (uint8_t *buf, int len, POF_MODEL *model){ int flags; float radius; int nr_submodels; int nr_debris; int i; if (getuint32 (buf - 8) == getuint32 ("OHDR")){ model->nr_submodels = getuint32 (buf); radius = getfloat (buf + 4); buf += 8; len -= 8; if (model->version >= VERSION_FREESPACE){ flags = getuint32 (buf); buf += 4; len -= 4; } } else { radius = getfloat (buf); flags = getuint32 (buf + 4); model->nr_submodels = getuint32 (buf + 8) + 1; buf += 12; len -= 12; } DEBUG_PRINTF ("# radius: %f\n", radius); DEBUG_PRINTF ("# %d submodels\n", model->nr_submodels); /* Allocate and zero memory for the submodels */ model->submodels = malloc(model->nr_submodels * sizeof(MODEL)); ASSERT_PERROR (model->submodels != 0, "Unable to allocate memory for models"); memset (model->submodels, 0, model->nr_submodels * sizeof(MODEL)); /* We don't need the Bounding box */ buf += 24; len -= 24; /* Get the Levels of Detail */ model->nr_lod = getuint32 (buf); DEBUG_PRINTF ("# Number of Levels of Detail: %d\n", model->nr_lod); model->lod = malloc(sizeof(int) * model->nr_lod); ASSERT_PERROR (model->lod != 0, "Unable to allocate memory for LOD list"); buf += 4; len -= 4; for (i=0; i < model->nr_lod; i++){ model->lod[i] = getuint32 (buf); model->submodels[model->lod[i]].path.lod = i + 1; buf += 4; len -= 4; } /* We don't want the debris */ nr_debris = getuint32 (buf); DEBUG_PRINTF ("# Pieces of debris: %d\n", nr_debris); buf += (nr_debris + 1) * 4; /* Mass and its effects */ if (model->version < 1903){ /* No mass, centre of mass, an no inertia vectors */ DEBUG_PRINTF ("# No mass\n"); } else if (model->version < 2009){ float mass; float masscor; VECTOR_3D com; VECTOR_3D iv[3]; /* Volume-based mass */ mass = pow(getfloat(buf), 2/3) * 4.65; masscor = mass / getfloat(buf); com = getvec3d (buf + 4); iv[0] = getvec3d (buf + 16); iv[1] = getvec3d (buf + 28); iv[2] = getvec3d (buf + 40); DEBUG_PRINTF ("# Mass: %f\n" "# Centre of Mass: [ %f %f %f ]\n" "# Right/Left Inertial Vector: [ %f %f %f ]\n" "# Up/Down Inertial Vector: [ %f %f %f ]\n" "# Fore/Aft Inertial Vector: [ %f %f %f ]\n", mass, com.x, com.y, com.z, iv[0].x * masscor, iv[0].y * masscor, iv[0].z * masscor, iv[1].x * masscor, iv[1].y * masscor, iv[1].z * masscor, iv[2].x * masscor, iv[2].y * masscor, iv[2].z * masscor); buf += 52; len -= 52; } else { float mass; VECTOR_3D com; VECTOR_3D iv[3]; /* Area-based mass */ mass = getfloat(buf); com = getvec3d (buf + 4); iv[0] = getvec3d (buf + 16); iv[1] = getvec3d (buf + 28); iv[2] = getvec3d (buf + 40); DEBUG_PRINTF ("# Mass: %f\n" "# Centre of Mass: [ %f %f %f ]\n" "# Right/Left Inertial Vector: [ %f %f %f ]\n" "# Up/Down Inertial Vector: [ %f %f %f ]\n" "# Fore/Aft Inertial Vector: [ %f %f %f ]\n", mass, com.x, com.y, com.z, iv[0].x, iv[0].y, iv[0].z, iv[1].x, iv[1].y, iv[1].z, iv[2].x, iv[2].y, iv[2].z); buf += 52; len -= 52; } /* We don't want the Cross-section */ if (model->version >= 2014){ int nr_xs; nr_xs = getuint32 (buf); DEBUG_PRINTF ("# Number of cross-sections: %d\n", nr_xs); if (nr_xs <= 0){ nr_xs = 0; } buf += (nr_xs * 2 + 1) * 4; } /* Look at all the pretty lights */ if (model->version >= 2007){ int n; int type; MODEL *m; POLY_VTX v; DEBUG_PRINTF ("# Setting up lights around model\n"); memset (&v, 0, sizeof(v)); n = model->nr_submodels - 1; m = &model->submodels[n]; m->nr_polyvtx = getuint32 (buf); m->nr_poly = m->nr_polyvtx; m->min.x = m->min.y = m->min.z = (1.0 / 0.0); m->max.x = m->max.y = m->max.z = -(1.0 / 0.0); if (m->nr_poly > 0 && model->nr_lod >= 1){ m->path.name = malloc (strlen("lights")+1); ASSERT_PERROR (m->path.name != NULL, "Unable to allocate memory for name `lights'"); strcpy (m->path.name, "lights"); m->path.parent = &model->submodels[model->lod[0]].path; m->path.nr_parents = 2; m->path.lod = 1; DEBUG_PRINTF ("# %d Lights:\n", m->nr_poly); buf += 4; m->polyvtx = malloc(m->nr_poly * sizeof(POLY_VTX)); ASSERT_PERROR (m->polyvtx != NULL, "Unable to allocate memory for lights"); memset (m->polyvtx, 0, m->nr_poly * sizeof(POLY_VTX)); m->mat = malloc(sizeof(MATERIAL)); ASSERT_PERROR (m->mat != NULL, "Unable to allocate memory for light material"); memset (m->mat, 0, sizeof(MATERIAL)); m->nr_mat = 1; v.mat.emissive.r = 1; v.mat.emissive.g = 1; v.mat.emissive.b = 1; v.mat.emissive.a = 1; v.mat.opacity = 1; m->mat[0] = v.mat; v.matn = 0; v.nverts = 1; v.vtxn = 0; for (i=0; i<m->nr_poly; i++){ v.polyn = i; v.vtx.pos = getvec3d (buf); type = getuint32 (buf + 12); if (v.vtx.pos.x > m->max.x){ m->max.x = v.vtx.pos.x; } if (v.vtx.pos.y > m->max.y){ m->max.y = v.vtx.pos.y; } if (v.vtx.pos.z > m->max.z){ m->max.z = v.vtx.pos.z; } if (v.vtx.pos.x < m->min.x){ m->min.x = v.vtx.pos.x; } if (v.vtx.pos.y < m->min.y){ m->min.y = v.vtx.pos.y; } if (v.vtx.pos.z < m->min.z){ m->min.z = v.vtx.pos.z; } DEBUG_PRINTF ("# %10d: [ %f %f %f ] type %d\n", i, v.vtx.pos.x, v.vtx.pos.y, v.vtx.pos.z, type); m->polyvtx[i] = v; buf += 16; } DEBUG_PRINTF ("# End of Lights\n"); } } DEBUG_PRINTF ("\n"); return 0; }
int pof_object (uint8_t *buf, int len, POF_MODEL *model){ uint32_t n; uint32_t l; int i; int m; int axis; int movetype; int nchunks; int bsp_data_size; int parent; char *name; /* Submodel number */ n = getuint32 (buf); buf += 4; len -= 4; ASSERT_PRINTF (n < model->nr_submodels, "Submodel number out of range\n"); DEBUG_PRINTF ("# Submodel %d\n", n); if (getuint32 (buf - 8) == getuint32 ("SOBJ")){ /* Parent submodel */ parent = getuint32 (buf); buf += 4; len -= 4; DEBUG_PRINTF ("# Parent: %d\n", parent); /* Descent had the normal and point for clip planes. We don't need these */ if (model->version < VERSION_FREESPACE){ buf += 24; len -= 24; } /* Offset of model */ model->submodels[n].offset = getvec3d (buf); buf += 12; len -= 12; DEBUG_PRINTF ("# Offset: [ %f %f %f ]\n", model->submodels[n].offset.x, model->submodels[n].offset.y, model->submodels[n].offset.z); /* Radius of submodel */ model->submodels[n].radius = getfloat (buf); buf += 4; len -= 4; DEBUG_PRINTF ("Radius: %f\n", model->submodels[n].radius); /* TODO: Pointers into IDTA block */ if (model->version < VERSION_FREESPACE){ buf += 4; len -= 4; } } else { /* Radius of submodel */ model->submodels[n].radius = getfloat (buf); buf += 4; len -= 4; DEBUG_PRINTF ("Radius: %f\n", model->submodels[n].radius); /* Parent submodel */ parent = getuint32 (buf); buf += 4; len -= 4; DEBUG_PRINTF ("# Parent: %d\n", parent); /* Offset of model */ model->submodels[n].offset = getvec3d (buf); buf += 12; len -= 12; DEBUG_PRINTF ("# Offset: [ %f %f %f ]\n", model->submodels[n].offset.x, model->submodels[n].offset.y, model->submodels[n].offset.z); } /* Point to the parent object */ if (parent < 0 || parent >= model->nr_submodels){ model->submodels[n].path.parent = &model->path; } else { model->submodels[n].path.parent = &model->submodels[parent].path; } model->submodels[n].path.nr_parents = model->submodels[n].path.parent->nr_parents + 1; if (model->submodels[n].path.lod == 0){ model->submodels[n].path.lod = model->submodels[n].path.parent->lod; } /* Geometric centre */ model->submodels[n].centre = getvec3d (buf); buf += 12; len -= 12; DEBUG_PRINTF ("# Geometric Centre: [ %f %f %f ]\n", model->submodels[n].centre.x, model->submodels[n].centre.y, model->submodels[n].centre.z); /* bounding box */ model->submodels[n].min = getvec3d (buf); model->submodels[n].max = getvec3d (buf + 12); buf += 24; len -= 24; /* Submodel name */ l = getuint32 (buf); if (l != 0){ model->submodels[n].path.name = malloc (l + 1); ASSERT_PERROR (model->submodels[n].path.name != NULL, "Unable to allocate memory for submodel name"); memcpy (model->submodels[n].path.name, buf + 4, l); model->submodels[n].path.name[l] = 0; } else { model->submodels[n].path.name = malloc (16); ASSERT_PERROR (model->submodels[n].path.name != NULL, "Unable to allocate memory for submodel name"); snprintf (model->submodels[n].path.name, 15, "_%d_", n); } DEBUG_PRINTF ("# Name: %s\n", model->submodels[n].path.name); buf += l + 4; len -= l + 4; /* Properties */ l = getuint32 (buf); buf += 4; len -= 4; { char *tmp; char **tmpptr; tmp = malloc (l + 1); ASSERT_PERROR (tmp != NULL, "Unable to allocate memory for submodel properties"); memcpy (tmp, buf, l); buf += l; len -= l; tmp[l] = 0; m = 0; for (i=0; i <= l; i++){ if (tmp[i] == '\r' || tmp[i] == '\n'){ tmp[i] = '\0'; } if (tmp[i] == '\0' && tmp[i-1] != '\0'){ m++; } } tmpptr = malloc ((m + 1) * sizeof(char *)); ASSERT_PERROR (tmpptr != NULL, "Unable to allocate memory for submodel properties list"); memset (tmpptr, 0, (m + 1) * sizeof(char *)); tmpptr[0] = tmp; m = 1; for (i=1; i < l; i++){ if (tmp[i-1] == '\0' && tmp[i] != '\0'){ tmpptr[m] = tmp + i; m++; } } model->submodels[n].props = tmpptr; model->submodels[n].nr_props = m; } /* Ignore the movement type, but keep the movement axis */ movetype = getuint32 (buf); axis = getuint32 (buf + 4); buf += 8; len -= 8; switch (movetype){ case -1: DEBUG_PRINTF ("# Movement Type: None\n"); break; case 0: DEBUG_PRINTF ("# Movement Type: Linear\n"); break; case 1: DEBUG_PRINTF ("# Movement Type: Rotating\n"); break; case 2: DEBUG_PRINTF ("# Movement Type: Turret\n"); } switch (axis){ case 0: model->submodels[n].axis.x = 1; break; case 1: model->submodels[n].axis.z = 1; break; case 2: model->submodels[n].axis.y = 1; } model->submodels[n].movetype = movetype; DEBUG_PRINTF ("# Movement Axis: [ %f %f %f ]\n", model->submodels[n].axis.x, model->submodels[n].axis.y, model->submodels[n].axis.z); /* nchunks */ nchunks = getuint32 (buf); buf += 4; len -= 4; ASSERT_PRINTF (nchunks == 0, "Cannot handle chunked models\n"); /* BSP data */ bsp_data_size = getuint32 (buf); buf += 4; len -= 4; ASSERT_PRINTF (bsp_data_size <= len, "BSP Data end past end of block\n"); DEBUG_PRINTF ("\n"); if (bspdecode (buf, bsp_data_size, &model->submodels[n])){ return -1; } /* Fill in the texture names */ for (i=0; i<model->submodels[n].nr_mat; i++){ m = (int)model->submodels[n].mat[i].texture[0]; if (m != 0 && m <= model->nr_textures){ model->submodels[n].mat[i].texture[0] = model->textures[m-1]; if (!strcmp (model->textures[m-1], "invisible")){ model->submodels[n].mat[i].opacity = 0; } } } return 0; }
int logr_read(struct logr *lgr, struct msg *k, struct msg *v, msgtype_t *t, uint32_t *tbn) { int r; uint32_t size = 0U; if (lgr->read < lgr->fsize) { char *base; uint32_t read; if (ness_os_read(lgr->fd, lgr->base, 4) != 4) { r = NESS_LOG_READ_SIZE_ERR; __ERROR(" log read size error, errno [%d]", r); goto ERR; } getuint32(lgr->base, &size); if (size > lgr->base_size) { lgr->base_size = size; lgr->base = xrealloc(lgr->base, lgr->base_size); } /* skip the length */ read = (size - 4); if (ness_os_read(lgr->fd, lgr->base, read) != read) { r = NESS_LOG_READ_DATA_ERR; __ERROR(" log read entry error, errno [%d]", r); goto ERR; } base = lgr->base; uint32_t exp_xsum; uint32_t act_xsum; getuint32(base + read - 4, &exp_xsum); buf_xsum(base, read - 4, &act_xsum); if (exp_xsum != act_xsum) { r = NESS_LOG_READ_XSUM_ERR; __ERROR("log read xsum error, exp_xsum [%" PRIu32 "],act_xsum [%" PRIu32 "]", exp_xsum, act_xsum); goto ERR; } int pos = 0; /* tbn */ getuint32(base + pos, tbn); pos += 4; /* key */ uint32_t fixsize; getuint32(base + pos, &fixsize); pos += 4; k->size = (fixsize >> 8); *t = (msgtype_t)(fixsize & 0xff); getnstr(base + pos, k->size, (char**)&k->data); pos += k->size; if (*t != MSG_DELETE) { /* value */ getuint32(base + pos, &v->size); pos += 4; getnstr(base + pos, v->size, (char**)&v->data); pos += v->size; } } else {
EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, struct protstream *in, const char *alt_reserve_base) { struct dlist *dl = NULL; static struct buf kbuf; static struct buf vbuf; int c; /* handle the key if wanted */ if (parsekey) { c = getastring(in, NULL, &kbuf); c = next_nonspace(in, c); } else { buf_setcstr(&kbuf, ""); c = prot_getc(in); } /* connection dropped? */ if (c == EOF) goto fail; /* check what sort of value we have */ if (c == '(') { dl = dlist_newlist(NULL, kbuf.s); c = next_nonspace(in, ' '); while (c != ')') { struct dlist *di = NULL; prot_ungetc(c, in); c = dlist_parse(&di, 0, in, alt_reserve_base); if (di) dlist_stitch(dl, di); c = next_nonspace(in, c); if (c == EOF) goto fail; } c = prot_getc(in); } else if (c == '%') { /* no whitespace allowed here */ c = prot_getc(in); if (c == '(') { dl = dlist_newkvlist(NULL, kbuf.s); c = next_nonspace(in, ' '); while (c != ')') { struct dlist *di = NULL; prot_ungetc(c, in); c = dlist_parse(&di, 1, in, alt_reserve_base); if (di) dlist_stitch(dl, di); c = next_nonspace(in, c); if (c == EOF) goto fail; } } else if (c == '{') { struct message_guid tmp_guid; static struct buf pbuf, gbuf; unsigned size = 0; const char *fname; const char *part; c = getastring(in, NULL, &pbuf); if (c != ' ') goto fail; c = getastring(in, NULL, &gbuf); if (c != ' ') goto fail; c = getuint32(in, &size); if (c != '}') goto fail; c = prot_getc(in); if (c == '\r') c = prot_getc(in); if (c != '\n') goto fail; if (!message_guid_decode(&tmp_guid, gbuf.s)) goto fail; part = alt_reserve_base ? alt_reserve_base : pbuf.s; if (reservefile(in, part, &tmp_guid, size, &fname)) goto fail; dl = dlist_setfile(NULL, kbuf.s, pbuf.s, &tmp_guid, size, fname); /* file literal */ } else { /* unknown percent type */ goto fail; } c = prot_getc(in); } else if (c == '{') { prot_ungetc(c, in); /* could be binary in a literal */ c = getbastring(in, NULL, &vbuf); dl = dlist_setmap(NULL, kbuf.s, vbuf.s, vbuf.len); } else if (c == '\\') { /* special case for flags */ prot_ungetc(c, in); c = getastring(in, NULL, &vbuf); dl = dlist_setflag(NULL, kbuf.s, vbuf.s); } else { prot_ungetc(c, in); c = getnastring(in, NULL, &vbuf); dl = dlist_setatom(NULL, kbuf.s, vbuf.s); } /* success */ *dlp = dl; return c; fail: dlist_free(&dl); return EOF; }
char *find_free_server(void) { const char *servers = config_getstring(IMAPOPT_SERVERLIST); unsigned long max_avail = 0; char *server = NULL; if (servers) { char *tmpbuf, *cur_server, *next_server; char mytag[128]; struct backend *be; /* make a working copy of the list */ cur_server = tmpbuf = xstrdup(servers); while (cur_server) { /* eat any leading whitespace */ while (Uisspace(*cur_server)) cur_server++; if (!*cur_server) break; /* find end of server */ if ((next_server = strchr(cur_server, ' ')) || (next_server = strchr(cur_server, '\t'))) *next_server++ = '\0'; syslog(LOG_DEBUG, "checking free space on server '%s'", cur_server); /* connect to server */ be = proxy_findserver(cur_server, &imap_protocol, proxy_userid, &backend_cached, &backend_current, &backend_inbox, imapd_in); if (be) { unsigned avail = 0; int c; /* fetch annotation from remote */ proxy_gentag(mytag, sizeof(mytag)); prot_printf(be->out, "%s GETANNOTATION \"\" " "\"/vendor/cmu/cyrus-imapd/freespace\" " "\"value.shared\"\r\n", mytag); prot_flush(be->out); for (/* each annotation response */;;) { /* read a line */ c = prot_getc(be->in); if (c != '*') break; c = prot_getc(be->in); if (c != ' ') { /* protocol error */ c = EOF; break; } c = chomp(be->in, "ANNOTATION \"\" " "\"/vendor/cmu/cyrus-imapd/freespace\" " "(\"value.shared\" \""); if (c == EOF) { /* we don't care about this response */ eatline(be->in, c); continue; } /* read uidvalidity */ c = getuint32(be->in, &avail); if (c != '\"') { c = EOF; break; } eatline(be->in, c); /* we don't care about the rest of the line */ } if (c != EOF) { prot_ungetc(c, be->in); /* we should be looking at the tag now */ eatline(be->in, c); } if (c == EOF) { /* uh oh, we're not happy */ fatal("Lost connection to backend", EC_UNAVAILABLE); } if (avail > max_avail) { server = cur_server; max_avail = avail; } } /* move to next server */ cur_server = next_server; } if (server) server = xstrdup(server); free(tmpbuf); } return server; }