Beispiel #1
0
bool http_reply::add_header(std::string const & name, std::string const & value) 
{
	try 
	{
		add_header_directly(name, value);
		add_crlf();
	}
	catch (std::exception const & expt)
	{
		return false;
	}
	return true;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
   char str[1000], uname[80], upwd[80];
   char host_name[256], logbook[32], textfile[256], subdir[256];
   char *buffer[MAX_ATTACHMENTS], attachment[MAX_ATTACHMENTS][256];
   INT att_size[MAX_ATTACHMENTS];
   INT i, n, fh, n_att, n_attr, port, reply, quote_on_reply, edit, download, encoding, suppress, size, ssl,
       text_flag;
   char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];

   text[0] = textfile[0] = uname[0] = upwd[0] = suppress = quote_on_reply = 0;
   host_name[0] = logbook[0] = subdir[0] = 0;
   n_att = n_attr = reply = edit = download = encoding = 0;
   port = 80;
   ssl = 0;
   text_flag = 0;

   for (i = 0; i < MAX_ATTACHMENTS; i++) {
      attachment[i][0] = 0;
      buffer[i] = NULL;
      att_size[i] = 0;
   }

   /* parse command line parameters */
   for (i = 1; i < argc; i++) {
      if (argv[i][0] == '-' && argv[i][1] == 'v')
         verbose = 1;
      else if (argv[i][0] == '-' && argv[i][1] == 's')
         ssl = 1;
      else if (argv[i][0] == '-' && argv[i][1] == 'q')
         quote_on_reply = 1;
      else if (argv[i][0] == '-' && argv[i][1] == 'x')
         suppress = 1;
      else {
         if (argv[i][0] == '-') {
            if (i + 1 >= argc || argv[i + 1][0] == '-')
               goto usage;
            if (argv[i][1] == 'h')
               strcpy(host_name, argv[++i]);
            else if (argv[i][1] == 'p')
               port = atoi(argv[++i]);
            else if (argv[i][1] == 'l')
               strcpy(logbook, argv[++i]);
            else if (argv[i][1] == 'd')
               strcpy(subdir, argv[++i]);
            else if (argv[i][1] == 'u') {
               strcpy(uname, argv[++i]);
               strcpy(upwd, argv[++i]);
            } else if (argv[i][1] == 'a') {
               strcpy(str, argv[++i]);
               if (strchr(str, '=')) {
                  strcpy(attrib[n_attr], strchr(str, '=') + 1);
                  *strchr(str, '=') = 0;
                  strcpy(attr_name[n_attr], str);
                  n_attr++;
               } else {
                  printf("Error: Attributes must be supplied in the form \"-a <attribute>=<value>\".\n");
                  return 1;
               }
            } else if (argv[i][1] == 'f')
               strcpy(attachment[n_att++], argv[++i]);
            else if (argv[i][1] == 'r')
               reply = atoi(argv[++i]);
            else if (argv[i][1] == 'e')
               edit = atoi(argv[++i]);
            else if (argv[i][1] == 'w') {
               if (argv[i+1][0] == 'l')
                  download = -1;
               else
                  download = atoi(argv[++i]);
            } else if (argv[i][1] == 'n')
               encoding = atoi(argv[++i]);
            else if (argv[i][1] == 'm') {
               strcpy(textfile, argv[++i]);
               text_flag = 1;
            } else {
             usage:
               printf("%s ", ELOGID);
               strcpy(str, svn_revision + 13);
               if (strchr(str, ' '))
                  *strchr(str, ' ') = 0;
               printf("revision %s\n", str);
               printf("\nusage: elog\n");
               printf("elog -h <hostname> [-p port] [-d subdir]\n");
               printf("                              Location where elogd is running\n");
               printf("     -l logbook/experiment    Name of logbook or experiment\n");
               printf("     -s                       Use SSL for communication\n");
               printf("     [-v]                     For verbose output\n");
               printf("     [-u username password]   Wser name and password\n");
               printf("     [-f <attachment>]        (up to %d attachments)\n", MAX_ATTACHMENTS);
               printf("     -a <attribute>=<value>   (up to %d attributes)\n", MAX_N_ATTR);
               printf("     [-r <id>]                Reply to existing message\n");
               printf("     [-q]                     Quote original text on reply\n");
               printf("     [-e <id>]                Edit existing message\n");
               printf("     [-w <id>|last]           Download existing message (last message)\n");
               printf("     [-x]                     Suppress email notification\n");
               printf("     [-n 0|1|2]               Encoding: 0:ELcode,1:plain,2:HTML\n");
               printf("     -m <textfile>] | <text>\n");
               printf("\nArguments with blanks must be enclosed in quotes\n");
               printf("The elog message can either be submitted on the command line, piped in like\n");
               printf("\"cat text | elog -h ... -l ... -a ...\" or in a file with the -m flag.\n");
               printf("Multiple attributes and attachments can be supplied\n");
               return 1;
            }
         } else {
            strcpy(text, argv[i]);
            convert_crlf(text, sizeof(text));
            text_flag = 1;
         }
      }
   }

