コード例 #1
0
static int
handle_assoc_response(const u_char *p)
{
	struct mgmt_body_t pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
	    IEEE802_11_AID_LEN))
		return 0;
	pbody.capability_info = EXTRACT_LE_16BITS(p);
	offset += IEEE802_11_CAPINFO_LEN;
	pbody.status_code = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_STATUS_LEN;
	pbody.aid = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_AID_LEN;

	parse_elements(&pbody, p, offset);

	printf(" AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 ,
	    CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
	    (pbody.status_code < NUM_STATUSES
		? status_text[pbody.status_code]
		: "n/a"));

	return 1;
}
コード例 #2
0
static int
handle_assoc_request(const u_char *p, u_int length)
{
	struct mgmt_body_t pbody;
	int offset = 0;
	int ret;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
		return 0;
	if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)
		return 0;
	pbody.capability_info = EXTRACT_LE_16BITS(p);
	offset += IEEE802_11_CAPINFO_LEN;
	length -= IEEE802_11_CAPINFO_LEN;
	pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_LISTENINT_LEN;
	length -= IEEE802_11_LISTENINT_LEN;

	ret = parse_elements(&pbody, p, offset, length);

	PRINT_SSID(pbody);
	PRINT_RATES(pbody);
	return ret;
}
コード例 #3
0
static int
handle_reassoc_request(const u_char *p)
{
	struct mgmt_body_t pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
	    IEEE802_11_AP_LEN))
		return 0;
	pbody.capability_info = EXTRACT_LE_16BITS(p);
	offset += IEEE802_11_CAPINFO_LEN;
	pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_LISTENINT_LEN;
	memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN);
	offset += IEEE802_11_AP_LEN;

	parse_elements(&pbody, p, offset);

	PRINT_SSID(pbody);
	printf(" AP : %s", etheraddr_string( pbody.ap ));

	return 1;
}
コード例 #4
0
static int
handle_probe_response(const u_char *p)
{
	struct mgmt_body_t  pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
	    IEEE802_11_CAPINFO_LEN))
		return 0;

	memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
	offset += IEEE802_11_TSTAMP_LEN;
	pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_BCNINT_LEN;
	pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_CAPINFO_LEN;

	parse_elements(&pbody, p, offset);

	PRINT_SSID(pbody);
	PRINT_RATES(pbody);
	PRINT_DS_CHANNEL(pbody);

	return 1;
}
コード例 #5
0
static int
handle_beacon(const u_char *p, u_int length)
{
	struct mgmt_body_t pbody;
	int offset = 0;
	int ret;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
	    IEEE802_11_CAPINFO_LEN))
		return 0;
	if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
	    IEEE802_11_CAPINFO_LEN)
		return 0;
	memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
	offset += IEEE802_11_TSTAMP_LEN;
	length -= IEEE802_11_TSTAMP_LEN;
	pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_BCNINT_LEN;
	length -= IEEE802_11_BCNINT_LEN;
	pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_CAPINFO_LEN;
	length -= IEEE802_11_CAPINFO_LEN;

	ret = parse_elements(&pbody, p, offset, length);

	PRINT_SSID(pbody);
	PRINT_RATES(pbody);
	printf(" %s",
	    CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS");
	PRINT_DS_CHANNEL(pbody);

	return ret;
}
コード例 #6
0
ファイル: print-802_11.c プロジェクト: OPSF/uClinux
static int
handle_probe_response(const u_char *p)
{
	struct mgmt_body_t  pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
	    IEEE802_11_CAPINFO_LEN))
		return 0;

	memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
	offset += IEEE802_11_TSTAMP_LEN;
	pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_BCNINT_LEN;
	pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_CAPINFO_LEN;

	if (!parse_elements(&pbody, p, offset))
		return 0;

	printf(" (");
	fn_print(pbody.ssid.ssid, NULL);
	printf(") ");
	PRINT_RATES(pbody);
	printf(" CH: %u%s", pbody.ds.channel,
	    CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" );

	return 1;
}
コード例 #7
0
ファイル: XMLParser.cpp プロジェクト: galek/hesperus
//#################### PUBLIC METHODS ####################
XMLElement_CPtr XMLParser::parse()
{
	XMLElement_Ptr root(new XMLElement("<root>"));

	std::vector<XMLElement_Ptr> children = parse_elements();
	for(std::vector<XMLElement_Ptr>::const_iterator it=children.begin(), iend=children.end(); it!=iend; ++it)
	{
		root->add_child(*it);
	}

	return root;
}
コード例 #8
0
static int
handle_auth(const u_char *p, u_int length)
{
	struct mgmt_body_t  pbody;
	int offset = 0;
	int ret;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, 6))
		return 0;
	if (length < 6)
		return 0;
	pbody.auth_alg = EXTRACT_LE_16BITS(p);
	offset += 2;
	length -= 2;
	pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset);
	offset += 2;
	length -= 2;
	pbody.status_code = EXTRACT_LE_16BITS(p + offset);
	offset += 2;
	length -= 2;

	ret = parse_elements(&pbody, p, offset, length);

	if ((pbody.auth_alg == 1) &&
	    ((pbody.auth_trans_seq_num == 2) ||
	     (pbody.auth_trans_seq_num == 3))) {
		printf(" (%s)-%x [Challenge Text] %s",
		    (pbody.auth_alg < NUM_AUTH_ALGS)
			? auth_alg_text[pbody.auth_alg]
			: "Reserved",
		    pbody.auth_trans_seq_num,
		    ((pbody.auth_trans_seq_num % 2)
		        ? ((pbody.status_code < NUM_STATUSES)
			       ? status_text[pbody.status_code]
			       : "n/a") : ""));
		return ret;
	}
	printf(" (%s)-%x: %s",
	    (pbody.auth_alg < NUM_AUTH_ALGS)
		? auth_alg_text[pbody.auth_alg]
		: "Reserved",
	    pbody.auth_trans_seq_num,
	    (pbody.auth_trans_seq_num % 2)
	        ? ((pbody.status_code < NUM_STATUSES)
		    ? status_text[pbody.status_code]
	            : "n/a")
	        : "");

	return ret;
}
コード例 #9
0
static int
handle_probe_request(const u_char *p)
{
	struct mgmt_body_t  pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	parse_elements(&pbody, p, offset);

	PRINT_SSID(pbody);
	PRINT_RATES(pbody);

	return 1;
}
コード例 #10
0
static int
handle_probe_request(const u_char *p, u_int length)
{
	struct mgmt_body_t  pbody;
	int offset = 0;
	int ret;

	memset(&pbody, 0, sizeof(pbody));

	ret = parse_elements(&pbody, p, offset, length);

	PRINT_SSID(pbody);
	PRINT_RATES(pbody);

	return ret;
}
コード例 #11
0
ファイル: print-802_11.c プロジェクト: OPSF/uClinux
static int
handle_probe_request(const u_char *p)
{
	struct mgmt_body_t  pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!parse_elements(&pbody, p, offset))
		return 0;

	printf(" (");
	fn_print(pbody.ssid.ssid, NULL);
	printf(")");
	PRINT_RATES(pbody);

	return 1;
}
コード例 #12
0
ファイル: mgmt.c プロジェクト: abnarain/mac-analyzer-quirm
int handle_beacon(const uchar *p, u_int length, struct rcv_pkt * paket)
{
    struct mgmt_body_t pbody;
    int offset = 0;
    int ret;
    memset(&pbody, 0, sizeof(pbody));
    if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + IEEE802_11_CAPINFO_LEN))
        return 0;
    if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
            IEEE802_11_CAPINFO_LEN)
        return 0;
    memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
    offset += IEEE802_11_TSTAMP_LEN;
    length -= IEEE802_11_TSTAMP_LEN;
    pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
    offset += IEEE802_11_BCNINT_LEN;
    length -= IEEE802_11_BCNINT_LEN;
    pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
    offset += IEEE802_11_CAPINFO_LEN;
    length -= IEEE802_11_CAPINFO_LEN;

    ret = parse_elements(&pbody, p, offset, length,paket);
    if (pbody.ssid_present) {
        fn_print(pbody.ssid.ssid, NULL,paket);
    }
    if (pbody.ds_present) {
        paket->p.mgmt_pkt.channel=pbody.ds.channel;
//       printf("packet channel = %d\n",pbody.ds.channel);
    }
    paket->p.mgmt_pkt.cap_privacy=  CAPABILITY_PRIVACY(pbody.capability_info) ? 1 :0 ;
    //  printf("%s \n",   CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS");

    u_int8_t _r;
    if (pbody.rates_present) {
        _r= pbody.rates.rate[pbody.rates.length -1] ;
        paket->p.mgmt_pkt.rate_max=(float)((.5 * ((_r) & 0x7f)));
        //    printf("packet rate is %f \n", paket->p.mgmt_pkt.rate_max);
    }
    else {
        paket->p.mgmt_pkt.rate_max=0.0; // undefined rate, because of bad fcs (might be a reason)
    }
    paket->p.mgmt_pkt.cap_ess_ibss = paket->p.mgmt_pkt.cap_ess_ibss=  CAPABILITY_ESS(pbody.capability_info) ? 1:2;
    return ret;
}
コード例 #13
0
ファイル: print-802_11.c プロジェクト: OPSF/uClinux
static int
handle_assoc_request(const u_char *p)
{
	struct mgmt_body_t pbody;
	int offset = 0;

	memset(&pbody, 0, sizeof(pbody));

	if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
		return 0;
	pbody.capability_info = EXTRACT_LE_16BITS(p);
	offset += IEEE802_11_CAPINFO_LEN;
	pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
	offset += IEEE802_11_LISTENINT_LEN;

	if (!parse_elements(&pbody, p, offset))
		return 0;

	printf(" (");
	fn_print(pbody.ssid.ssid, NULL);
	printf(")");
	PRINT_RATES(pbody);
	return 1;
}
コード例 #14
0
ファイル: fake_ast.cpp プロジェクト: Bill-Gray/sat_code
int main( const int argc, const char **argv)
{
   FILE *ifile = fopen( argv[1], "rb");
   char line1[100], line2[100];
   const char *intl_id = NULL;
   double step_size = .1;
   int i, n_steps = 100;

   if( !ifile)
      {
      printf( "Couldn't open input file\n");
      exit( -1);
      }
   for( i = 1; i < argc; i++)
      if( argv[i][0] == '-')
         switch( argv[i][1])
            {
            case 'i':
               intl_id = argv[i] + 2;
               break;
            case 'n':
               n_steps = atoi( argv[i] + 2);
               break;
            default:
               printf( "Unrecognized option '%s'\n", argv[i]);
               break;
            }
   *line1 = '\0';
   sxpx_set_implementation_param( SXPX_DUNDEE_COMPLIANCE, 1);
   while( fgets( line2, sizeof( line2), ifile))
      {
      tle_t tle; /* Pointer to two-line elements set for satellite */
      int err_val;

      if( (!intl_id || !memcmp( intl_id, line1 + 9, 6))
                && (err_val = parse_elements( line1, line2, &tle)) >= 0)
         {                  /* hey! we got a TLE! */
         int is_deep = select_ephemeris( &tle);
         double sat_params[N_SAT_PARAMS], observer_loc[3];

         if( err_val)
            printf( "WARNING: TLE parsing error %d\n", err_val);
         for( i = 0; i < 3; i++)
            observer_loc[i] = '\0';
         if( is_deep)
            SDP4_init( sat_params, &tle);
         else
            SGP4_init( sat_params, &tle);
         for( i = 0; i < n_steps; i++)
            {
            double ra, dec, dist_to_satellite;
            double pos[3]; /* Satellite position vector */
            double t_since = (double)( i - n_steps / 2) * step_size;
            double jd = tle.epoch + t_since;

            t_since *= 1440.;
            if( is_deep)
               err_val = SDP4( t_since, &tle, sat_params, pos, NULL);
            else
               err_val = SGP4( t_since, &tle, sat_params, pos, NULL);
            if( err_val)
               printf( "Ephemeris error %d\n", err_val);
            get_satellite_ra_dec_delta( observer_loc, pos,
                                 &ra, &dec, &dist_to_satellite);
            epoch_of_date_to_j2000( jd, &ra, &dec);
            printf( "%-14sC%13.5f    %08.4f    %+08.4f",
                     intl_id, jd, ra * 180. / PI, dec * 180. / PI);
            printf( "                    TLEs 500\n");
            }
         }
      strcpy( line1, line2);
      }
   fclose( ifile);
   return( 0);
} /* End of main() */
コード例 #15
0
ファイル: sat_id.cpp プロジェクト: RTS2/rts2
int main( const int argc, const char **argv)
{
   const char *tle_file_name = "ALL_TLE.TXT";
   FILE *ifile = fopen( argv[1], "rb"), *tle_file;
   FILE *stations;
   char line1[100], line2[100], buff[90];
   double search_radius = .2;     /* default to .2-degree search */
   double lon = 0., rho_sin_phi = 0., rho_cos_phi = 0.;
   char curr_mpc_code[4];
   int i, debug_level = 0, show_non_mpc_report_lines = 0;
   char prev_obj[20];
   double prev_jd = 0., prev_ra = 0., prev_dec = 0.;

   if( argc == 1)
      error_exit( -2);

   if( !ifile)
      {
      printf( "Couldn't open input file %s\n", argv[1]);
      exit( -1);
      }

   stations = fopen( "ObsCodes.html", "rb");
   if( !stations)          /* perhaps stored with truncated extension? */
      stations = fopen( "ObsCodes.htm", "rb");
   if( !stations)          /* Or as a text file? */
      stations = fopen( "stations.txt", "rb");
   if( !stations)
      {
      printf( "Failed to find MPC station list 'ObsCodes.html'\n");
      printf( "This can be downloaded at:\n\n");
      printf( "http://www.minorplanetcenter.org/iau/lists/ObsCodes.html\n");
      exit( -1);
      }
   curr_mpc_code[0] = curr_mpc_code[3] = '\0';
   for( i = 1; i < argc; i++)
      if( argv[i][0] == '-')
         switch( argv[i][1])
            {
            case 'r':
               search_radius = atof( argv[i] + 2);
               break;
            case 't':
               tle_file_name = argv[i] + 2;
               break;
               break;
            case 'd':
               debug_level = atoi( argv[i] + 2);
               break;
            case 'a':
               show_non_mpc_report_lines = 1;
               break;
            default:
               printf( "Unrecognized command-line option '%s'\n", argv[i]);
               exit( -2);
               break;
            }

   tle_file = fopen( tle_file_name, "rb");
   if( !tle_file)
      {
      printf( "Couldn't open TLE file %s\n", tle_file_name);
      exit( -1);
      }

   *prev_obj = '\0';
   while( fgets( buff, sizeof( buff), ifile))
      {
      double target_ra, target_dec, jd;

      if( !get_mpc_data( buff, &jd, &target_ra, &target_dec))
         {
         char preceding_line[80], line0[100];
         double observer_loc[3], observer_loc2[3];

         printf( "\n%s", buff);
         if( !memcmp( prev_obj, buff, 12) && fabs( jd - prev_jd) < .3)
            {
            double motion, posn_ang;

            if( !compute_motion( jd - prev_jd,
                  (target_ra - prev_ra) * cos( (prev_dec + target_dec) / 2.),
                  (target_dec - prev_dec), &motion, &posn_ang))
               printf( "    Object motion is %.3lf'/sec at PA %.1lf\n",
                  motion, posn_ang);
            }

         memcpy( prev_obj, buff, 12);
         prev_ra = target_ra;
         prev_dec = target_dec;
         prev_jd = jd;
         if( memcmp( curr_mpc_code, buff + 77, 3))
            {
            char tbuff[100];
            int got_it = 0;

            memcpy( curr_mpc_code, buff + 77, 3);
            fseek( stations, 0L, SEEK_SET);
            while( !got_it && fgets( tbuff, sizeof( tbuff), stations))
               got_it = !memcmp( tbuff, curr_mpc_code, 3);
            if( got_it)
               sscanf( tbuff + 3, "%lf %lf %lf",
                                     &lon, &rho_cos_phi, &rho_sin_phi);
            if( !got_it)
               printf( "FAILED to find MPC code %s\n", curr_mpc_code);
            }

         if( debug_level)
            printf( "lon = %.5lf rho cos phi = %.5lf rho sin phi = %.5lf\n",
                                      lon,  rho_cos_phi, rho_sin_phi);
         observer_cartesian_coords( jd,
                lon * PI / 180., rho_cos_phi, rho_sin_phi, observer_loc);
         observer_cartesian_coords( jd + TIME_EPSILON,
                lon * PI / 180., rho_cos_phi, rho_sin_phi, observer_loc2);

         fseek( tle_file, 0L, SEEK_SET);
         *line0 = '\0';
         if( fgets( line1, sizeof( line1), tle_file))
            while( fgets( line2, sizeof( line2), tle_file))
               {
               tle_t tle;  /* Structure for two-line elements set for satellite */

               if( parse_elements( line1, line2, &tle) >= 0)
                  {                           /* hey! we got a TLE! */
                  int is_deep = select_ephemeris( &tle);
                  double sat_params[N_SAT_PARAMS], radius, d_ra, d_dec;
                  double ra, dec, dist_to_satellite, t_since;
                  double pos[3]; /* Satellite position vector */
                  double unused_delta2;

                  if( debug_level > 1)
                     printf( "%s", line1);
                  t_since = (jd - tle.epoch) * 1440.;
                  if( is_deep)
                     {
                     SDP4_init( sat_params, &tle);
                     SDP4( t_since, &tle, sat_params, pos, NULL);
                     }
                  else
                     {
                     SGP4_init( sat_params, &tle);
                     SGP4( t_since, &tle, sat_params, pos, NULL);
                     }
                  if( debug_level > 1)
                     printf( "%s", line2);
                  if( debug_level > 2)
                     printf( " %.5lf %.5lf %.5lf\n", pos[0], pos[1], pos[2]);
                  get_satellite_ra_dec_delta( observer_loc, pos,
                                          &ra, &dec, &dist_to_satellite);
                  if( debug_level > 3)
                     printf( "RA: %.5lf dec: %.5lf\n", ra * 180. / PI,
                                                      dec * 180. / PI);
                  epoch_of_date_to_j2000( jd, &ra, &dec);
                  d_ra = (ra - target_ra + PI * 4.);
                  while( d_ra > PI)
                     d_ra -= PI + PI;
                  d_dec = dec - target_dec;
                  radius = sqrt( d_ra * d_ra + d_dec * d_dec) * 180. / PI;
                  if( radius < search_radius)      /* good enough for us! */
                     {
                     double arcmin_per_sec, posn_ang;


                                       /* Compute position one second later,  so we */
                                       /* can show speed/PA of motion: */
                     t_since += TIME_EPSILON * 1440.;
                     if( is_deep)
                        SDP4( t_since, &tle, sat_params, pos, NULL);
                     else
                        SGP4( t_since, &tle, sat_params, pos, NULL);
                     get_satellite_ra_dec_delta( observer_loc2, pos,
                                             &d_ra, &d_dec, &unused_delta2);
                     epoch_of_date_to_j2000( jd, &d_ra, &d_dec);
                     d_ra -= ra;
                     d_dec -= dec;
                     while( d_ra > PI)
                        d_ra -= PI + PI;
                     while( d_ra < -PI)
                        d_ra += PI + PI;
                                /* Put RA into 0 to 2pi range: */
                     if( !compute_motion( TIME_EPSILON, d_ra * cos( dec), d_dec,
                                    &arcmin_per_sec, &posn_ang))
                        {
                        line1[8] = line1[16] = '\0';
                        memcpy( line1 + 30, line1 + 11, 6);
                        line1[11] = '\0';
                        printf( "   %s = %s%s-%s",
                              line1 + 2, (line1[9] >= '6' ? "19" : "20"),
                              line1 + 9, line1 + 30);
                        printf( " e=%.2lf; P=%.1lf min; i=%.1lf",
                                     tle.eo,
                                     2. * PI / tle.xno,
                                     tle.xincl * 180. / PI);
                        if( strlen( line0) < 30)         /* object name given... */
                           printf( ": %s\n", line0);     /* not all TLEs do this */
                        else
                           printf( "\n");
                        printf( "   delta=%8.1lf km; offset=%5.2lf degrees; motion %6.3lf'/sec at PA=%.1lf\n",
                              dist_to_satellite, radius, arcmin_per_sec,
                              posn_ang);
                                    /* "Speed" is displayed in arcminutes/second,
                                       or in degrees/minute */
                        }
                     }
                  }
               strcpy( preceding_line, line1);
               strcpy( line0, line1);
               strcpy( line1, line2);
               for( i = 0; line0[i] >= ' '; i++)
                  ;
               line0[i] = '\0';        /* remove trailing CR/LF */
               }
         }
      else if( show_non_mpc_report_lines)
         printf( "%s", buff);
      }
   fclose( tle_file);
   fclose( stations);
   fclose( ifile);
   return( 0);
} /* End of main() */
コード例 #16
0
ファイル: XMLParser.cpp プロジェクト: galek/hesperus
XMLElement_Ptr XMLParser::parse_element()
{
	XMLToken_Ptr token;

	token = read_token();
	if(!token)
	{
		// If there are no tokens left, we're done.
		return XMLElement_Ptr();
	}

	if(token->type() != XMLT_LBRACKET)
	{
		// If the token isn't '<', we're reading something other than an element.
		m_lookahead.push_back(token);
		return XMLElement_Ptr();
	}

	token = read_checked_token(XMLT_IDENT);

	XMLElement_Ptr element(new XMLElement(token->value()));

	token = read_token();
	while(token && token->type() == XMLT_IDENT)						// while there are attributes to be processed
	{
		std::string attribName = token->value();
		read_checked_token(XMLT_EQUALS);
		token = read_checked_token(XMLT_VALUE);
		std::string attribValue = token->value();
		element->set_attribute(attribName, attribValue);

		token = read_token();
	}

	if(!token) throw Exception("Token unexpectedly missing");

	switch(token->type())
	{
		case XMLT_RBRACKET:
		{
			// This element has sub-elements, so parse them recursively and add them to the current element.
			std::vector<XMLElement_Ptr> children = parse_elements();
			for(std::vector<XMLElement_Ptr>::const_iterator it=children.begin(), iend=children.end(); it!=iend; ++it)
			{
				element->add_child(*it);
			}

			// Read the element closing tag.
			read_checked_token(XMLT_LSLASH);
			token = read_checked_token(XMLT_IDENT);
			if(token->value() != element->name()) throw Exception("Mismatched element tags: expected " + element->name() + " not " + token->value());
			read_checked_token(XMLT_RBRACKET);

			break;
		}
		case XMLT_RSLASH:
		{
			// The element is complete, so just break and return it.
			break;
		}
		default:
		{
			throw Exception("Unexpected token type");
		}
	}

	return element;
}
コード例 #17
0
static gboolean
parse_elements (GUPnPDIDLLiteParser *parser,
                xmlNode             *node,
                GUPnPAVXMLDoc       *xml_doc,
                xmlNs               *upnp_ns,
                xmlNs               *dc_ns,
                xmlNs               *dlna_ns,
                xmlNs               *pv_ns,
                gboolean             recursive,
                GError             **error)
{
        xmlNode *element;

        for (element = node->children; element; element = element->next) {
                GUPnPDIDLLiteObject *object;

                object = gupnp_didl_lite_object_new_from_xml (element, xml_doc,
                                                              upnp_ns, dc_ns,
                                                              dlna_ns, pv_ns);

                if (object == NULL)
                        continue;

                if (GUPNP_IS_DIDL_LITE_CONTAINER (object)) {
                        g_signal_emit (parser,
                                       signals[CONTAINER_AVAILABLE],
                                       0,
                                       object);
                        if (recursive &&
                            !parse_elements (parser,
                                             element,
                                             xml_doc,
                                             upnp_ns,
                                             dc_ns,
                                             dlna_ns,
                                             pv_ns,
                                             recursive,
                                             error)) {
                                g_object_unref (object);

                                return FALSE;
                        }
                } else if (GUPNP_IS_DIDL_LITE_ITEM (object)) {
                        node = gupnp_didl_lite_object_get_xml_node (object);
                        if (!verify_didl_attributes (node)) {
                                g_object_unref (object);
                                g_set_error (error,
                                             G_MARKUP_ERROR,
                                             G_MARKUP_ERROR_PARSE,
                                             "Could not parse DIDL-Lite XML");

                                return FALSE;
                        }

                        g_signal_emit (parser,
                                       signals[ITEM_AVAILABLE],
                                       0,
                                       object);
                }

                g_signal_emit (parser,
                               signals[OBJECT_AVAILABLE],
                               0,
                               object);

                g_object_unref (object);
        }

        return TRUE;
}
コード例 #18
0
ファイル: elem2tle.cpp プロジェクト: Bill-Gray/sat_code
/* Main program */
int main( const int argc, const char **argv)
{
   const char *tle_filename = ((argc == 1) ? "test.tle" : argv[1]);
   FILE *ifile = fopen( tle_filename, "rb");
   tle_t tle; /* Pointer to two-line elements set for satellite */
   char line1[100], line2[100];
   int ephem = 1;       /* default to SGP4 */
   int i;               /* Index for loops etc */
   int n_failures = 0, n_simple = 0, n_simplex = 0;
   bool failures_only = false;

   for( i = 2; i < argc; i++)
      if( argv[i][0] == '-')
         switch( argv[i][1])
            {
            case 'f':
               failures_only = true;
               break;
            case 'v':
               verbose = 1;
               break;
            case 'd':
               dist_offset = atof( argv[i] + 2);
               break;
            case 's':
               vel_offset = atof( argv[i] + 2);
               break;
            default:
               printf( "Option '%s' unrecognized\n", argv[i]);
               break;
            }
   if( !ifile)
      {
      printf( "Couldn't open input TLE file %s\n", tle_filename);
      exit( -1);
      }
   *line1 = '\0';
   while( fgets( line2, sizeof( line2), ifile))
      {
      int got_data = 0;
      double state_vect[6];

      set_tle_defaults( &tle);
      if( strlen( line2) > 110 && line2[7] == '.' && line2[18] == '.'
                     && line2[0] == '2' && line2[1] == '4')
         {
         got_data = 3;           /* Find_Orb state vector ephemeris */
         tle.epoch = atof( line2);
         sscanf( line2 + 13, "%lf %lf %lf %lf %lf %lf",
                    state_vect + 0, state_vect + 1, state_vect + 2,
                    state_vect + 3, state_vect + 4, state_vect + 5);
         }
      else if( strlen( line1) > 55 && !memcmp( line1 + 50, " (TDB)", 6))
         {                                  /* JPL Horizons vector */
         const double obliq_2000 = 23.4392911 * PI / 180.;

         tle.epoch = atof( line1);          /* get JD epoch from header... */
         strcpy( line1, line2);
         if( fgets( line2, sizeof( line2), ifile))
            got_data = 1;
         sscanf( line1, "%lf %lf %lf",
                    state_vect + 0, state_vect + 1, state_vect + 2);
         sscanf( line2, "%lf %lf %lf",
                    state_vect + 3, state_vect + 4, state_vect + 5);
                      /* Cvt ecliptic to equatorial 2000: */
         rotate_vector( state_vect    , obliq_2000, 0);
         rotate_vector( state_vect + 3, obliq_2000, 0);
         }
      else if( parse_elements( line1, line2, &tle) >= 0)
         got_data = 2;

      if( got_data == 1 || got_data == 3)
         tle.epoch -= 68.00 / 86400.;       /* rough convert TDT to UTC */

      if( got_data)     /* hey! we got a TLE! */
         {
         double sat_params[N_SAT_PARAMS],  trial_state[6];
         int simple_rval;
         bool failed = false;
         tle_t new_tle;

         if( got_data == 1 || got_data == 3)
            {
            ephem = 3;        /* Use SDP4 for JPL Horizons vectors */
            for( i = 0; i < 6 && fabs( state_vect[i]) < 1.; i++)
               ;
            if( i == 6)   /* all small quantities,  must be in AU & AU/day : */
               {
               for( i = 0; i < 6; i++)
                  state_vect[i] *= AU_IN_KM;
               for( i = 3; i < 6; i++)
                  state_vect[i] /= seconds_per_day;
               }
            for( i = 3; i < 6; i++)    /* cvt km/sec to km/min */
               state_vect[i] *= seconds_per_minute;
            if( !failures_only)
               show_results( "Before:", NULL, state_vect);
            }
         else
            {
            int is_deep = select_ephemeris( &tle);

            if( is_deep && (ephem == 1 || ephem == 2))
               ephem += 2;    /* switch to an SDx */
            if( !is_deep && (ephem == 3 || ephem == 4))
               ephem -= 2;    /* switch to an SGx */

            /* Calling of NORAD routines */
            /* Each NORAD routine (SGP, SGP4, SGP8, SDP4, SDP8)   */
            /* will be called in turn with the appropriate TLE set */
            switch( ephem)
               {
               case 0:
                  SGP_init( sat_params, &tle);
                  SGP( 0., &tle, sat_params, state_vect, state_vect + 3);
                  break;
               case 1:
                  SGP4_init( sat_params, &tle);
                  SGP4( 0., &tle, sat_params, state_vect, state_vect + 3);
                  break;
               case 2:
                  SGP8_init( sat_params, &tle);
                  SGP8( 0., &tle, sat_params, state_vect, state_vect + 3);
                  break;
               case 3:
                  SDP4_init( sat_params, &tle);
                  SDP4( 0., &tle, sat_params, state_vect, state_vect + 3);
                  break;
               case 4:
                  SDP8_init( sat_params, &tle);
                  SDP8( 0., &tle, sat_params, state_vect, state_vect + 3);
                  break;
               }
            if( !failures_only)
               show_results( "Before:", &tle, state_vect);
            }

         new_tle = tle;
         simple_rval = compute_tle_from_state_vector( &new_tle, state_vect, ephem, trial_state);
         if( simple_rval)
            {
            n_simplex++;
            find_tle_via_simplex_method( &new_tle, state_vect, trial_state, ephem);
            }
         else
            n_simple++;

         compute_new_state_vect( &new_tle, trial_state, ephem);
         for( i = 0; i < 6; i++)
            {
            trial_state[i] -= state_vect[i];
            if( fabs( trial_state[i]) > 1e-6)
               failed = true;
            }
         if( failed && failures_only)
            show_results( "Before:", &tle, state_vect);
         if( failed || !failures_only)
            show_results( (simple_rval ? "Simplex result:" : "Simplest method:"),
                                &new_tle, trial_state);
         if( failed)
            n_failures++;
         }
      strcpy( line1, line2);
      }
   fclose( ifile);
   printf( "%d solved with simple method; %d with simplex\n", n_simple, n_simplex);
   if( n_failures)
      printf( "%d failures\n", n_failures);
   return(0);
} /* End of main() */
コード例 #19
0
/**
 * gupnp_didl_lite_parser_parse_didl_recursive:
 * @parser: A #GUPnPDIDLLiteParser
 * @didl: The DIDL-Lite XML string to be parsed
 * @error: The location where to store any error, or %NULL
 *
 * Parses DIDL-Lite XML string @didl, emitting the ::object-available,
 * ::item-available and ::container-available signals appropriately during the
 * process.
 *
 * Return value: TRUE on success.
 **/
