Beispiel #1
0
 static void
 dump_a ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::a_resource*) Ptr )->domain() << "\t" << ( (dns::a_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::a_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::a_resource*) Ptr )->rtype()) << "\t" << ( (dns::a_resource*) Ptr )->address().to_string() << std::endl;
 }
Beispiel #2
0
 static void
 dump_ns ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::ns_resource*) Ptr )->domain() << "\t" << ( (dns::ns_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::ns_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::ns_resource*) Ptr )->rtype()) << "\t" << ( (dns::ns_resource*) Ptr )->nameserver() << std::endl;
 }
Beispiel #3
0
 static void
 dump_mx ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::mx_resource*) Ptr )->domain() << "\t" << ( (dns::mx_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::mx_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::mx_resource*) Ptr )->rtype()) << "\t" << ( (dns::mx_resource*) Ptr )->preference() << "\t"
       << ( (dns::mx_resource*) Ptr )->exchange() << std::endl;
 }
Beispiel #4
0
int networkifv6_internal_print(MYNETWORKIF * p,MYIPADDRESSINFO* pipaddress)
{
	int i;
	if(p==NULL || pipaddress==NULL)return 0;

	printf("IPADDRESSINFO\n");
	printf("    type=%s\n",get_type_string(pipaddress->type));

	printf("    ipAddress.type=%s\n",get_type_string(pipaddress->ipAddress.type));
	printf("    ipAddress.len=%d\n",pipaddress->ipAddress.len);
	printf("    ipAddress=");
	for(i=0;i<pipaddress->ipAddress.len;i++){
		int c=(pipaddress->ipAddress.type==1)?'.':':';

		if(i+1==pipaddress->ipAddress.len)c=' ';
		printf((pipaddress->ipAddress.type==1)?"%d%c":"%02x%c",pipaddress->ipAddress.address[i]&255,c);
	}
	printf("\n");

	printf("    netMask.type=%s\n",get_type_string(pipaddress->netMask.type));
	printf("    netMask.len=%d\n",pipaddress->netMask.len);
	printf("    netMask=");
	for(i=0;i<pipaddress->netMask.len;i++){
		int c='.';
		if(i+1==pipaddress->netMask.len)c=' ';
		printf("%d%c",pipaddress->netMask.address[i],c);
	}
	printf("\n");
	
	printf("    phyAddress.type=%s\n",get_type_string(pipaddress->phyAddress.type));
	printf("    phyAddress.len=%d\n",pipaddress->phyAddress.len);
	printf("    phyAddress=");
	for(i=0;i<pipaddress->phyAddress.len;i++){
		int c=':';
		if(i+1==pipaddress->phyAddress.len)c=' ';
		printf("%02x%c",pipaddress->phyAddress.address[i],c);
	}
	printf("\n");

	printf("\n");
	return 1;
}
Beispiel #5
0
int networkif_print(MYIPADDRESSINFO* pipaddress)
{
	int i;
	if(pipaddress==NULL)return 0;

	printf("IPADDRESSINFO\n");
	printf("    type=%s\n",get_type_string(pipaddress->type));

	printf("    ipAddress.type=%s\n",get_type_string(pipaddress->ipAddress.type));
	printf("    ipAddress.len=%d\n",pipaddress->ipAddress.len);
	printf("    ipAddress=");
	for(i=0;i<pipaddress->ipAddress.len;i++){
		int c='.';
		if(i+1==pipaddress->ipAddress.len)c=' ';
		printf("%d%c",pipaddress->ipAddress.address[i],c);
	}
	printf("\n");

	printf("    netMask.type=%s\n",get_type_string(pipaddress->netMask.type));
	printf("    netMask.len=%d\n",pipaddress->netMask.len);
	printf("    netMask=");
	for(i=0;i<pipaddress->netMask.len;i++){
		int c='.';
		if(i+1==pipaddress->netMask.len)c=' ';
		printf("%d%c",pipaddress->netMask.address[i],c);
	}
	printf("\n");
	
	printf("    phyAddress.type=%s\n",get_type_string(pipaddress->phyAddress.type));
	printf("    phyAddress.len=%d\n",pipaddress->phyAddress.len);
	printf("    phyAddress=");
	for(i=0;i<pipaddress->phyAddress.len;i++){
		int c=':';
		if(i+1==pipaddress->phyAddress.len)c=' ';
		printf("%02x%c",pipaddress->phyAddress.address[i],c);
	}
	printf("\n");

	printf("\n");
	return 1;
}
Beispiel #6
0
/*#  Generate an xml string   */
static int generate_xml_string(Prod_header* product, const char* file_name)
{
	static char* xml_string = NULL;
        int rda_elev_indx;
	char text[100];
	struct tm* time;
	char* desc = NULL;
	int i;
	int status;
	int lb_fd;
	float elevation;
	xml_string = STR_copy(xml_string, "<item>\n  <time fractional=\"0.000000\"> ");
	sprintf(text, "%d", (int) product->elev_t);
	xml_string = STR_cat(xml_string, text);
	xml_string = STR_cat(xml_string, " </time>\n  <params>NIDS FlatFile ");
	xml_string = STR_cat(xml_string, output_dir);
	xml_string = STR_cat(xml_string, " ");
	xml_string = STR_cat(xml_string, get_type_string(product));
	xml_string = STR_cat(xml_string, " ");
	xml_string = STR_cat(xml_string, file_name);
	xml_string = STR_cat(xml_string, " </params>\n  <selections> ");
	time = gmtime((const time_t*)&product->elev_t);
	sprintf(text, "%4.4d%2.2d%2.2d-%2.2d%2.2d%2.2d ",
		   time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
		   time->tm_hour, time->tm_min, time->tm_sec);
	xml_string = STR_cat(xml_string, text);

	desc = STR_copy(desc, ORPGPAT_get_description(product->g.prod_id, STRIP_MNEMONIC));
	for (i=0; (i < strlen(desc)); i++)
	{
	    if (desc[i] == ' ')
		desc[i] = '_';
	}
	xml_string = STR_cat(xml_string, desc);
	STR_free(desc);
        rda_elev_indx = ORPGVST_get_rda_index(product->g.elev_ind);
	elevation = ((float)ORPGVST_get_elevation(rda_elev_indx)) / 10;
	if (ORPGPAT_get_type(product->g.prod_id) == 0)
	   elevation = 0.0;
	sprintf(text, " %2.2f </selections>\n</item>\n", elevation);
	xml_string = STR_cat(xml_string, text);

	lb_fd = get_index_lb();
	if (lb_fd >= 0)
	{
		LE_send_msg(GL_INFO, "Writing xml string");
		LE_send_wrapped_string(GL_INFO, xml_string, 150);
		status = LB_write(lb_fd, xml_string, strlen(xml_string) + 1, LB_ANY);
		if (status < 0)
		   LE_send_msg(GL_INFO, "Error (%d) writing to index lb", status);
	}
	return(lb_fd);
}
Beispiel #7
0
void node::draw( D3DXMATRIX& matWorld ){

	D3DXMatrixIdentity(&matLocal);

	matLocal = matSelfSpin * matModelView * matParent * matWorld;

	calc_center();

	swprintf_s(s_information,STRING_SIZE, L"%sid: %d, type:%s, (%.2f, %.2f, %.2f), size:%.0f \n",
		s_information,
		this->nodeid,
		get_type_string(),
		center[0],
		center[1],
		center[2],
		this->size
		);

	// draw lines for debug
	d3d_ctrl.draw_axis( matLocal );
	
	d3d_ctrl.setWorldTransform( (matScale*matLocal) );
	primitive.draw();
	
	//draw child
	int count = 0;
	count = 0;
	for( nodelist::iterator it = child.begin(); it != child.end() ; it++ ){
		if( count == 0 ){
			for( int i = 0 ; i < nodelevel ; ++i ){
				swprintf_s( s_information,STRING_SIZE, L"%s    ", s_information );
			};
			swprintf_s( s_information,STRING_SIZE, L"%s     id: %d's child: \n",
				s_information,
				this->nodeid
				);
		}
		(*it)->draw( matLocal );
		count++;
	}
	if( count != 0 ){
		for( int i = 0 ; i < nodelevel ; ++i ){
				swprintf_s( s_information,STRING_SIZE, L"%s    ", s_information );
			};
		swprintf_s( s_information,STRING_SIZE, L"%s     end of id: %d's child: \n",
			s_information,
			this->nodeid
			);
	}
}
Beispiel #8
0
/**
 * \brief Function to compare two packets.
 * \param pkt1 Packet to compare.
 * \param pkt2 Packet to compare.
 * \return the difference in size between the two packets,
 */
