Exemplo n.º 1
0
Bezier *BezierBSPTree(Bezier *bezier, BSPTree *bsptree, int action)
{
    if (never_translucent((Geom *)bezier)) {
	return bezier;
    }

    switch (action) {
    case BSPTREE_CREATE:
	HandleRegister(&bezier->meshhandle,
		       (Ref *)bezier, bsptree, BSPTreeInvalidate);
	return bezier;
    case BSPTREE_DELETE:
	HandleUnregisterJust(&bezier->meshhandle,
			     (Ref *)bezier, bsptree,BSPTreeInvalidate);
	return bezier;
    case BSPTREE_ADDGEOM:
	if (bezier->mesh == NULL ||
	    bezier->mesh->nu != bezier->nu || bezier->mesh->nv != bezier->nv) {
	    bezier->geomflags |= BEZ_REMESH;
	}    
	if (bezier->geomflags & BEZ_REMESH) {
	    BezierReDice(bezier);
	}
	BSPTreeAddObject(bsptree, (Geom *)bezier->mesh);
	return bezier;
    default:
	return NULL;
    }
}
Exemplo n.º 2
0
bool proxy_processor::on_recv_msg(mysocket & s, const mymsg & msg)
{
	msg.read_buffer((int8_t*)g_msg_buffer, msg.size());
	int32_t recvmsgsize = g_netmsg.Unmarshal(g_msg_buffer, msg.size());
	LOG_DEBUG("recv cmd %d from %u size %d\n", 
		g_netmsg.m_ProxyMsgHead.m_CmdMsgPara.m_Type, 
		g_netmsg.m_ProxyMsgHead.m_SrcSvrID,
		recvmsgsize);

	if (recvmsgsize < 0)
	{
		return false;
	}

	switch (g_netmsg.m_ProxyMsgHead.m_CmdMsgPara.m_Type)
	{
	case Fproto::CMD_REGISTR:
		HandleRegister(s, g_netmsg);
		break;
	case Fproto::CMD_TRANS_BY_KEY_HASH:
		HandleTransByKey(s, g_netmsg);
		break;
	case Fproto::CMD_TRANS_BY_ID:
		HandleTransByID(s, g_netmsg);
		break;
	case Fproto::CMD_TRANS_BROADCAST:
		HandleTransBroadcast(s, g_netmsg);
		break;
	default:
		break;
	}

	return true;
}
Exemplo n.º 3
0
Geom *InstImport(Pool *p)
{
    Inst *inst = NULL;
    IOBFILE *file;
    char *expect = NULL;
    int c;

    if(p == NULL || (file = PoolInputFile(p)) == NULL) {
	return 0;
    }

    if(strcmp(GeomToken(file), "INST")) {
	return 0;
    }

    for(;;) {
	switch((c = iobfnextc(file, 0))) {
	case EOF:
	case CKET:
	    goto done;

	case 'l':
	    if(iobfexpectstr(file, expect = "location")) {
		goto syntax;
	    }
	    if(inst == NULL) {
		inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
	    }
	    inst->location = getlocation( iobfdelimtok("(){}", file, 0) );
	    expect = "location [local|global|camera|ndc|screen]";
	    if(inst->location < 0) {
		goto syntax;
	    }
	    break;

	case 'o':
	    if(iobfexpectstr(file, expect = "origin")) {
		goto syntax;
	    }	    
	    if(inst == NULL) {
		inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
	    }

	    expect = "origin [local|global|camera|ndc|screen] X Y Z";
	    inst->origin = getlocation( iobfdelimtok("(){}", file, 0) );
	    if(inst->origin < 0) {
		goto syntax;
	    }
	    if(iobfgetnf(file, 3, &inst->originpt.x, 0) < 3) {
		goto syntax;
	    }
	    break;
	    
	    
	case 'u':
	    if(iobfexpectstr(file, expect = "unit")) {
		goto syntax;
	    }
	    goto geom;

	case 'g':
	    if(iobfexpectstr(file, expect = "geom"))
		goto syntax;

	geom:
	    if(inst == NULL) {
		inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
	    }
	    expect = "geometry";
	    if(!GeomStreamIn(p, &inst->geomhandle, &inst->geom)) {
		goto failed;
	    }
	    if(inst->geomhandle) {
		HandleRegister(&inst->geomhandle,
			       (Ref *)inst, &inst->geom, HandleUpdRef);
	    }
	    break;

	case 'n': /* ntransform */
	    if(iobfexpectstr(file, (expect = "ntransform"))) {
		goto syntax;
	    }
	    if(inst == NULL) {
		inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
	    }
	    expect = "ntransform matrix";
	    if(!NTransStreamIn(p, &inst->NDaxishandle, &inst->NDaxis)) {
		goto failed;
	    }
	    if(inst->NDaxishandle) {
		HandleRegister(&inst->NDaxishandle,
			       (Ref *)inst, &inst->NDaxis, HandleUpdRef);
	    }
	    break;
	    
	case 't':		/* tlist ... or transform ... */
	    if(inst == NULL) {
		inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
	    }
	    iobfgetc(file);
	    switch((c = iobfgetc(file))) {
	    case 'l':
		if(iobfexpectstr(file, (expect = "tlist")+2)) { /* "tlist" */
		    goto syntax;
		}
	    transforms:
		if(inst == NULL) {
		    inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
		}
		expect = "TLIST object";
		if(!GeomStreamIn(p, &inst->tlisthandle, &inst->tlist)) {
		    goto failed;
		}
		if(inst->tlisthandle) {
		    HandleRegister(&inst->tlisthandle,
				   (Ref *)inst, &inst->tlist, HandleUpdRef);
		}
		break;

	    case 'r':
		if(iobfexpectstr(file, (expect = "transform")+2)) {
		    /* "transform" */
		    goto syntax;
		}
		if(iobfexpectstr(file, "s") == 0) { /* transforms = tlist */
		    goto transforms;
		}
		if(inst == NULL) {
		    inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
		}
		expect = "transform matrix";
		if (!TransStreamIn(p, &inst->axishandle, inst->axis)) {
		    goto failed;
		}
		if (inst->axishandle) {
		    HandleRegister(&inst->axishandle,
				   (Ref *)inst, inst->axis, TransUpdate);
		}
		break;

	    case 'x':
		if (iobfexpectstr(file, (expect = "txtransforms")+2)) {
		    goto syntax;
		}
		if(inst == NULL) {
		    inst = (Inst *)GeomCCreate(NULL, InstMethods(), NULL);
		}
		expect = "TLIST object";
		if(!GeomStreamIn(p, &inst->txtlisthandle, &inst->txtlist)) {
		    goto failed;
		}
		if(inst->txtlisthandle) {
		    HandleRegister(&inst->txtlisthandle,
				   (Ref *)inst, &inst->txtlist, HandleUpdRef);
		}
		break;

	    default:
		expect = "something";
		goto syntax;

	    }
	    break;

	default:
	syntax:
	    OOGLSyntax(file, "Couldn't read INST in \"%s\": "
		       "syntax error, expected %s, got char %c",
		       p->poolname, expect, c);
	    goto bogus;

	failed:
	    OOGLSyntax(file, "Couldn't read INST in \"%s\": expected %s",
		       PoolName(p), expect);

        bogus:
	    GeomDelete((Geom *)inst);
	    return NULL;
	}
    }

 done:

    return (Geom *)inst;
}
Exemplo n.º 4
0
Inst *InstBSPTree(Inst *inst, BSPTree *bsptree, int action)
{
  TransformPtr oldT, oldTxT;
  GeomIter *it, *txit;
  Transform T, tT, Tl2o, TxT;
  Transform oldTinv;

  if (inst->geom) {
    GeomMakePath(inst, 'I', path, pathlen);
    inst->geom->ppath = path;
    inst->geom->ppathlen = pathlen;
  }

  /* No need to loop over all transforms unless action == BSPTREE_ADDGEOM */
  switch (action) {
  case BSPTREE_CREATE:
    GeomBSPTree(inst->geom, bsptree, action);
    HandleRegister(&inst->geomhandle,
		   (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleRegister(&inst->tlisthandle,
		   (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleRegister(&inst->axishandle,
		   (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleRegister(&inst->NDaxishandle,
		   (Ref *)inst, bsptree, BSPTreeInvalidate);
    return inst;

  case BSPTREE_DELETE:
    /* unregister any pending callback */
    HandleUnregisterJust(&inst->geomhandle,
			 (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleUnregisterJust(&inst->tlisthandle,
			 (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleUnregisterJust(&inst->axishandle,
			 (Ref *)inst, bsptree, BSPTreeInvalidate);
    HandleUnregisterJust(&inst->NDaxishandle,
			 (Ref *)inst, bsptree, BSPTreeInvalidate);
    GeomBSPTree(inst->geom, bsptree, action);
    return inst;

  case BSPTREE_ADDGEOM:
    if (inst->NDaxis) {
      /* No need to add to the BSPTree here, will be handled by the
       * various draw_projected_BLAH() stuff.
       */
      return inst;
    }

    if ((inst->origin != L_NONE || inst->location > L_LOCAL)) {
      BSPTreeSet(bsptree, BSPTREE_ONESHOT, true, BSPTREE_END);
      if (bsptree->Tidinv == NULL) {
	if (bsptree->Tid != TM_IDENTITY) {
	  bsptree->Tidinv = obstack_alloc(&bsptree->obst, sizeof(Transform));
	  TmInvert(bsptree->Tid, bsptree->Tidinv);
	} else {
	  bsptree->Tidinv = TM_IDENTITY;
	}
      }
    }

    oldT = BSPTreePushTransform(bsptree, TM_IDENTITY);
    oldTxT = BSPTreePushTxTransform(bsptree, TM_IDENTITY);

    if (inst->origin != L_NONE) {
      TmInvert(oldT, oldTinv);
    }

    it = GeomIterate((Geom *)inst, DEEP);
    txit = GeomIterate((Geom *)inst->txtlist, DEEP);
    while (NextTransform(it, T)) {

      /* Compute origin *before* changing mg tfm */
      if (inst->origin != L_NONE) {	    
	Point3 originwas, delta;
	TmCoord (*l2o)[4], (*o2W)[4];
	static HPoint3 zero = { 0, 0, 0, 1 };

	/* We have location2W, origin2W. We want to translate
	 * in 'origin' coords such that (0,0,0) in location
	 * coords maps to originpt in origin coords.
	 */
	o2W = coords2W(inst->origin, oldT);
	l2o = coordsto(inst->location, inst->origin, oldT, oldTinv);
	HPt3TransPt3(l2o, &zero, &originwas);
	Pt3Sub(&inst->originpt, &originwas, &delta);
	TmTranslate(tT, delta.x, delta.y, delta.z);
	TmConcat(l2o, tT, Tl2o);
	TmConcat(T, Tl2o, tT);
	TmConcat(tT, o2W, T);
	/* finally concat with tree->Tid^{-1} to get the correct
	 * absolute positioning.
	 */
	if (inst->location > L_LOCAL) {
	  if (bsptree->Tid != TM_IDENTITY) {
	    TmConcat(T, bsptree->Tidinv, T);
	  }
	}
      } else if (inst->location > L_LOCAL) {
	TmConcat(T, coords2W(inst->location, oldT), T);
	if (bsptree->Tid != TM_IDENTITY) {
	  TmConcat(T, bsptree->Tidinv, T);
	}
      } else {
	TmConcat(T, oldT, T);
      }
      BSPTreeSetTransform(bsptree, T);
      if (!NextTransform(txit, TxT)) {
	txit = NULL;
      } else {
	TmConcat(TxT, oldTxT, TxT);
	BSPTreeSetTxTransform(bsptree, TxT);
      }
      GeomBSPTree(inst->geom, bsptree, action);
    }

    BSPTreePopTxTransform(bsptree, oldT);
    BSPTreePopTransform(bsptree, oldT);

    return inst;
  default:
    return NULL;
  }
}
Exemplo n.º 5
0
Texture *
_TxSet(Texture *tx, int attr1, va_list *alist)
{
  int mask;
  Handle *h;
  Image  *img;
  TransformPtr f;
  int attr;
  char *str;
  bool do_purge = false;
  bool img_files = false;
  bool do_delete = false;

  if (tx == NULL) {
    tx = OOGLNewE(Texture, "TxCreate Texture");
    TxDefault(tx);
    do_delete = true;
  }

#define NEXT(type) va_arg(*alist, type)
	
  for ( attr = attr1; attr != TX_END; attr = NEXT(int)) {
    switch (attr) { /* parse argument list */
    case TX_DOCLAMP:
      mask = NEXT(int);
      tx->flags = (tx->flags & ~(TXF_SCLAMP|TXF_TCLAMP)) |
	(mask & (TXF_SCLAMP|TXF_TCLAMP));
      break;
    case TX_APPLY:
      mask = NEXT(int);
      if (mask < TXF_MODULATE || mask > TXF_REPLACE) {
	OOGLError(1, "TxSet: bad value for TX_APPLY: %d must be %d..%d",
		  mask, TXF_MODULATE, TXF_DECAL);
	goto nope;
      }
      tx->apply = (enum apply_enum)mask;
      break;
    case TX_FILE:
      str = NEXT(char *);
      if (str && tx->filename && strcmp(str, tx->filename) == 0) {
	break;
      }
      if (tx->filename) {
	OOGLFree(tx->filename);
      }
      tx->filename = str ? strdup(str) : NULL;
      do_purge = true;
      img_files = true;
      break;
    case TX_ALPHAFILE:
      str = NEXT(char *);
      if (str && tx->alphafilename &&
	  strcmp(str, tx->alphafilename) == 0) {
	break;
      }
      if (tx->alphafilename) {
	OOGLFree(tx->alphafilename);
      }
      tx->alphafilename = str ? strdup(str) : NULL;
      do_purge = true;
      img_files = true;
      break;
#if 0
    case TX_DATA:
      str = NEXT(char *);
      if (tx->data && str != tx->data)
	OOGLFree(tx->data);
      tx->data = str;
      if (str)
	tx->flags |= TXF_LOADED;
      break;
    case TX_XSIZE:
      mask = NEXT(int);
      if (mask != tx->xsize)
	tx->flags &= ~TXF_LOADED;
      tx->xsize = mask;
      break;
    case TX_YSIZE:
      mask = NEXT(int);
      if (mask != tx->ysize)
	tx->flags &= ~TXF_LOADED;
      tx->ysize = mask;
      break;
    case TX_CHANNELS:
      mask = NEXT(int);
      if (mask != tx->channels)
	tx->flags &= ~TXF_LOADED;
      tx->channels = mask;
      break;
#endif
#if 0 /* not implemented */
    case TX_COORDS:
      mask = NEXT(int);
      if (mask < TXF_COORD_GIVEN||mask > TXF_COORD_NORMAL) {
	OOGLError(1, "TxSet: bad value for TX_APPLY: %d must be %d..%d",
		  mask, TXF_MODULATE, TXF_DECAL);
	goto nope;
      }
      tx->coords = mask;
      break;
#endif
    case TX_BACKGROUND:
      tx->background = *NEXT(Color *);
      break;
    case TX_HANDLE_IMAGE:
      h   = NEXT(Handle *);
      img = NEXT(Image *);
      if (tx->imghandle) {
	HandlePDelete(&tx->imghandle);
      }
      tx->imghandle = REFGET(Handle, h);
      if (h) {
	HandleRegister(&tx->imghandle, (Ref *)tx, &tx->image,
		       TxUpdateImage);
	HandleSetObject(tx->imghandle, (Ref *)img);
      } else {
	tx->image = REFGET(Image, img);
      }
      do_purge = true;
      break;
    case TX_HANDLE_TRANSFORM:
      h = NEXT(Handle *);
      f = NEXT(TransformPtr);
      if (tx->tfmhandle) {
	HandlePDelete( &tx->tfmhandle );
      }
      tx->tfmhandle = REFGET(Handle, h);
      TmCopy(f, tx->tfm);
      if (h) {
	HandleRegister(&tx->tfmhandle,
		       (Ref *)tx, tx->tfm, TransUpdate);
      }
      break;
    default:
      OOGLError(1, "TxSet: unknown attribute %d", attr);
      goto nope;
    }
  }

  if (do_purge) {
    tx->flags &= ~TXF_LOADED;
    TxPurge(tx);
  }

  if (img_files) {
  }

  return tx;

 nope:
  if (do_delete) {
    TxDelete(tx);
  }
  return NULL;
}
Exemplo n.º 6
0
/* see the comments in src/lib/gprim/geom/geomstream.c */
int
TxStreamIn(Pool *p, Handle **hp, Texture **txp)
{
  IOBFILE *stream;
  char *fname;
  Handle *h = NULL;
  Texture *tx = NULL;
  float val[16];
  struct txkw *kw;
  char *w, *raww;
  int i, k = 0;
  int brack = 0;
  int empty = 1;
  bool braces = true;
  /*int plus = 0;*/
  bool more, mine = true; /* Questionable -- we'll report all errors */

  if ((stream = PoolInputFile(p)) == NULL) {
    return 0;
  }
  fname = PoolName(p);

  more = false;
  do {
    iobfnextc(stream, 0);

    switch(i = iobfgetc(stream)) {
    case ':':
    case '<':
      w = iobfdelimtok("{}()", stream, 0);
      /*
       * Consider doing a path search.
       * Do this before calling HandleReferringTo()
       * to prevent spurious error messages.
       */
      if (i == '<' && (h = HandleByName(w, &TextureOps)) == NULL && w[0] != '/') {
	w = findfile(fname, raww = w);
	if (w == NULL) {
	  OOGLSyntax(PoolInputFile(p),
		     "Error reading \"%s\": can't find file \"%s\"",
		     fname, raww);
	}
      } else if (h) {
	HandleDelete(h);
      }
      h = HandleReferringTo(i, w, &TextureOps, NULL);
      if (h != NULL) {
	tx = (Texture *)HandleObject(h);
	RefIncr((Ref*)tx);
      }
      break;

    case EOF: brack = 0; break;
    case '{': brack++; braces = true; break;
    case '}':
      if (brack-- <= 0) {
	iobfungetc(i, stream);
      }
      break;
    case '-':
    case '!':
      /*plus = -1;*/
      break;
    case '+':
      /*plus = 1;*/
      break;
    case '*':  break;

    default:
      more = false;
      iobfungetc(i, stream);
      w = iobfdelimtok("{}()", stream, 0);
      if (w == NULL) {
	break;
      }	    

      for (i = sizeof(tx_kw)/sizeof(tx_kw[0]), kw = tx_kw; --i >= 0; kw++)
	if (!strcmp(kw->word, w))
	  break;
      if (i < 0) {
	if (mine)
	  OOGLSyntax(stream, "%s: unknown texture keyword %s",
		     fname, w);
	return 0;
      }
      if (tx == NULL) {
	tx = TxCreate(TX_END);
      }

      if (kw->args < 0) {
	char allowed[256], *tail = allowed;
	w = iobfdelimtok("{}()", stream, 0);
	if (w == NULL) w = "";
	allowed[0] = '\0';
	for (k = 1; strcmp((kw+k)->word, w); k++) {
	  sprintf(tail, " %s", (kw+k)->word);
	  tail += strlen(tail);
	  if (k + kw->args >= 0) {
	    OOGLSyntax(stream, "%s: %s %s: expected one of: %s",
		       fname, kw->word, w, allowed);
	    TxDelete(tx);
	    return 0;
	  }
	}
      } else if (kw->args > 0) {
	int n = iobfgetnf(stream, kw->args, val, 0);
	if (n != kw->args) {
	  OOGLSyntax(stream, "%s: %s expected %d numeric values",
		     fname, w, kw->args);
	  TxDelete(tx);
	  return 0;
	}
      }

      empty++;

      switch((int)kw->aval) {
      case -1:
	mine = more = true;
	empty--;
	break;

      case TX_APPLY:
	tx->apply = (enum apply_enum)(kw+k)->aval;
	break;

      case TX_FILE:
      case TX_ALPHAFILE:
	raww = iobfdelimtok("{}()", stream, 0);
	w = findfile(fname, raww);
	if (w == NULL) {
	  OOGLSyntax(stream,
		     "Warning: reading \"%s\": can't find file \"%s\", ignoring texture",
		     fname, raww);
	} else {
	  TxSet(tx, kw->aval, w, TX_END);
	}
	break;

#if 0 /* does not belong here */
      case TX_XSIZE:
      case TX_YSIZE:
      case TX_CHANNELS:
	if (val[0] < 1 ||
	    val[0] > (tx_kw[i].aval==TX_CHANNELS) ? 4 : 100000) {
	  OOGLSyntax(stream, "%s: Bad value for %s: %s",
		     fname, kw->word, w);
	  TxDelete(tx);
	  return 0;
	}
	TxSet(tx, kw->aval, (int)val[0], TX_END);
	break;
#endif

#if 0 /* not implemented */
      case TX_COORDS:
	tx->coords = (kw+k)->aval;
	break;
#endif
      case TX_BACKGROUND: {
	/* We allow ColorA for compatibility, but the texture
	 * background color really is only RGB, not RGBA (see
	 * glTexEnvf(3)). So: if the next character is not a closing
	 * brace and not '\n', consume the next float which should be
	 * the alpha component
	 */
	float dummy;
	int c;

	if ((c = iobfnextc(stream, 1)) != '\n' && c != '}' && c != EOF) {
	  if (iobfgetnf(stream, 1, &dummy, 0) < 1) {
	    OOGLSyntax(stream, "%s: background color expected", fname);
	    TxDelete(tx);
	    return false;
	  }
	}
	TxSet(tx, kw->aval, val, TX_END);
	break;
      }
      case TX_HANDLE_IMAGE:
	if (!ImgStreamIn(p, &tx->imghandle, &tx->image)) {
	  OOGLSyntax(stream, "%s: texture image definition expected",
		     fname);
	  TxDelete(tx);
	  return false;
	}
	if (tx->filename) {
	  OOGLFree(tx->filename);
	  tx->filename = NULL;
	}
	if (tx->alphafilename) {
	  OOGLFree(tx->alphafilename);
	  tx->alphafilename = NULL;
	}
	if (tx->imghandle) {
	  HandleRegister(&tx->imghandle, (Ref *)tx, &tx->image,
			 TxUpdateImage);
	}
	break;
      case TX_HANDLE_TRANSFORM:
	if (!TransStreamIn(p, &tx->tfmhandle, tx->tfm)) {
	  OOGLSyntax(stream, "%s: 4x4 texture transform expected",
		     fname);
	  TxDelete(tx);
	  return false;
	}
	if (tx->tfmhandle) {
	  HandleRegister(&tx->tfmhandle, (Ref *)tx,
			 tx->tfm, TransUpdate);
	}
	break;
      case TX_DOCLAMP:
	tx->flags = (kw+k)->aval;
	break;


      default:
	break;
      }
      /*plus = 0;*/
    }
  } while (brack > 0 || more);

  /* handle file and alphafile constructs */
  if (h == NULL && tx->filename) {
    struct stat st;
    char hname[2*(4+(INO_T_LSIZE+DEV_T_LSIZE+TIME_T_LSIZE)*SIZEOF_LONG)+1];
    char *ptr;

    if (tx->imghandle) {
      HandlePDelete(&tx->imghandle);
      tx->imghandle = NULL;
    }
    if (tx->image) {
      ImgDelete(tx->image);
      tx->image = NULL;
    }
	
    if (stat(tx->filename, &st) < 0) {
      OOGLSyntax(stream, "%s: cannot stat file %s", fname, tx->filename);
      TxDelete(tx);
      return 0;
    }

    ptr = hname;
    ptr += stat_to_handle(ptr, st.st_dev, st.st_ino, st.st_mtime);

    if (tx->alphafilename) {
      if (stat(tx->alphafilename, &st) < 0) {
	OOGLSyntax(stream,
		   "%s: cannot stat file %s", fname, tx->filename);
	TxDelete(tx);
	return 0;
      }
      ptr += stat_to_handle(ptr, st.st_dev, st.st_ino, st.st_mtime);
    }
    /* we share texture images defined by the same files, as was
     * the previous behaviour. However, this is implemented using
     * references and handles to image objects.
     */
    tx->imghandle = HandleByName(hname, &ImageOps);
    if (tx->imghandle != NULL) {
      tx->image = REFGET(Image, HandleObject(tx->imghandle));
    } else {
      /* This means there is no image, create one */
      tx->image = tx->alphafilename
	? ImgCreate(IMG_DATA_CHAN_FILE,
		    IMGF_AUTO, NULL, tx->filename,
		    IMG_DATA_CHAN_FILE,
		    IMGF_ALPHA, NULL, tx->alphafilename,
		    IMG_END)
	: ImgCreate(IMG_DATA_CHAN_FILE,
		    IMGF_AUTO, NULL, tx->filename,
		    IMG_END);
      if (!tx->image) {
	OOGLSyntax(stream,
		   "%s: cannot create image from given file(s) "
		   "(\"%s\"/\"%s\"",
		   fname, tx->filename, tx->alphafilename);
	TxDelete(tx);
	return 0;
      }
      /* Generate a new reference */
      tx->imghandle = HandleAssign(hname, &ImageOps, (Ref *)tx->image);
      tx->imghandle->permanent = false;
    }
  }

  /* Pass the ownership of h and tx to the caller if requested */

  if (hp != NULL) {
    /* pass on ownership of the handle h to the caller of this function */
    if (*hp != NULL) {
      if (*hp != h) {
	HandlePDelete(hp);
      } else {
	HandleDelete(*hp);
      }
    }
    *hp = h;
  } else if (h) {
    /* Otherwise delete h because we are its owner. Note that
     * HandleReferringTo() has passed the ownership of h to us;
     * explicitly defined handles (hdefine and define constructs)
     * will not be deleted by this call.
     */
    HandleDelete(h);
  }

  /* same logic as for hp */
  if (txp != NULL) {
    if (*txp != NULL) {
      TxDelete(*txp);
    }
    *txp = tx;
  } else if(tx) {
    TxDelete(tx);
  }

  return (tx != NULL || h != NULL || (empty && braces));
}
Exemplo n.º 7
0
void HandleClientMsg(SSL_CLIENT_DATA* ssl_data, int epollfd)
{
    if(!ssl_data)
        return;
    cJSON *root=NULL, *cmd=NULL, *attr=NULL, *child=NULL;
    SSL *ssl = ssl_data->ssl;
    char buffer[BUFF_LEN];
    int recvLen;
    bzero(buffer, BUFF_LEN);

    /*Receive information from client*/
    recvLen = SSL_recv(ssl, buffer, BUFF_LEN);
    if(recvLen <= 0 || strncmp(buffer, "quit", 4)==0)
    {
        printf("client quit!\n");
        int connfd = SSL_get_fd(ssl_data->ssl);
        Session_Delete(connfd);
        Session_Print_All();
        SSL_Client_Leave(ssl_data, epollfd);
        return;
    }
    printf("client %d: %s\n", SSL_get_fd(ssl_data->ssl), buffer);
    /*Parse the client message*/
    root = cJSON_Parse(buffer);
    if(!root)
    {
        printf("Error before: [%s]\n",cJSON_GetErrorPtr());
        HandleError(ssl, "JSON format not recognized.");
        return;
    }

    child = root->child;
    while(child)
    {
        if(strcmp(child->string, "cmd")==0)
        {
            cmd = child;
        } else if(strcmp(child->string, "attr")==0)
        {
            attr = child;
        }

        child = child->next;
    }

    if(0==strcmp(cmd->valuestring, "register"))
    {
        HandleRegister(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "cert_status_ok"))
    {
        HandleCertStatusUpdate(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "login"))
    {
        HandleLogin(ssl,attr);
    } else if(0==strcmp(cmd->valuestring, "query_pulse"))
    {
        HandleQueryPulse(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "file_query"))
    {
        HandleFileQuery(ssl,  attr);
    } else if(0==strcmp(cmd->valuestring, "sending_file_next"))
    {
        HandleSendingFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "receiving_file_next"))
    {
        HandleReceivingFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "open_file"))
    {
        HandleOpenFile(ssl, attr);
    } else if(0==strcmp(cmd->valuestring, "revoke_file"))
    {
        HandleRevokeFile(ssl, attr);
    }

    cJSON_Delete(root);
}