Пример #1
0
// a triangle with the normals specified
static int tcl_graphics_trinorm(MoleculeGraphics *gmol, 
				int argc, const char *argv[],
				Tcl_Interp *interp)
{
  // the first three are {x, y, z} coordinates
  // the next three are {x, y, z} normals
  MUST_HAVE(6, "trinorm");
  float vals[19];
  if (tcl_get_vector(argv[0], vals+0,  interp) != TCL_OK ||
      tcl_get_vector(argv[1], vals+3,  interp) != TCL_OK ||
      tcl_get_vector(argv[2], vals+6,  interp) != TCL_OK ||
      tcl_get_vector(argv[3], vals+9,  interp) != TCL_OK ||
      tcl_get_vector(argv[4], vals+12, interp) != TCL_OK ||
      tcl_get_vector(argv[5], vals+15, interp) != TCL_OK   ) {
    return TCL_ERROR;
  }

  // I have a triangle, so add it
  char tmpstring[64];
  sprintf(tmpstring, "%d",
	  gmol->add_trinorm(vals+0, vals+3, vals+6, 
			    vals+9, vals+12, vals+15));
  Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
  return TCL_OK;
}
Пример #2
0
// takes:
//  a color index
//  a color name (like "red")
static int tcl_graphics_color(VMDApp *app, MoleculeGraphics *gmol,
			      int argc, const char *argv[],
			      Tcl_Interp *interp)
{
  MUST_HAVE(1, "color");
  // is it a valid number?
  int id;
  Tcl_ResetResult(interp);
  if (Tcl_GetInt(interp, argv[0], &id) == TCL_OK) {
    // is it valid?
    if (id >=0 && id < MAXCOLORS) {
      char tmpstring[64];
      sprintf(tmpstring, "%d", gmol->use_color(id));
      Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
      return TCL_OK;
    } else {
      char tmpstring[64];
      sprintf(tmpstring, "graphics: color index value '%d' out of range", id);
      Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
      return TCL_ERROR;
    }
  }
  // is it a color name?
  Tcl_ResetResult(interp);
  id = app->color_index(argv[0]);
  if (id >= 0) { 
    char tmpstring[64];
    sprintf(tmpstring, "%d", gmol->use_color(id));
    Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
    return TCL_OK;
  }
  // Otherwise there is a problem
  Tcl_AppendResult(interp, "graphics: unknown color: ", argv[0], NULL);
  return TCL_ERROR;
}
Пример #3
0
// turn them on or off
static int tcl_graphics_materials(MoleculeGraphics *gmol,
				  int argc, const char *argv[],
				  Tcl_Interp *interp)
{
  MUST_HAVE(1, "materials");
  int val;
  if (Tcl_GetBoolean(interp, argv[0], &val) != TCL_OK) {
    return TCL_ERROR;
  }
  
  // enable/disable materials
  char tmpstring[64];
  sprintf(tmpstring, "%d", gmol->use_materials(val));
  Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
  return TCL_OK;
}
Пример #4
0
// only has coordinates
static int tcl_graphics_pickpoint(MoleculeGraphics *gmol, 
			      int argc, const char *argv[],
			      Tcl_Interp *interp)
{
  MUST_HAVE(1, "pickpoint");
  float vals[3];
  if (tcl_get_vector(argv[0], vals+0, interp) != TCL_OK) {
    return TCL_ERROR;
  }

  // we've got a point, so add it
  char tmpstring[64];
  sprintf(tmpstring, "%d", gmol->add_pickpoint(vals+0));
  Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
  return TCL_OK;
}
Пример #5
0
// set material for this graphics molecule
static int tcl_graphics_material(MoleculeGraphics *gmol,
				  int argc, const char *argv[],
				  Tcl_Interp *interp, MaterialList *mlist)
{
  MUST_HAVE(1, "material");
  int val = mlist->material_index(argv[0]);
  if (val < 0) {
    char tmpstring[1024];
    sprintf(tmpstring, "graphics: invalid material: %s", argv[0]);
    Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
    return TCL_ERROR;
  }
  const Material *mat = mlist->material(val); 
  char tmpstring[64];
  sprintf(tmpstring, "%d", gmol->use_material(mat));
  Tcl_SetResult(interp, tmpstring, TCL_VOLATILE);
  return TCL_OK;
} 
Пример #6
0
// The npdu is a raw packet including the ip header.
int miniggsn_snd_npdu_by_mgc(mg_con_t *mgp,unsigned char *npdu, unsigned len)
{
    // Verify the IP header.
    struct iphdr *ipheader = (struct iphdr*)npdu;
    // The return address must be the MS itself.
    uint32_t ms_ip_address = mgp->mg_ip;
    uint32_t packet_source_ip_addr = ipheader->saddr;
    uint32_t packet_dest_ip_addr = ipheader->daddr;

	char infobuf[200];
	MGINFO("ggsn: writing %s at %s",packettoa(infobuf,npdu,len),timestr().c_str());
	//MGLOGF("ggsn: writing proto=%s %d byte npdu to %s from %s at %s",
		//ip_proto_name(ipheader->protocol),
		//len,ip_ntoa(packet_dest_ip_addr,NULL),
		//ip_ntoa(packet_source_ip_addr,nbuf), timestr().c_str());

#define MUST_HAVE(assertion) \
    if (! (assertion)) { MGERROR("ggsn: Packet failed test, discarded: %s",#assertion); return -1; }

    if (mg_debug_level > 2) ip_hdr_dump(npdu,"npdu");
    MUST_HAVE(ipheader->version == 4);	// 4 as in IPv4
    MUST_HAVE(ipheader->ihl >= 5);		// Minimum header length is 5 words.

    int checksum = ip_checksum(ipheader,sizeof(*ipheader),NULL);
    MUST_HAVE(checksum == 0);				// If fails, packet is bad.

    MUST_HAVE(ipheader->ttl > 0);		// Time to live - how many hops allowed.


	// The blackberry sends ICMP packets, so we better support.
	// I'm just going to allow any protocol through.
    //MUST_HAVE(ipheader->protocol == IPPROTO_TCP || 
	//	ipheader->protocol == IPPROTO_UDP ||
	//	ipheader->protocol == IPPROTO_ICMP);

    MUST_HAVE(packet_source_ip_addr == ms_ip_address);

#if OLD_FIREWALL
    // The destination address may not be a local address on this machine
	// as configured by the operator.
	// Note these are all in network order, so be careful.
    //uint32_t local_ip_addr = inet_addr(mg_base_ip_str); // probably "192.168.99.1"
	uint32_t net_mask = inet_addr(mg_net_mask);			// probably "255.255.255.0"
    MUST_HAVE((packet_dest_ip_addr & net_mask) != (local_ip_addr & net_mask));
#endif

	for (GgsnFirewallRule *rp = gFirewallRules; rp; rp = rp->next) {
		MUST_HAVE((packet_dest_ip_addr & rp->ipMasknl) != (rp->ipBasenl & rp->ipMasknl));
	}

    // Decrement ttl and recompute checksum.  We are doing this in place.
    ipheader->ttl--;
    ipheader->check = 0;
    //ipheader->check = htons(ip_checksum(ipheader,sizeof(*ipheader),NULL));
    ipheader->check = ip_checksum(ipheader,sizeof(*ipheader),NULL);

	// Just write to the MS-side tunnel device.

	int result = write(tun_fd,npdu,len);
	if (result != (int) len) {
		MGERROR("ggsn: error: write(tun_fd,%d) result=%d %s",len,result,strerror(errno));
	}
    return 0;
}
Пример #7
0
void DlgFeedback::on_btnSend_clicked()
{
    using Feelings = app::Feedback::Feeling;
    using Response = app::Feedback::Response;

#define MUST_HAVE(x) \
    if (x->text().isEmpty()) {\
        x->setFocus(); \
        return; \
    }

    MUST_HAVE(ui_.editName);
    MUST_HAVE(ui_.editEmail);
    MUST_HAVE(ui_.editPlatform);
    MUST_HAVE(ui_.editVersion);

    feedback_.setType(uimode_);
    feedback_.setFeeling((Feelings)ui_.cmbFeelings->currentIndex());
    feedback_.setName(ui_.editName->text());
    feedback_.setEmail(ui_.editEmail->text());
    feedback_.setPlatform(ui_.editPlatform->text());
    feedback_.setVersion(ui_.editVersion->text());
    feedback_.setMessage(ui_.txtMessage->toPlainText());

    if (ui_.grpAttachment->isChecked())
    {
        MUST_HAVE(ui_.editAttachment);
        feedback_.setAttachment(ui_.editAttachment->text());
    }

    feedback_.setCountry(ui_.editCountry->text());

    feedback_.onComplete = [&](app::Feedback::Response r) {
        ui_.progress->setVisible(false);
        ui_.btnSend->setEnabled(true);
        switch (r)
        {
            case Response::Success:
                QMessageBox::information(this, windowTitle(),
                    "Thank you. Your message has been sent.");
                break;
            case Response::DirtyRottenSpammer:
                QMessageBox::critical(this, windowTitle(),
                    "You're submitting data too fast. Please hold off for a moment!");
                break;

            case Response::DatabaseUnavailable:
            case Response::DatabaseError:
            case Response::EmailUnavailable:
                QMessageBox::critical(this, windowTitle(),
                    "A database error occurred. Your message was not recorded. Please try again later.");
                break;

            case Response::NetworkError:
                QMessageBox::critical(this, windowTitle(),
                    "A network error occurred. Your message was not delivered. Please try again later.");
                break;
        }
    };
    feedback_.send();

    ui_.progress->setVisible(true);
    ui_.btnSend->setEnabled(false);
}