int test_compare_packets(struct mqtt_packet *pkt1, struct mqtt_packet *pkt2) {
  int i;
  int delta = pkt1->len - pkt2->len;

  if (pkt1->fixed->generic.type != pkt1->fixed->generic.type) {
    log_std(LOG_ERROR, "Cannot compare packets of different type");
    return delta;
  }

  log_std(LOG_INFO, "Comparing %s type packets:",
      get_type_string(pkt1->fixed->generic.type));

  if (delta) {
    delta = (delta < 0) ? delta * -1 : delta;

    log_std(LOG_INFO, "Packet sizes differ by %d", delta);
    log_std(LOG_INFO, "pkt1 len: %zu pkt2 len: %zu", pkt1->len, pkt2->len);

    log_std(LOG_INFO, "\nPacket 1:");
    print_packet_hex_debug(pkt1);
    log_std(LOG_INFO, "\nPacket 2:");
    print_packet_hex_debug(pkt2);
    return delta;
  }

  for (i = 0; i < pkt1->len; i++) {
    if (pkt1->raw.buf[i] != pkt2->raw.buf[i]) {
      log_std(LOG_INFO, "Byte %d differs: pkt1: %02X pkt2: %02X",
          i, pkt1->raw.buf[i], pkt2->raw.buf[i]);
      delta++;
    }
  }

  if (!delta) {
    log_std(LOG_INFO, "Packets match exactly");
  } else {
    log_std(LOG_INFO, "\nPacket 1:");
    print_packet_hex_debug(pkt1);
    log_std(LOG_INFO, "\nPacket 2:");
    print_packet_hex_debug(pkt2);
  }

  return delta;
}
Beispiel #9
0
static void
dump_elan(Elan_t *elan)
{
  int i;

  printf("ELAN:%s (namelen:%d)\n",elan->elan_name, elan->elan_name_size);
  fflush(stdout);
  if (elan == default_elan) {
    printf("\tDEFAULT ELAN\n");
    fflush(stdout);
  }
  printf("\tMax frame size : %s\n", 
	 get_max_frame_size_string(elan->max_frame));
  fflush(stdout);
  printf("\tELAN type      : %s\n", get_type_string(elan->type));
  fflush(stdout);
  printf("\tLES address    : %s\n", get_atm_addr_string(elan->les_addr));
  fflush(stdout);
  for(i=0;i<elan->no_addresses;i++)
    printf("\t\t%s\n", elan->addresses[i]);
  printf("\t------------------------\n");
}
Beispiel #10
0
ObjectSettings
Dispenser::get_settings()
{
  ObjectSettings result = BadGuy::get_settings();
  result.options.push_back( ObjectOption(MN_NUMFIELD, _("Cycle"), &cycle,
                                         "cycle"));
  result.options.push_back( ObjectOption(MN_TOGGLE, _("Random"), &random,
                                         "random"));
  result.options.push_back( ObjectOption(MN_BADGUYSELECT, _("Enemies"), &badguys,
                                         "badguy"));

  ObjectOption seq(MN_STRINGSELECT, _("Type"), &type);
  seq.select.push_back(_("dropper"));
  seq.select.push_back(_("rocket launcher"));
  seq.select.push_back(_("cannon"));
  seq.select.push_back(_("invisible"));

  result.options.push_back( seq );

  type_str = get_type_string();
  result.options.push_back( ObjectOption(MN_TEXTFIELD, "type", &type_str, "type", false));
  return result;
}
Beispiel #11
0
 static void
 dump_srv ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::srv_resource*) Ptr )->domain() << "\t" << ( (dns::srv_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::srv_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::srv_resource*) Ptr )->rtype()) << "\t" << ( (dns::srv_resource*) Ptr )->priority() << "\t"
       << ( (dns::srv_resource*) Ptr )->weight() << "\t" << ( (dns::srv_resource*) Ptr )->port() << "\t"
       << ( (dns::srv_resource*) Ptr )->targethost() << std::endl;
 }
