static void write_header(const char *fmt, const char *reason, int extra_fields) { char buf[1024]; int len; if (extra_fields) { char hostname[256]; char date[256]; time_t t; FILE *me; *hostname = '\0'; if ((me = fopen("/var/qmail/control/me", "r"))) { len = better_fgets(hostname, sizeof(hostname), me); fclose(me); } if (!*hostname) strcpy(hostname, "UNKNOWN"); t = time(NULL); if (!strftime(date, sizeof(date), "%F %T -0000", gmtime(&t))) *date = '\0'; snprintf(buf, sizeof(buf), fmt, hostname, date, reason); } else { snprintf(buf, sizeof(buf), fmt, reason); } len = strlen(buf); if (write(qq_mail[1], buf, (size_t)len) != len) qq_done(); }
static char *addr2user(const char *addr) { FILE *list; static char buf[128]; const char *domain; int len; domain = strchr(addr, '@'); if (!domain) domain = addr; list = fopen("/var/qmail/users/spam", "r"); if (!list) return NULL; while ((len = better_fgets(buf, sizeof(buf), list))) { char *sep = strchr(buf, ':'); if (buf[0] == '#' || !sep) continue; *sep++ = '\0'; if (cmpaddr(addr, buf)) { fclose(list); if (*sep == '*') { strlcpy(buf, addr, sizeof(buf)); sep = strchr(buf, '@'); if (sep) *sep = '\0'; sep = strchr(buf, '-'); if (sep) *sep = '\0'; return strdup(buf); } return strdup(sep); } } fclose(list); return NULL; }
static void check_list(const char *addr) { FILE *list; static char buf[128]; const char *adomain; unsigned int alocallen; int len; // fprintf(stderr, "Checking list for %s\n", addr); adomain = strchr(addr, '@'); alocallen = adomain - addr; if (!adomain || !alocallen) return; list = fopen("/var/qmail/users/lists", "r"); if (!list) return; while ((len = better_fgets(buf, sizeof(buf), list))) { char *dir = strchr(buf, ':'); if (buf[0] == '#' || !dir) continue; *dir++ = '\0'; char *domain = strchr(buf, '@'); if (domain && !strcmp(domain, adomain)) { unsigned int locallen = domain - buf; if (locallen && locallen <= alocallen && (addr[locallen] == '@' || addr[locallen] == '-') && !memcmp(addr, buf, locallen)) { // Domain matches, local part in list is no // longer than local part in address, they // match up to that length, and the left // over part is empty or begins with "-". // IOW this will be handled by that list. fclose(list); const char *rest = addr + locallen; if (!memcmp(rest, "-owner@", 7) || !memcmp(rest, "-subscribe", 10) || !memcmp(rest, "-sc.", 4) || !memcmp(rest, "-uc.", 4) || !memcmp(rest, "-help@", 6) || !memcmp(rest, "-info@", 6) || !memcmp(rest, "-faq@", 5) || !memcmp(rest, "-return-", 8)) { // Never reject for these return; } reject_list(dir); return; } } } fclose(list); }
bool ModelType::ParseObj(char *filename) { FILE *in_file; char oneline[255]; char mtlname[255]; int currGroup = -1; float x, y, z; int iV1, iV2, iV3, iV4, iT1, iT2, iT3, iT4, iN1, iN2, iN3, iN4; printf("Loading model %s: ", filename); in_file = fopen(filename, "rt"); if (in_file == NULL) { printf("error, file not found!\n"); return false; } else printf("done.\n"); tDispObj = (OBJModel*)malloc(sizeof(OBJModel)); tDispObj->NumVerts = 0; tDispObj->NumTexts = 0; tDispObj->NumNorms = 0; tDispObj->NumTngls = 0; tDispObj->NumQuads = 0; for (int i = 0; i < objMaxNumMats; i++) { tDispObj->group[i].objTngls = NULL; tDispObj->group[i].objQuads = NULL; tDispObj->group[i].objEdges = NULL; tDispObj->group[i].matID = -1; tDispObj->mtrl[i].Name[0] = '\0'; tDispObj->mtrl[i].aTextName[0] = '\0'; tDispObj->mtrl[i].dTextName[0] = '\0'; tDispObj->mtrl[i].sTextName[0] = '\0'; tDispObj->mtrl[i].NormType = 0; tDispObj->mtrl[i].SmthType = 0; tDispObj->mtrl[i].aCol.x = 1.0f; tDispObj->mtrl[i].aCol.y = 1.0f; tDispObj->mtrl[i].aCol.z = 1.0f; tDispObj->mtrl[i].dCol.x = 1.0f; tDispObj->mtrl[i].dCol.y = 1.0f; tDispObj->mtrl[i].dCol.z = 1.0f; tDispObj->mtrl[i].sCol.x = 1.0f; tDispObj->mtrl[i].sCol.y = 1.0f; tDispObj->mtrl[i].sCol.z = 1.0f; tDispObj->mtrl[i].Reflect = 1.0f; tDispObj->mtrl[i].Opacity = 1.0f; } while (!feof(in_file)) { if (better_fgets(oneline, 255, in_file) == NULL) break; // Caso tenha uma linha falando sobre mtllib if (strncmp(oneline, "mtllib", 6) == 0) { // Manda carregar o mtllib if (sscanf(oneline, "mtllib %s", mtlname) == 1) ParseMtl(mtlname); } // Caso escolha um material ? else if (strncmp(oneline, "usemtl", 6) == 0) { int matID = 0; if ((sscanf(oneline, "usemtl %s", mtlname) == 1) && (numObjects != 0)) { while (strncmp(mtlname, tDispObj->mtrl[matID].Name, 32) != 0) { matID++; if (matID == numObjects) break; } } currGroup = matID; tDispObj->group[currGroup].matID = matID; } // Caso leu um ponto else if (sscanf(oneline, "v %f %f %f", &x, &y, &z) == 3) { x *= myScale; y *= myScale; z *= myScale; tDispObj->objVerts[tDispObj->NumVerts].x = x; tDispObj->objVerts[tDispObj->NumVerts].y = y; tDispObj->objVerts[tDispObj->NumVerts].z = z; tDispObj->NumVerts++; if (x > maxVerts.x) maxVerts.x = x; if (y > maxVerts.y) maxVerts.y = y; if (z > maxVerts.z) maxVerts.z = z; if (x < minVerts.x) minVerts.x = x; if (y < minVerts.y) minVerts.y = y; if (z < minVerts.z) minVerts.z = z; } // Caso leu uma coordenada tripla de textura else if (sscanf(oneline, "vt %f %f %f", &x, &y, &z) == 3) { tDispObj->objTexts[tDispObj->NumTexts].u = x; tDispObj->objTexts[tDispObj->NumTexts].v = y; tDispObj->objTexts[tDispObj->NumTexts].w = z; tDispObj->NumTexts++; } // Caso leu uma coordenada dupla de textura else if (sscanf(oneline, "vt %f %f", &x, &y) == 2) { tDispObj->objTexts[tDispObj->NumTexts].u = x; tDispObj->objTexts[tDispObj->NumTexts].v = y; tDispObj->objTexts[tDispObj->NumTexts].w = 0.0f; tDispObj->NumTexts++; } else if (sscanf(oneline, "vn %f %f %f", &x, &y, &z) == 3) { tDispObj->objNorms[tDispObj->NumNorms].x = x; tDispObj->objNorms[tDispObj->NumNorms].y = y; tDispObj->objNorms[tDispObj->NumNorms].z = z; tDispObj->NumNorms++; } else if (sscanf(oneline, "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", &iV1, &iT1, &iN1, &iV2, &iT2, &iN2, &iV3, &iT3, &iN3, &iV4, &iT4, &iN4) == 12) { tDispObj->NumQuads++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = (iV4 < 0) ? (tDispObj->NumVerts + iV4) : --iV4; newFace->t1 = (iT1 < 0) ? (tDispObj->NumTexts + iT1) : --iT1; newFace->t2 = (iT2 < 0) ? (tDispObj->NumTexts + iT2) : --iT2; newFace->t3 = (iT3 < 0) ? (tDispObj->NumTexts + iT3) : --iT3; newFace->t4 = (iT4 < 0) ? (tDispObj->NumTexts + iT4) : --iT4; newFace->n1 = (iN1 < 0) ? (tDispObj->NumNorms + iN1) : --iN1; newFace->n2 = (iN2 < 0) ? (tDispObj->NumNorms + iN2) : --iN2; newFace->n3 = (iN3 < 0) ? (tDispObj->NumNorms + iN3) : --iN3; newFace->n4 = (iN4 < 0) ? (tDispObj->NumNorms + iN4) : --iN4; newFace->NormType = 1; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objQuads == NULL) tDispObj->group[currGroup].objQuads = newFace; else Insert_Face(tDispObj->group[currGroup].objQuads, newFace); } else if (sscanf(oneline, "f %d/%d/%d %d/%d/%d %d/%d/%d", &iV1, &iT1, &iN1, &iV2, &iT2, &iN2, &iV3, &iT3, &iN3) == 9) { tDispObj->NumTngls++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = -1; newFace->t1 = (iT1 < 0) ? (tDispObj->NumTexts + iT1) : --iT1; newFace->t2 = (iT2 < 0) ? (tDispObj->NumTexts + iT2) : --iT2; newFace->t3 = (iT3 < 0) ? (tDispObj->NumTexts + iT3) : --iT3; newFace->t4 = -1; newFace->n1 = (iN1 < 0) ? (tDispObj->NumNorms + iN1) : --iN1; newFace->n2 = (iN2 < 0) ? (tDispObj->NumNorms + iN2) : --iN2; newFace->n3 = (iN3 < 0) ? (tDispObj->NumNorms + iN3) : --iN3; newFace->n4 = -1; newFace->NormType = 1; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objTngls == NULL) tDispObj->group[currGroup].objTngls = newFace; else Insert_Face(tDispObj->group[currGroup].objTngls, newFace); } else if (sscanf(oneline, "f %d//%d %d//%d %d//%d %d//%d", &iV1, &iN1, &iV2, &iN2, &iV3, &iN3, &iV4, &iN4) == 8) { tDispObj->NumQuads++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = (iV4 < 0) ? (tDispObj->NumVerts + iV4) : --iV4; newFace->t1 = -1; newFace->t2 = -1; newFace->t3 = -1; newFace->t4 = -1; newFace->n1 = (iN1 < 0) ? (tDispObj->NumNorms + iN1) : --iN1; newFace->n2 = (iN2 < 0) ? (tDispObj->NumNorms + iN2) : --iN2; newFace->n3 = (iN3 < 0) ? (tDispObj->NumNorms + iN3) : --iN3; newFace->n4 = (iN4 < 0) ? (tDispObj->NumNorms + iN4) : --iN4; newFace->NormType = 1; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objQuads == NULL) tDispObj->group[currGroup].objQuads = newFace; else Insert_Face(tDispObj->group[currGroup].objQuads, newFace); } else if (sscanf(oneline, "f %d/%d %d/%d %d/%d %d/%d", &iV1, &iT1, &iV2, &iT2, &iV3, &iT3, &iV4, &iT4) == 8) { tDispObj->NumQuads++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = (iV4 < 0) ? (tDispObj->NumVerts + iV4) : --iV4; newFace->t1 = (iT1 < 0) ? (tDispObj->NumTexts + iT1) : --iT1; newFace->t2 = (iT2 < 0) ? (tDispObj->NumTexts + iT2) : --iT2; newFace->t3 = (iT3 < 0) ? (tDispObj->NumTexts + iT3) : --iT3; newFace->t4 = (iT4 < 0) ? (tDispObj->NumTexts + iT4) : --iT4; newFace->n1 = -1; newFace->n2 = -1; newFace->n3 = -1; newFace->n4 = -1; newFace->NormType = 0; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objQuads == NULL) tDispObj->group[currGroup].objQuads = newFace; else Insert_Face(tDispObj->group[currGroup].objQuads, newFace); } else if (sscanf(oneline, "f %d//%d %d//%d %d//%d", &iV1, &iN1, &iV2, &iN2, &iV3, &iN3) == 6) { tDispObj->NumTngls++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = -1; newFace->t1 = -1; newFace->t2 = -1; newFace->t3 = -1; newFace->t4 = -1; newFace->n1 = (iN1 < 0) ? (tDispObj->NumNorms + iN1) : --iN1; newFace->n2 = (iN2 < 0) ? (tDispObj->NumNorms + iN2) : --iN2; newFace->n3 = (iN3 < 0) ? (tDispObj->NumNorms + iN3) : --iN3; newFace->n4 = -1; newFace->NormType = 1; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objTngls == NULL) tDispObj->group[currGroup].objTngls = newFace; else Insert_Face(tDispObj->group[currGroup].objTngls, newFace); } else if (sscanf(oneline, "f %d/%d %d/%d %d/%d", &iV1, &iT1, &iV2, &iT2, &iV3, &iT3) == 6) { tDispObj->NumTngls++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = -1; newFace->t1 = (iT1 < 0) ? (tDispObj->NumTexts + iT1) : --iT1; newFace->t2 = (iT2 < 0) ? (tDispObj->NumTexts + iT2) : --iT2; newFace->t3 = (iT3 < 0) ? (tDispObj->NumTexts + iT3) : --iT3; newFace->t4 = -1; newFace->n1 = -1; newFace->n2 = -1; newFace->n3 = -1; newFace->n4 = -1; newFace->NormType = 0; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objTngls == NULL) tDispObj->group[currGroup].objTngls = newFace; else Insert_Face(tDispObj->group[currGroup].objTngls, newFace); } else if (sscanf(oneline, "f %d %d %d %d", &iV1, &iV2, &iV3, &iV4) == 4) { tDispObj->NumQuads++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = (iV4 < 0) ? (tDispObj->NumVerts + iV4) : --iV4; newFace->t1 = -1; newFace->t2 = -1; newFace->t3 = -1; newFace->t4 = -1; newFace->n1 = -1; newFace->n2 = -1; newFace->n3 = -1; newFace->n4 = -1; newFace->NormType = 0; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objQuads == NULL) tDispObj->group[currGroup].objQuads = newFace; else Insert_Face(tDispObj->group[currGroup].objQuads, newFace); } else if (sscanf(oneline, "f %d %d %d", &iV1, &iV2, &iV3) == 3) { tDispObj->NumTngls++; OBJFace *newFace = (OBJFace*)malloc(sizeof(OBJFace)); newFace->next = NULL; newFace->v1 = (iV1 < 0) ? (tDispObj->NumVerts + iV1) : --iV1; newFace->v2 = (iV2 < 0) ? (tDispObj->NumVerts + iV2) : --iV2; newFace->v3 = (iV3 < 0) ? (tDispObj->NumVerts + iV3) : --iV3; newFace->v4 = -1; newFace->t1 = -1; newFace->t2 = -1; newFace->t3 = -1; newFace->t4 = -1; newFace->n1 = -1; newFace->n2 = -1; newFace->n3 = -1; newFace->n4 = -1; newFace->NormType = 0; if (currGroup == -1) currGroup = numObjects; if (tDispObj->group[currGroup].objTngls == NULL) tDispObj->group[currGroup].objTngls = newFace; else Insert_Face(tDispObj->group[currGroup].objTngls, newFace); } } fclose(in_file); if (numObjects == 0) numObjects++; if (fabs(maxVerts.x) > myRadius) myRadius = fabs(maxVerts.x); if (fabs(maxVerts.y) > myRadius) myRadius = fabs(maxVerts.y); if (fabs(maxVerts.z) > myRadius) myRadius = fabs(maxVerts.z); if (fabs(minVerts.x) > myRadius) myRadius = fabs(maxVerts.x); if (fabs(minVerts.y) > myRadius) myRadius = fabs(maxVerts.y); if (fabs(minVerts.z) > myRadius) myRadius = fabs(maxVerts.z); printf("-> Number of vertices: %d\n", tDispObj->NumVerts); printf("-> Number of normals: %d\n", tDispObj->NumNorms); printf("-> Number of tex coords: %d\n", tDispObj->NumTexts); printf("-> Number of triangles: %d\n", tDispObj->NumTngls); printf("-> Number of quads: %d\n", tDispObj->NumQuads); return true; }
bool ModelType::ParseMtl(char *filename) { char temp[100] = {}; strcat(temp,PASTA); strcat(temp,filename); strcpy(filename,temp); FILE *in_file; char oneline[255]; int currMtrl = -1; float cVal1, cVal2, cVal3; int bVal; printf("Loading material library %s: ", filename); in_file = fopen(filename, "rt"); if (in_file == NULL) { printf("error, file not found!\n"); return false; } while (!feof(in_file)) { if (better_fgets(oneline, 255, in_file) == NULL) break; if (strncmp(oneline, "newmtl", 6) == 0) { currMtrl++; sscanf(oneline, "newmtl %s", tDispObj->mtrl[currMtrl].Name); } if (strncmp(oneline, "Ka", 2) == 0) { sscanf(oneline, "Ka %f %f %f", &cVal1, &cVal2, &cVal3); tDispObj->mtrl[currMtrl].aCol.x = cVal1; tDispObj->mtrl[currMtrl].aCol.y = cVal2; tDispObj->mtrl[currMtrl].aCol.z = cVal3; } if (strncmp(oneline, "Kd", 2) == 0) { sscanf(oneline, "Kd %f %f %f", &cVal1, &cVal2, &cVal3); tDispObj->mtrl[currMtrl].dCol.x = cVal1; tDispObj->mtrl[currMtrl].dCol.y = cVal2; tDispObj->mtrl[currMtrl].dCol.z = cVal3; } if (strncmp(oneline, "Ks", 2) == 0) { sscanf(oneline, "Ks %f %f %f", &cVal1, &cVal2, &cVal3); tDispObj->mtrl[currMtrl].sCol.x = cVal1; tDispObj->mtrl[currMtrl].sCol.y = cVal2; tDispObj->mtrl[currMtrl].sCol.z = cVal3; } if (strncmp(oneline, "Tr", 2) == 0) { sscanf(oneline, "Tr %f", &cVal1); tDispObj->mtrl[currMtrl].Opacity = cVal1; } if (strncmp(oneline, "Ns", 2) == 0) { sscanf(oneline, "Ns %f", &cVal1); tDispObj->mtrl[currMtrl].Reflect = cVal1; } else if (strncmp(oneline, "map_Ka", 6) == 0) sscanf(oneline, "map_Ka %s", tDispObj->mtrl[currMtrl].aTextName); else if (strncmp(oneline, "map_Kd", 6) == 0) sscanf(oneline, "map_Kd %s", tDispObj->mtrl[currMtrl].dTextName); else if (strncmp(oneline, "map_Ks", 6) == 0) sscanf(oneline, "map_Ks %s", tDispObj->mtrl[currMtrl].sTextName); else if (sscanf(oneline, "Smooth %d", &bVal) == 1) tDispObj->mtrl[currMtrl].SmthType = bVal; else if (sscanf(oneline, "Normal %d", &bVal) == 1) tDispObj->mtrl[currMtrl].NormType = bVal; } printf("done.\n"); printf("-> Number of materials: %d\n", ++currMtrl); numObjects = currMtrl; return true; }