#ifndef HAVE_SSL
   if (ssl) {
      printf("SLL support not compiled into this program\n");
      return 1;
   }
#endif

#if defined( _MSC_VER )
   {
      WSADATA WSAData;

      /* Start windows sockets */
      if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
         return -1;
   }
#endif

   if (host_name[0] == 0) {
      printf("Please specify hostname.\n");
      return 1;
   }

   if (logbook[0] == 0) {
      printf("Please specify logbook with the \"-l\" flag.\n");
      return 1;
   }

   if (n_attr == 0 && !edit && !reply && !download) {
      printf("Please specify attribute(s) with the \"-a\" flag.\n");
      return 1;
   }

   fh = -1;

   if (textfile[0]) {
      fh = open(textfile, O_RDONLY | O_BINARY);
      if (fh < 0) {
         printf("Message file \"%s\" does not exist.\n", textfile);
         return 1;
      }

      size = (INT) lseek(fh, 0, SEEK_END);
      lseek(fh, 0, SEEK_SET);

      if (size > (INT) (sizeof(text) - 1)) {
         printf("Message file \"%s\" is too long (%zd bytes max).\n", textfile, sizeof(text));
         return 1;
      }

      i = read(fh, text, size);

      if (i < size) {
         printf("Cannot fully read message from file %s.\n", textfile);
         return 1;
      }

      close(fh);
   }

   if (text_flag == 0 && !edit && !download) {
      /* read from stdin */

      n = 0;

      do {
         i = getchar();

         text[n++] = i;

      } while (i != EOF);

      if (n > 0)
         text[n - 1] = 0;
   }

   /* change CR -> CRLF for unix text files */
   add_crlf(text, sizeof(text));

   /*---- open attachment file ----*/

   for (i = 0; i < MAX_ATTACHMENTS; i++) {
      if (!attachment[i][0])
         break;

      fh = open(attachment[i], O_RDONLY | O_BINARY);
      if (fh < 0) {
         printf("Attachment file \"%s\" does not exist.\n", attachment[i]);
         return 1;
      }

      att_size[i] = lseek(fh, 0, SEEK_END);
      lseek(fh, 0, SEEK_SET);

      buffer[i] = (char *)malloc(att_size[i] + 1);

      n = read(fh, buffer[i], att_size[i]);
      if (n < att_size[i]) {
         printf("Cannot fully read attachment file \"%s\".\n", attachment[i]);
         return 1;
      }
      buffer[i][n] = 0;

      close(fh);
   }

   /* now submit message */
   submit_elog(host_name, port, ssl, subdir, logbook,
               uname, upwd, reply, quote_on_reply, edit, download, suppress, encoding, attr_name, attrib, n_attr, text,
               attachment, buffer, att_size);

   for (i = 0; i < MAX_ATTACHMENTS; i++)
      if (buffer[i])
         free(buffer[i]);

   return 0;
}
Beispiel #3
0
inline void
end_header(http_connection *con)
{
    add_crlf(con);
}
/* [timestamp]  */
static void *store_to_log_thread_func(void * arg)
{	

	int stat = 0;
      
	api_pos_data_t g_origin_pos;
	//原点在羽毛球场起飞点
	g_origin_pos.longti = ORIGIN_IN_HENGSHENG_LONGTI;
	g_origin_pos.lati = ORIGIN_IN_HENGSHENG_LATI;
	g_origin_pos.alti = ORIGIN_IN_HENGSHENG_ALTI;
	XYZ g_origin_XYZ, cur_XYZ;  
	api_quaternion_data_t cur_quaternion;
	struct timeval    tv;  
	struct tm         *tmlocal; 
	double dji_time=0;
	char _wbuf[500] = {0};
    Queue* pq=create(4);
       
	if(log_fd == -1)
	{
		printf("Bad log fd.\n");
		pthread_exit(NULL);
	}

	char header[300];
	sprintf(header,
			"linux time;dji time;"
			"body_roll;body_pitch;body_yaw;"
			"agx;agy;agz;"
			"vgx;vgy;vgz;"
			"wx;wy;wz;"
			"mx;my;mz;"
			"longti;lati;alti;height;health;"
			"cur_xyz;"
			"no_gps_z;"
			"pitch,roll,yaw,thr;"
			"ultra,ultra_calc;"
			"of_x;of_y;of_z;"
			"of_ad_x;of_ad_y;of_ad_z;\n");
	
	//printf("%s\n", header);
	
	int ret = write(log_fd, header, strlen((const char *) header));
	if(ret == -1)
	{
		printf("Header bad write.\n");      
	}
	
	while(1)
	{	
		if(if_log_on() )
		{		
			DJI_Pro_Get_Quaternion(&cur_quaternion);
			QUA2ANGLE(cur_quaternion,&body_angle) ;                                                        
			DJI_Pro_Get_GroundAcc(&cur_acc);  
			DJI_Pro_Get_GroundVo(&cur_vo);
			DJI_Pro_Get_Broadcast_Data(&cur_broadcast_data);
			stat |= 0x01;
                              
			DJI_Pro_Get_Pos(&_log_pos);
			geo2XYZ(_log_pos, &cur_XYZ);
			XYZ2xyz(g_origin_pos, cur_XYZ, &cur_xyz);
			stat |= (0x02 | 0x04);

			_log_no_gps_z = get_no_gps_z_data();
			stat |= 0x08;
			
			if( XY_Get_Ctrl_Data(&_log_user_ctrl_data) == 0 )
			{
				stat |= 0x10;
			}
			
			if(XY_Get_Ultra_Data(&_log_ultra_data, ULTRA_GET_ID_A) == 0)
		   	{
                           if(!ultra_queue_full(pq))
                           {
                                push_queue(pq,_log_ultra_data);
                                //printf("_log_ultra_data is %.4f\n",_log_ultra_data);
                           }
                           if(ultra_queue_full(pq))
                           {
                                ultra_calc(pq);
								Get_calced_Ultra(pq,&_calc_ultra_data);
                                queue_pop(pq);                            
                                //printf("_calc_ultra_data is %.4f\n",_calc_ultra_data);
                           }
			   	stat |= 0x20;
		   	}

			/* sd code should use OFFSET_GET_ID_B */
			if( XY_Get_Offset_Data(&_log_offset, OFFSET_GET_ID_B) == 0)
			{
				stat |= 0x40;

				get_log_offset_adjust(&_log_offset_adjust);
				stat |= 0x80;
			}

			
                              
			if( gettimeofday(&tv, NULL) != 0)
			{
				printf("ERROR get timestamp for log.\n");
				
			}
			tmlocal = localtime(&tv.tv_sec); 
        	dji_time=((float)cur_broadcast_data.time_stamp/600);
			
			sprintf(_wbuf, "%d-%d %d:%d:%d:%6ld;%6lf;",	1 + tmlocal->tm_mon,
														tmlocal->tm_mday,
														tmlocal->tm_hour,
														tmlocal->tm_min,
														tmlocal->tm_sec,
														tv.tv_usec,
														dji_time); 
			
			int ret = write(log_fd, _wbuf, strlen((const char *)_wbuf));
			memset(_wbuf, 0, strlen((const char *)_wbuf));
			if(ret == -1)
			{
				perror("log write");
			}
			check_stat_store(stat, 0x01, _wbuf);
			check_stat_store(stat, 0x02, _wbuf);
			check_stat_store(stat, 0x04, _wbuf);
			check_stat_store(stat, 0x08, _wbuf);
			check_stat_store(stat, 0x10, _wbuf);
			check_stat_store(stat, 0x20, _wbuf);
			check_stat_store(stat, 0x40, _wbuf);
			check_stat_store(stat, 0x80, _wbuf);
		  
			add_crlf();
			
			stat = 0;
			
			usleep(100000);	//100ms
		}
		else
		{
			printf("log fd will be closed.\n");
			close(log_fd);
			break;
			//wait_log_on();
		}
	}
	pthread_exit(NULL);
}