Beispiel #12
0
 static void
 dump_hinfo ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::hinfo_resource*) Ptr )->domain() << "\t" << ( (dns::hinfo_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::hinfo_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::hinfo_resource*) Ptr )->rtype()) << "\t" << ( (dns::hinfo_resource*) Ptr )->cpu() << "\t"
       << ( (dns::hinfo_resource*) Ptr )->os() << std::endl;
 }
Beispiel #13
0
 static void
 dump_cname ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::cname_resource*) Ptr )->domain() << "\t" << ( (dns::cname_resource*) Ptr )->ttl() << "\t"
       << get_class_string( ( (dns::cname_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::cname_resource*) Ptr )->rtype()) << "\t" << ( (dns::cname_resource*) Ptr )->canonicalname()
       << std::endl;
 }
Beispiel #14
0
 static void
 dump_soa ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   strm << ( (dns::soa_resource*) Ptr )->domain() << "\t" << ( (dns::soa_resource*) Ptr )->ttl() << "\t"
       << "SOA\t" << get_class_string( ( (dns::soa_resource*) Ptr )->rclass()) << "\t" << get_type_string(
       ( (dns::soa_resource*) Ptr )->rtype()) << "\t" << ( (dns::soa_resource*) Ptr )->master_name() << "\t"
       << ( (dns::soa_resource*) Ptr )->responsible_name() << "\t"
       << ( (dns::soa_resource*) Ptr )->serial_number() << "\t" << ( (dns::soa_resource*) Ptr )->refresh()
       << "\t" << ( (dns::soa_resource*) Ptr )->retry() << "\t" << ( (dns::soa_resource*) Ptr )->expire()
       << "\t" << ( (dns::soa_resource*) Ptr )->minttl() << std::endl;
 }
