/*** qytOpen - open a file or directory. ***/ void* qytOpen(pObject obj, int mask, pContentType systype, char* usrtype, pObjTrxTree* oxt) { pQytData inf; pSnNode node = NULL; char buf[1]; /** If CREAT and EXCL, we only create, failing if already exists. **/ if ((obj->Mode & O_CREAT) && (obj->Mode & O_EXCL) && (obj->SubPtr == obj->Pathname->nElements)) { node = snNewNode(obj->Prev, usrtype); if (!node) { mssError(0,"QYT","Could not create new querytree node object"); return NULL; } } /** Otherwise, try to open it first. **/ if (!node) { objRead(obj->Prev, buf, 0, 0, OBJ_U_SEEK); node = snReadNode(obj->Prev); } /** If no node, and user said CREAT ok, try that. **/ if (!node && (obj->Mode & O_CREAT) && (obj->SubPtr == obj->Pathname->nElements)) { node = snNewNode(obj->Prev, usrtype); } /** If _still_ no node, quit out. **/ if (!node) { mssError(0,"QYT","Could not open querytree node object"); return NULL; } /** Allocate the structure **/ inf = qyt_internal_ProcessPath(obj->Session, obj->Pathname, node, obj->SubPtr, node->Data, obj->Mode & (O_CREAT | OBJ_O_AUTONAME), 0); obj_internal_PathPart(obj->Pathname,0,0); if (!inf) return NULL; inf->Obj = obj; inf->Mask = mask; obj->SubCnt = obj->Pathname->nElements - obj->SubPtr + 1; /** Set object params. **/ inf->BaseNode = node; inf->BaseNode->OpenCnt++; inf->Offset = 0; return (void*)inf; }
/*** qytRead - Attempt to read from the underlying object. ***/ int qytRead(void* inf_v, char* buffer, int maxcnt, int offset, int flags, pObjTrxTree* oxt) { pQytData inf = QYT(inf_v); int rcnt; /** If no actual pathname (presented path was a text="") ... **/ if (inf->LLObj == NULL) { return qyt_internal_ReadText(inf, buffer, maxcnt, offset, flags, oxt); } /** Otherwise, attempt the read operation. **/ rcnt = objRead(inf->LLObj, buffer, maxcnt, offset, flags); return rcnt; }
/*** qyRead - Attempt to read from the underlying object. ***/ int qyRead(void* inf_v, char* buffer, int maxcnt, int offset, int flags, pObjTrxTree* oxt) { pQyData inf = QY(inf_v); int rcnt; /** If no actual pathname (presented path was a text="") ... **/ if (inf->LLObj == NULL) { mssError(1,"QY","Cannot read content from a text='' querytree object"); return -1; } /** Otherwise, attempt the read operation. **/ rcnt = objRead(inf->LLObj, buffer, maxcnt, offset, flags); return rcnt; }
void objInit(struct obj *obj, const char *filename) { fprintf(stderr, "< objRead"); objRead(obj, filename); fprintf(stderr, "> objRead"); objCount(obj); fprintf(stderr, "nbvtx=%d, nbnrm=%d, nbidx=%d\n", obj->nbvtx, obj->nbnrm, obj->nbidx); objParse(obj); free(obj->buf); /* int i; int id; float *vtx; for(i = 0; i < obj->nbidx; i++) { id = obj->idx[i*3]; vtx = obj->vtx; printf("%d) %f, %f, %f\n", id, vtx[id*3], vtx[id*3+1], vtx[id*3+2]); id = obj->idx[i*3+1]; printf("%d) %f, %f, %f\n", id, vtx[id*3], vtx[id*3+1], vtx[id*3+2]); id = obj->idx[i*3+2]; printf("%d) %f, %f, %f\n", id, vtx[id*3], vtx[id*3+1], vtx[id*3+2]); } */ }
/*** nht_internal_COPY - implements the COPY centrallix-http method. ***/ int nht_internal_COPY(pNhtSessionData nsess, pFile conn, pStruct url_inf, char* dest) { pObject source_obj,target_obj; int size; int already_exist = 0; char sbuf[256]; int cnt,rcnt,wcnt; /** Ok, open the source object here. **/ source_obj = objOpen(nsess->ObjSess, url_inf->StrVal, O_RDONLY, 0600, "text/html"); if (!source_obj) { sprintf(sbuf,"HTTP/1.0 404 Not Found\r\n" "Server: Centrallix/1.0\r\n" "\r\n" "<H1>404 Source Not Found</H1><HR><PRE>\r\n"); fdWrite(conn,sbuf,strlen(sbuf),0,0); mssPrintError(conn); netCloseTCP(conn,1000,0); thExit(); } /** Do we need to set params as a part of the open? **/ nht_internal_CkParams(url_inf, target_obj); /** Get the size of the original object, if possible **/ if (objGetAttrValue(source_obj,"size",&size) != 0) size = -1; /** Try to open the new object read-only to see if it exists... **/ target_obj = objOpen(nsess->ObjSess, dest, O_RDONLY, 0600, "text/html"); if (target_obj) { objClose(target_obj); already_exist = 1; } /** Ok, open the target object for keeps now. **/ target_obj = objOpen(nsess->ObjSess, dest, O_WRONLY | O_TRUNC | O_CREAT, 0600, "text/html"); if (!target_obj) { sprintf(sbuf,"HTTP/1.0 404 Not Found\r\n" "Server: Centrallix/1.0\r\n" "\r\n" "<H1>404 Target Not Found</H1>\r\n"); fdWrite(conn,sbuf,strlen(sbuf),0,0); netCloseTCP(conn,1000,0); thExit(); } /** Set the size of the new document... **/ if (size >= 0) objSetAttrValue(target_obj, "size", &size); /** Do the copy operation. **/ while((rcnt = objRead(source_obj, sbuf, 256, 0,0)) > 0) { while(rcnt > 0) { wcnt = objWrite(target_obj, sbuf, rcnt, 0,0); if (wcnt <= 0) break; rcnt -= wcnt; } } /** Close the objects **/ objClose(source_obj); objClose(target_obj); /** Ok, issue the HTTP header for this one. **/ if (nsess->IsNewCookie) { if (already_exist) { sprintf(sbuf,"HTTP/1.0 200 OK\r\n" "Server: Centrallix/1.0\r\n" "Set-Cookie: %s\r\n" "\r\n" "%s\r\n", nsess->Cookie, dest); } else { sprintf(sbuf,"HTTP/1.0 201 Created\r\n" "Server: Centrallix/1.0\r\n" "Set-Cookie: %s\r\n" "\r\n" "%s\r\n", nsess->Cookie, dest); } nsess->IsNewCookie = 0; } else { if (already_exist) { sprintf(sbuf,"HTTP/1.0 200 OK\r\n" "Server: Centrallix/1.0\r\n" "\r\n" "%s\r\n", dest); } else { sprintf(sbuf,"HTTP/1.0 201 Created\r\n" "Server: Centrallix/1.0\r\n" "\r\n" "%s\r\n", dest); } } fdWrite(conn,sbuf,strlen(sbuf),0,0); return 0; }
/*** nht_internal_GET - handle the HTTP GET method, reading a document or *** attribute list, etc. ***/ int nht_internal_GET(pNhtSessionData nsess, pFile conn, pStruct url_inf) { char sbuf[256]; int cnt; pStruct find_inf; pObjQuery query; char* dptr; char* ptr; char* aptr; pObject target_obj, sub_obj; char* bufptr; /*printf("GET called, stack ptr = %8.8X\n",&cnt);*/ /** If we're opening the "errorstream", pass of processing to err handler **/ if (!strncmp(url_inf->StrVal,"/errorstream",12)) { return nht_internal_ErrorHandler(nsess, conn); } /** Ok, open the object here. **/ target_obj = objOpen(nsess->ObjSess, url_inf->StrVal, O_RDONLY, 0600, "text/html"); if (!target_obj) { nht_internal_GenerateError(nsess); sprintf(sbuf,"HTTP/1.0 404 Not Found\r\n" "Server: Centrallix/1.0\r\n" "\r\n" "<H1>404 Not Found</H1><HR><PRE>\r\n"); fdWrite(conn,sbuf,strlen(sbuf),0,0); mssPrintError(conn); netCloseTCP(conn,1000,0); thExit(); } /** Do we need to set params as a part of the open? **/ nht_internal_CkParams(url_inf, target_obj); /** Ok, issue the HTTP header for this one. **/ if (nsess->IsNewCookie) { sprintf(sbuf,"HTTP/1.0 200 OK\r\n" "Server: Centrallix/1.0\r\n" "Set-Cookie: %s\r\n" "\r\n", nsess->Cookie); nsess->IsNewCookie = 0; } else { sprintf(sbuf,"HTTP/1.0 200 OK\r\n" "Server: Centrallix/1.0\r\n" "\r\n"); } fdWrite(conn,sbuf,strlen(sbuf),0,0); /** Check GET mode. **/ find_inf = stLookup_ne(url_inf,"ls__mode"); /** GET CONTENT mode. **/ if (!find_inf || !strcmp(find_inf->StrVal, "content")) { /** Check the object type. **/ objGetAttrValue(target_obj, "content_type", &ptr); if (!strcmp(ptr,"widget/page") || !strcmp(ptr,"widget/frameset")) { /*fdSetOptions(conn, FD_UF_WRBUF);*/ htrRender(conn, target_obj); } else { bufptr = (char*)nmMalloc(4096); while((cnt=objRead(target_obj,bufptr,4096,0,0)) > 0) { fdWrite(conn,bufptr,cnt,0,FD_U_PACKET); } if (cnt < 0) { mssError(0,"NHT","Incomplete read of object's content"); nht_internal_GenerateError(nsess); } nmFree(bufptr, 4096); } } /** GET DIRECTORY LISTING mode. **/ else if (!strcmp(find_inf->StrVal,"list")) { query = objOpenQuery(target_obj,"",NULL,NULL,NULL); if (query) { sprintf(sbuf,"<HTML><HEAD><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></HEAD><BODY><TT><A HREF=%s/..>..</A><BR>\n",url_inf->StrVal); fdWrite(conn,sbuf,strlen(sbuf),0,0); dptr = url_inf->StrVal; while(*dptr && *dptr == '/' && dptr[1] == '/') dptr++; while(sub_obj = objQueryFetch(query,O_RDONLY)) { objGetAttrValue(sub_obj, "name", &ptr); objGetAttrValue(sub_obj, "annotation", &aptr); sprintf(sbuf,"<A HREF=%s%s%s TARGET='%s'>%s</A><BR>\n",dptr, (dptr[0]=='/' && dptr[1]=='\0')?"":"/",ptr,ptr,aptr); fdWrite(conn,sbuf,strlen(sbuf),0,0); objClose(sub_obj); } objQueryClose(query); } else { nht_internal_GenerateError(nsess); } } /** GET METHOD LIST mode. **/ else if (!strcmp(find_inf->StrVal,"methods")) { } /** GET ATTRIBUTE-VALUE LIST mode. **/ else if (!strcmp(find_inf->StrVal,"attr")) { } /** Close the objectsystem entry. **/ objClose(target_obj); return 0; }