gboolean
gupnp_didl_lite_parser_parse_didl_recursive (GUPnPDIDLLiteParser *parser,
                                             const char          *didl,
                                             gboolean             recursive,
                                             GError             **error)
{
        xmlDoc        *doc;
        xmlNode       *element;
        xmlNs         *upnp_ns = NULL;
        xmlNs         *dc_ns   = NULL;
        xmlNs         *dlna_ns = NULL;
        xmlNs         *pv_ns   = NULL;
        GUPnPAVXMLDoc *xml_doc = NULL;
        gboolean       result;

        doc = xmlRecoverMemory (didl, strlen (didl));
        if (doc == NULL) {
                g_set_error (error,
                             G_MARKUP_ERROR,
                             G_MARKUP_ERROR_PARSE,
                             "Could not parse DIDL-Lite XML:\n%s", didl);

                return FALSE;
        }

        /* Get a pointer to root element */
        element = xml_util_get_element ((xmlNode *) doc,
                                        "DIDL-Lite",
                                        NULL);
        if (element == NULL) {
                g_set_error (error,
                             G_MARKUP_ERROR,
                             G_MARKUP_ERROR_PARSE,
                             "No 'DIDL-Lite' node in the DIDL-Lite XML:\n%s",
                             didl);
                xmlFreeDoc (doc);

                return FALSE;
        }

        if (element->children == NULL) {
                g_set_error (error,
                             G_MARKUP_ERROR,
                             G_MARKUP_ERROR_EMPTY,
                             "Empty 'DIDL-Lite' node in the DIDL-Lite XML:\n%s",
                             didl);
                xmlFreeDoc (doc);

                return FALSE;
        }

        /* Create namespaces if they don't exist */
        upnp_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_UPNP);
        if (! upnp_ns)
                upnp_ns = xml_util_create_namespace (xmlDocGetRootElement (doc),
                                                     GUPNP_XML_NAMESPACE_UPNP);

        dc_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_DC);
        if (! dc_ns)
                dc_ns = xml_util_create_namespace (xmlDocGetRootElement (doc),
                                                   GUPNP_XML_NAMESPACE_DC);
        dlna_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_DLNA);
        if (! dlna_ns)
                dlna_ns = xml_util_create_namespace (xmlDocGetRootElement (doc),
                                                   GUPNP_XML_NAMESPACE_DLNA);

        pv_ns = xml_util_lookup_namespace (doc, GUPNP_XML_NAMESPACE_PV);
        if (! pv_ns)
                pv_ns = xml_util_create_namespace (xmlDocGetRootElement (doc),
                                                   GUPNP_XML_NAMESPACE_PV);

        xml_doc = xml_doc_new (doc);

        result = parse_elements (parser,
                                 element,
                                 xml_doc,
                                 upnp_ns,
                                 dc_ns,
                                 dlna_ns,
                                 pv_ns,
                                 recursive,
                                 error);
        xml_doc_unref (xml_doc);

        return result;
}