Beispiel #15
0
Dispenser::Dispenser(const ReaderMapping& reader) :
  BadGuy(reader, "images/creatures/dispenser/dispenser.sprite"),
  colgroup_active(COLGROUP_MOVING_STATIC),
  cycle(),
  badguys(),
  next_badguy(),
  dispense_timer(),
  autotarget(),
  swivel(),
  broken(),
  random(),
  type(),
  type_str()
{
  set_colgroup_active(COLGROUP_MOVING_STATIC);
  SoundManager::current()->preload("sounds/squish.wav");
  if ( !reader.get("cycle", cycle)) cycle = 5;
  if ( !reader.get("badguy", badguys)) badguys.clear();
  if ( !reader.get("random", random)) random = false;
  std::string type_s = "dropper"; //default
  if ( !reader.get("type", type_s)) type_s = "";
  if (type_s == "dropper") {
    type = DT_DROPPER;
  } else if (type_s == "rocketlauncher") {
    type = DT_ROCKETLAUNCHER;
  } else if (type_s == "cannon") {
    type = DT_CANNON;
  } else if (type_s == "point") {
    type = DT_POINT;
  } else {
    if(type_s.empty()) {
      log_warning << "No dispenser type set, setting to dropper." << std::endl;
    }
    else {
      log_warning << "Unknown type of dispenser:" << type_s << ", setting to dropper." << std::endl;
    }
    type = DT_DROPPER;
  }
  type_str = get_type_string();
  next_badguy = 0;
  autotarget = false;
  swivel = false;
  broken = false;

//  if (badguys.size() <= 0)
//    throw std::runtime_error("No badguys in dispenser.");

  switch (type) {
    case DT_DROPPER:
      sprite->set_action("dropper");
      break;
    case DT_ROCKETLAUNCHER:
      sprite->set_action(dir == LEFT ? "working-left" : "working-right");
      set_colgroup_active(COLGROUP_MOVING); //if this were COLGROUP_MOVING_STATIC MrRocket would explode on launch.
      colgroup_active = COLGROUP_MOVING;

      if (start_dir == AUTO) {
        autotarget = true;
      }
      break;
    case DT_CANNON:
      sprite->set_action("working");
      break;
    case DT_POINT:
      set_colgroup_active(COLGROUP_DISABLED);
      colgroup_active = COLGROUP_DISABLED;
    default:
      break;
  }

  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
  countMe = false;
}
Beispiel #16
0
 static void
 dump_a6 ( std::ostream& strm, dns::resource_base_t* Ptr )
 {
   try
   {
     strm << ( (dns::a6_resource*) Ptr )->domain() << "\t" << ( (dns::a6_resource*) Ptr )->ttl() << "\t"
         << get_class_string( ( (dns::a6_resource*) Ptr )->rclass()) << "\t" << get_type_string(
         ( (dns::a6_resource*) Ptr )->rtype()) << "\t" << ( (dns::a6_resource*) Ptr )->address().to_string()
         << std::endl;
   }
   catch( asio::error_code& ec )
   {
     strm << ec.message() << std::endl;
   }
 }
Beispiel #17
0
BOOL  DumpTAR_FAILED( LPDFSTR lpdf )
{
   BOOL  bRet = FALSE;
   LPTSTR   lpb = &gcOutBuf[0];  // [16K]
   LPTSTR   lpb2 = &gcOutBuf2[0];  // [16K]
   char * pv = (char *)lpdf->df_pVoid;
   struct posix_header * pph = (struct posix_header *)lpdf->df_pVoid;
   char * cp;
   size_t   off, boff, count, fsz, remains, len, hlen, culen;
   int   i;
   char c;
   size_t maxcnt = iFileCount + iDirCount;
   size_t entry = 0;
   enum read_header h;
   struct tar_stat_info * info = &current_stat_info;
   DWORD dwm = lpdf->dwmax;
   union block * p;
   if( !pph )
      return bRet;

   iMaxFileSize = 0;
   iMinFileSize = 0x7fffffff;
   current_block = (union block *)pv;
   dwm = lpdf->dwmax;
   p = current_block;
   while(dwm)
   {
      record_end = p;
      p++;
      if(dwm >= BLOCKSIZE)
      {
         dwm -= BLOCKSIZE;
         if(dwm == 0)
            record_end = p;
      }
      else
         dwm = 0;
   }

   if(( _strnicmp(pph->magic, TMAGIC, 5) == 0 )||
      ( rdhdr == HEADER_SUCCESS ) ){
      // we have a USTAR format
      off = 1;
      count = 0;
      sprtf( "TAR [%s] is [%s] format ..."MEOR,
         lpdf->fn,
         get_format_stg(current_format) );
      while(off)
      {
         entry++;
         boff = count * BLOCKSIZE;
         pph = (struct posix_header *) &pv[boff];
         if( (boff + BLOCKSIZE) > lpdf->dwmax )
         {
            sprtf( "WARNING: DATA EXPIRED BEFORE ZERO BLOCK!"MEOR );
            break;
         }
         tar_stat_destroy(info);
         current_header = (union block *)pph;
         h = tar_checksum ((union block *)pph, TRUE);
         form = -1;
         decode_header ((union block *)pph, info, &form, 0);
         //      if (header->header.typeflag == LNKTYPE)
         if( pph->typeflag == LNKTYPE )
            info->stat.st_size = 0;	/* links 0 size on tape */
         else
            info->stat.st_size = OFF_FROM_HEADER (pph->size);
         fsz = (size_t)info->stat.st_size;
         if( VERB5 )
         {
            cp = (char *)pph;
            sprtf( "%s: form [%s](%d): type [%s]: size %9d; offset %#08X; time %s"MEOR,
               get_header_stg( h ),
               get_format_stg(form),
               form,
               get_type_string( pph->typeflag),
               info->stat.st_size,
               (cp - pv),
               tartime( info->mtime, 0 ));
         }
         // else if (header->header.typeflag == XHDTYPE
		   // || header->header.typeflag == SOLARIS_XHDTYPE)
         if(( h == HEADER_SUCCESS )&&
            (( pph->typeflag == XHDTYPE )||
             ( pph->typeflag == SOLARIS_XHDTYPE )))
         {
            // we need to READ the xheader ...
            struct posix_header * pph_save = pph;
            fsz = (size_t)info->stat.st_size;
            len = 1;
            xheader_read (&info->xhdr, (union block *)pph, (size_t)fsz);
            if( VERB9 )
               sprtf( "Skipping %d extended header blocks ...\n", len );
            boff = ((count + len) * BLOCKSIZE);
            pph = (struct posix_header *)&pv[boff];
            if( (boff + BLOCKSIZE) > lpdf->dwmax )
            {
               sprtf( "WARNING: DATA EXPIRED BEFORE ZERO BLOCK!"MEOR );
               pph = pph_save;
               break;
            }
            tar_stat_destroy(info);
            pph = (struct posix_header *)current_block; // move up to this block
            current_header = (union block *)pph;
            h = tar_checksum ((union block *)pph, TRUE);
            form = -1;
            decode_header ((union block *)pph, info, &form, 0);
            if( pph->typeflag == LNKTYPE )
               info->stat.st_size = 0;	/* links 0 size on tape */
            else
               info->stat.st_size = OFF_FROM_HEADER (pph->size);
            fsz = (size_t)info->stat.st_size;
            if( h == HEADER_SUCCESS ) {
               XHDTYPE_count++;
               if( VERB5 )
               {
                  cp = (char *)pph;
                  sprtf( "%s: form [%s](%d): type [%s]: size %9d; offset %#08X; time %s"MEOR,
                     get_header_stg( h ),
                     get_format_stg(form),
                     form,
                     get_type_string( pph->typeflag),
                     info->stat.st_size,
                     (cp - pv),
                     tartime( info->mtime, 0 ));
               }
               count += len;
            } else {
               pph = pph_save;
               tar_stat_destroy(info);
               current_header = (union block *)pph;
               h = tar_checksum ((union block *)pph, TRUE);
               form = -1;
               decode_header ((union block *)pph, info, &form, 0);
            }
         }

         fsz = 0;
         i = collect_octal_size( lpb, pph, &fsz, 1 );
         off = collect_prefix_name( lpb, pph );
         if( off ) {
            // we GOT a NAME
            sprtf( "%5d %-50s %s %10d %s"MEOR,
               entry,
               lpb,
               get_type_string(pph->typeflag),
               fsz,
               tartime( info->mtime, 0 ));
            // gather counts
            switch(pph->typeflag)
            {
            case REGTYPE:
            case AREGTYPE:
               REGTYPE_count++;
               if( fsz > iMaxFileSize )
                  iMaxFileSize = fsz;
               if( fsz < iMinFileSize )
                  iMinFileSize = fsz;
               remains = fsz;
               while(remains)
               {
                  count++;
                  boff = count * BLOCKSIZE;
                  if(remains > BLOCKSIZE)
                     len = BLOCKSIZE;
                  else
                     len = remains;
                  culen = 0;
                  if( VERB9 && bExtraDebug )
                  {
                     while( len )
                     {
                        if(len > 16)
                           hlen = 16;
                        else
                           hlen = len;
                        *lpb = 0;
                        GetHEXString( lpb, &pv[boff+culen], hlen, pv, FALSE );
                        sprtf( "%s"MEOR, lpb );
                        len -= hlen;
                        culen += hlen;
                     }
                  }
                  pph = (struct posix_header *) &pv[boff];
                  if(remains > BLOCKSIZE)
                     remains -= BLOCKSIZE;
                  else
                     remains = 0;
               }
               break;
            case LNKTYPE:  // , "link" },
               LNKTYPE_count++;
               break;
            case SYMTYPE:  //, "reserved" },
               SYMTYPE_count++;
               break;
            case CHRTYPE:  // , "character special" },
               CHRTYPE_count++;
               break;
            case BLKTYPE:  //, "block special" }, //  '4'		/* block special */
               BLKTYPE_count++;
               break;
            case DIRTYPE:  // , "directory" },     //  '5'		/* directory */
               DIRTYPE_count++;
               break;
            case FIFOTYPE: //, "FIFO special" }, // '6'		/* FIFO special */
               FIFOTYPE_count++;
               break;
            case CONTTYPE: //, "reserved" },     // '7'		/* reserved */
               CONTTYPE_count++;
               break;
            case XHDTYPE:  //, "extended header" }, //  'x'   /* Extended header referring to the next file in the archive */
               XHDTYPE_count++;
               break;
            case XGLTYPE:  //, "global header" }, //  'g'            /* Global extended header */
               XGLTYPE_count++;
               break;
            default:
               default_count++;
               sprtf("WARNING: Uncased type %c!!!"MEOR, pph->typeflag);
               break;
            }
         }
         count++;
      }  // while ...

      if( max_warn_count < warn_count )
      {
         sprtf( "WARNING: Plus another [%d] OUT OF OCTAL RANGE!!!"MEOR,
            warn_count - max_warn_count );
      }

      // fell out because of a BLANK block
      sprtf( "Processed %d entries", maxcnt );
      if( REGTYPE_count ) {
         // case AREGTYPE: counted with above
         sprtf( ", %d file%s (min %d, max %d)",
            REGTYPE_count,
            ((REGTYPE_count == 1) ? "" : "s"),
            iMinFileSize,
            iMaxFileSize );
      }
      if( LNKTYPE_count )
         sprtf( ", %d link%s", LNKTYPE_count, ((LNKTYPE_count == 1) ? "" : "s") );
      if( SYMTYPE_count )
         sprtf( ", %d sym%s", SYMTYPE_count, ((SYMTYPE_count == 1) ? "" : "s") );
      if( CHRTYPE_count )
         sprtf( ", %d char%s", CHRTYPE_count, ((CHRTYPE_count == 1) ? "" : "s") );
      if( BLKTYPE_count )
         sprtf( ", %d block%s", BLKTYPE_count, ((BLKTYPE_count == 1) ? "" : "s") );
      if( DIRTYPE_count )
         sprtf( ", %d dir%s", DIRTYPE_count, ((DIRTYPE_count == 1) ? "" : "s") );
      if( FIFOTYPE_count )
         sprtf( ", %d fifo%s", FIFOTYPE_count, ((FIFOTYPE_count == 1) ? "" : "s") );
      if( CONTTYPE_count )
         sprtf( ", %d cont%s", CONTTYPE_count, ((CONTTYPE_count == 1) ? "" : "s") );
      if( XHDTYPE_count )
         sprtf( ", %d xhdr%s", XHDTYPE_count, ((XHDTYPE_count == 1) ? "" : "s") );
      if( XGLTYPE_count )
         sprtf( ", %d xgl%s", XGLTYPE_count, ((XGLTYPE_count == 1) ? "" : "s") );
      if( default_count )
         sprtf( ", %d default%s", default_count, ((default_count == 1) ? "" : "s") );
      sprtf( " (blocks %d)"MEOR,
         count );

      count++;
      boff = count * BLOCKSIZE;
      remains = (lpdf->dwmax - (boff + BLOCKSIZE));
      strcpy(lpb, (remains == 0 ? "perfect" : "remainder " ));
      if(remains) sprintf(EndBuf(lpb)," %d", remains );
      if(remains > 0)
      {
         off = 0;
         boff = count * BLOCKSIZE;
         if( VERB )
            sprtf( "Reached offset %d of %d ... %s"MEOR,
            (boff + BLOCKSIZE), lpdf->dwmax, lpb );
         while(remains > 0)
         {
            if(remains > BLOCKSIZE)
               len = BLOCKSIZE;
            else
               len = remains;
            culen = 0;
            remains -= len;
            while( len )
            {
               if(len > 16)
                  hlen = 16;
               else
                  hlen = len;
               for( i = 0; i < (int)hlen; i++ )
               {
                  c = pv[boff+culen+i];
                  if(c)
                     break;
               }
               if(c) {
                  if(VERB5)
                  {
                     *lpb = 0;
                     GetHEXString( lpb, &pv[boff+culen], hlen, pv, FALSE );
                     sprtf( "%s"MEOR, lpb );
                  }
                  off++;
               }
               len -= hlen;
               culen += hlen;
            }
            count++;
         }
         // done the remainder
         if( off == 0 ) {
            // NO HEX OUTPUT
            sprtf( "But it was ALL zeros ... (to %d)"MEOR, ((count+1) * BLOCKSIZE) );
         }
      }
      bRet = TRUE;
   }

   return bRet;
}
Beispiel #18
0
void log_attr(CK_ATTRIBUTE_PTR pAttr)
{
  const char *ctype = NULL;
  int       logtype = 0;
  FILE      *fp = NULL;
  char      string[129];
  const char *s;
  int       len = 0;
  CK_ULONG  ul = 0;
  CK_BBOOL	b;

  if (pAttr == NULL)
     return;

  util_lock(logmutex);

#ifdef WIN32
  if ((fopen_s(&fp,g_szLogFile, "a")) != 0)
#else
  if ((fp = fopen(g_szLogFile, "a")) == NULL)
#endif
     goto cleanup;

  map_log_info(pAttr->type, &ctype, &logtype);

  //log attribute type
  if (ctype)
     fprintf(fp, "\nAttribute type : %s\n", ctype); 
  else
     fprintf(fp, "\nAttribute type : ??? (0x%0lx)\n", pAttr->type); 

  //log value
  if (pAttr->pValue == NULL)
     {
     fprintf(fp, "Attribute Value: NULL\n");
     goto cleanup;
     }

  switch (logtype)
     {
     case T_TYPE:
        if (pAttr->ulValueLen != sizeof(CK_ULONG))
           {
           fprintf(fp, "Attribute Value: INVALID size for Value (CK_ULONG)\n)");
           break;
           }
        memcpy(&ul, (CK_ULONG*) pAttr->pValue, sizeof(CK_ULONG));
        s = get_type_string(pAttr->type, ul);
        fprintf(fp, "Attribute Value: %s\n", s);
        break;

     case T_BOOL:
        if (pAttr->ulValueLen != sizeof(CK_BBOOL))
           {
           fprintf(fp, "Attribute Value: INVALID size for Value (CK_BBOOL)\n)");
           break;
           }
        memcpy(&b, pAttr->pValue, sizeof(CK_BBOOL));
        fprintf(fp, b == CK_TRUE ? "Attribute Value: TRUE\n":"Value: FALSE\n"); 
        break;

     case T_STRING:
        len = pAttr->ulValueLen <= 128 ? pAttr->ulValueLen:128;
        memcpy(string, pAttr->pValue, len);
        string[len]=0;
        fprintf(fp, "Attribute Value: %s\n", string); 
        break;

     case T_UL:
        if (pAttr->ulValueLen != sizeof(CK_ULONG))
           {
           fprintf(fp, "Attribute Value: INVALID size for CK_ULONG\n)");
           break;
           }
         
        memcpy(&ul, (CK_ULONG*) pAttr->pValue, sizeof(CK_ULONG));
        fprintf(fp, "Attribute Value: 0x%lx\n",  ul); 
        break;

     default: ;
        /* if length < sizeof (CK_ULONG) => print as ULONG */
        if (pAttr->ulValueLen <= sizeof(CK_ULONG))
           {
           memcpy(&ul, pAttr->pValue, pAttr->ulValueLen);
           fprintf(fp, "Attribute Value: 0x%lx\n",  ul); 
           }
        else
           {
           fclose(fp);
           fp = NULL;
           log_xtrace(0, "Attribute Value: ", pAttr->pValue, pAttr->ulValueLen);
           }
     }
 
cleanup:
  util_unlock(logmutex);
  if (fp)
     fclose(fp);
}
Beispiel #19
0
/*******************************************************************
 *         demangle_datatype
 *
 * Attempt to demangle a C++ data type, which may be compound.
 * a compound type is made up of a number of simple types. e.g:
 * char** = (pointer to (pointer to (char)))
 *
 * Uses a simple recursive descent algorithm that is broken
 * and/or incomplete, without a doubt ;-)
 */
static char *demangle_datatype (char **str, compound_type *ct,
                                parsed_symbol* sym)
{
  char *iter;

  assert (str && *str);
  assert (ct);

  iter = *str;

  if (!get_constraints_convention_1 (&iter, ct))
    return NULL;

  if (*iter == '_')
  {
    /* MS type: __int8,__int16 etc */
    ct->flags |= CT_EXTENDED;
    iter++;
  }

  switch (*iter)
  {
    case 'C': case 'D': case 'E': case 'F': case 'G':
    case 'H': case 'I': case 'J': case 'K': case 'M':
    case 'N': case 'O': case 'X': case 'Z':
      /* Simple data types */
      ct->dest_type = *iter++;
      if (!get_constraints_convention_2 (&iter, ct))
        return NULL;
      ct->expression = get_type_string (ct->dest_type, ct->flags);
      break;
    case 'U':
    case 'V':
      /* Class/struct/union */
      ct->dest_type = *iter++;
      if (*iter == '0' || *iter == '1')
      {
        /* Referring to class type (implicit 'this') */
        char *stripped;
        if (!sym->argc)
          return NULL;

        iter++;
        /* Apply our constraints to the base type (struct xxx *) */
        stripped = strdup (sym->arg_text [0]);
        if (!stripped)
          fatal ("Out of Memory");

        /* If we're a reference, re-use the pointer already in the type */
        if (!(ct->flags & CT_BY_REFERENCE))
          stripped[ strlen (stripped) - 2] = '\0'; /* otherwise, strip it */

        ct->expression = str_create (2, ct->flags & CT_CONST ? "const " :
                         ct->flags & CT_VOLATILE ? "volatile " : "", stripped);
        free (stripped);
      }
      else if (*iter != '@')
      {
        /* The name of the class/struct, followed by '@@' */
        char *struct_name = iter;
        while (*iter && *iter++ != '@') ;
        if (*iter++ != '@')
          return NULL;
        struct_name = str_substring (struct_name, iter - 2);
        ct->expression = str_create (4, ct->flags & CT_CONST ? "const " :
                         ct->flags & CT_VOLATILE ? "volatile " : "", "struct ",
                         struct_name, ct->flags & CT_BY_REFERENCE ? " *" : "");
        free (struct_name);
      }
      break;
    case 'Q': /* FIXME: Array Just treated as pointer currently  */
    case 'P': /* Pointer */
      {
        compound_type sub_ct;
        INIT_CT (sub_ct);

        ct->dest_type = *iter++;
        if (!get_constraints_convention_2 (&iter, ct))
          return NULL;

        /* FIXME: P6 = Function pointer, others who knows.. */
        if (isdigit (*iter))
	{
	  if (*iter == '6')
	  {
	      int sub_expressions = 0;
	      /* FIXME: there are a tons of memory leaks here */
	      /* FIXME: this is still broken in some cases and it has to be
	       * merged with the function prototype parsing above...
	       */
	      iter += iter[1] == 'A' ? 2 : 3; /* FIXME */
	      if (!demangle_datatype (&iter, &sub_ct, sym))
		  return NULL;
	      ct->expression = str_create(2, sub_ct.expression, " (*)(");
	      if (*iter != '@')
	      {
		  while (*iter != 'Z')
		  {
		      FREE_CT (sub_ct);
		      INIT_CT (sub_ct);
		      if (!demangle_datatype (&iter, &sub_ct, sym))
			  return NULL;
		      if (sub_expressions)
                              ct->expression = str_create(3, ct->expression, ", ", sub_ct.expression);
		      else
                              ct->expression = str_create(2, ct->expression, sub_ct.expression);
		      while (*iter == '@') iter++;
		      sub_expressions++;
		  }
	      } else while (*iter == '@') iter++;
	      iter++;
	      ct->expression = str_create(2, ct->expression, ")");
	  }
	  else
	      return NULL;
	}
	else
	{
	    /* Recurse to get the pointed-to type */
	    if (!demangle_datatype (&iter, &sub_ct, sym))
		return NULL;

	    ct->expression = get_pointer_type_string (ct, sub_ct.expression);
	}

        FREE_CT (sub_ct);
      }
      break;
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
      /* Referring back to previously parsed type */
      if (sym->argc >= (size_t)('0' - *iter))
        return NULL;
      ct->dest_type = sym->arg_type ['0' - *iter];
      ct->expression = strdup (sym->arg_text ['0' - *iter]);
      iter++;
      break;
    default :
      return NULL;
  }
  if (!ct->expression)
    return NULL;

  return (char *)(*str = iter);
}
Beispiel #20
0
/**
 * \brief Function to process packets to the broker connection.
 * \param conn The connection to send the packet through.
 * \param pkt The packet to be processed.
 */
umqtt_ret broker_process_packet(struct broker_conn *conn, struct mqtt_packet *pkt) {
  LOG_DEBUG_FN("fn: broker_process_packet");

  umqtt_ret ret = UMQTT_SUCCESS;

  switch (pkt->fixed->generic.type) {

    case CONNECT:
      if (conn->proc && conn->proc->connect_method) {
        ret = conn->proc->connect_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case CONNACK:
      if (conn->proc && conn->proc->connack_method) {
        ret = conn->proc->connack_method(conn, pkt);

      } else {
        /* Processing response */
        if (pkt->variable->connack.connect_ret == CONN_ACCEPTED) {
          conn->state = UMQTT_CONNECTED;
        } else {
          conn->state = UMQTT_DISCONNECTED;
          LOG_ERROR("MQTT connect failed");
          ret = UMQTT_CONNECT_ERROR;
        }
      }
      break;

    case PUBLISH:
      if (conn->proc && conn->proc->publish_method) {
        ret = conn->proc->publish_method(conn, pkt);

      }
      break;

    case PUBACK:
      if (conn->proc && conn->proc->puback_method) {
        ret = conn->proc->puback_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case PUBCOMP:
      if (conn->proc && conn->proc->pubcomp_method) {
        ret = conn->proc->pubcomp_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case PUBREL:
      if (conn->proc && conn->proc->pubrel_method) {
        ret = conn->proc->pubrel_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case PUBREC:
      if (conn->proc && conn->proc->pubrec_method) {
        ret = conn->proc->pubrec_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case SUBSCRIBE:
      if (conn->proc && conn->proc->subscribe_method) {
        ret = conn->proc->subscribe_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case UNSUBSCRIBE:
      if (conn->proc && conn->proc->unsubscribe_method) {
        ret = conn->proc->unsubscribe_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case SUBACK:
      if (conn->proc && conn->proc->suback_method) {
        ret = conn->proc->suback_method(conn, pkt);

      } else {
        int i = 0;
        for (i = 0; i < conn->sub_count; i++) {
          if (pkt->variable->generic.pkt_id == conn->subs[i]->variable->generic.pkt_id) {
            if (pkt->payload->data == 0x00) {
              pkt->fixed->generic.type = SUBACK;
            } else {
              LOG_ERROR("bad SUBACK return: 0x%X", pkt->payload->data);
              ret = UMQTT_CONNECT_ERROR;
            }
            break;
          }
        }
      }
      break;

    case UNSUBACK:
      if (conn->proc && conn->proc->unsuback_method) {
        ret = conn->proc->unsuback_method(conn, pkt);

      } else {
        ret = UMQTT_PKT_NOT_SUPPORTED;
      }
      break;

    case PINGREQ:
      if (conn->proc && conn->proc->pingreq_method) {
        ret = conn->proc->pingreq_method(conn, pkt);

      } else {
        /* send PINGRESP */
        struct mqtt_packet *pkt_resp = construct_default_packet(PINGRESP, 0, 0);
        if (conn->send_method(conn, pkt)) {
          LOG_ERROR("Failed to send PINGRESP packet");
          ret = UMQTT_PACKET_ERROR;
        }
        free_packet(pkt_resp);
      }
      break;

    case PINGRESP:
      if (conn->proc && conn->proc->pingresp_method) {
        ret = conn->proc->pingresp_method(conn, pkt);

      } else {
        conn->state = UMQTT_CONNECTED;
      }
      break;

    case DISCONNECT:
      if (conn->proc && conn->proc->disconnect_method) {
        ret = conn->proc->disconnect_method(conn, pkt);

      } else {
        conn->state = UMQTT_DISCONNECTED;
      }
      break;

    default:
      ret = UMQTT_PKT_NOT_SUPPORTED;
  }

  if (ret == UMQTT_PKT_NOT_SUPPORTED) {
    LOG_ERROR("MQTT packet not currently supported: %s",
        get_type_string(pkt->fixed->generic.type));
  }

  return ret;
}