Ejemplo n.º 1
0
Archivo: vga.c Proyecto: LFUnion/LFOS
void vga_send() {
    print_raw("Number of functions: ");
    printf(itoa(vga_api.datai.number_of_functions));
    print_raw("Priority: ");
    printf(itoa(vga_api.datai.driver_priority));
    printf(vga_api.datai.driver_description);
}
Ejemplo n.º 2
0
void			print_memory(const void *addr, size_t size)
{
	size_t i;

	i = 0;
	while (size > 16)
	{
		print_hexa((unsigned char*)addr + i, 16);
		print_raw((unsigned char*)addr + i, 16);
		size -= 16;
		i += 16;
	}
	print_hexa((unsigned char*)addr + i, size);
	print_raw((unsigned char*)addr + i, size);
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
	struct bpf_program prog;
	parse_args(argc, argv);

	if (pcap_compile_nopcap(snaplen, dlt, &prog, expr, 1, 0))
	{
		fprintf(stderr, "Syntax error in expression\n");
		exit(EX_USAGE);
	}

	switch(format)
	{
	case RAW:
		print_raw(&prog);
		break;
	case HEXSTRING:
		print_hexstring(&prog);
		break;
	case NG_BPF:
		print_ng_bpf(&prog);
		break;
	}

	return EX_OK;
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------
 * print_pos - Print CSCN and SCN for this LCR
 *---------------------------------------------------------------------*/
static void print_pos(oci_t *ocip, ub1 *pos, ub2 poslen, char *comm)
{
  sword        ret;
  OCINumber    scn;
  OCINumber    cscn;
  ub4          numval;

  printf("%s=", comm);
  print_raw(pos, poslen);
  printf("\n");
  ret = OCILCRSCNsFromPosition(ocip->svcp, ocip->errp,
                               pos, poslen, &scn, &cscn, OCI_DEFAULT);
  if (ret != OCI_SUCCESS)
    printf ("OCILCRNumberFromPosition ERROR %d\n", ret);

  ret = OCINumberToInt(ocip->errp, (const OCINumber *)&cscn,
                       sizeof(numval), OCI_NUMBER_UNSIGNED, &numval);

  printf("  Position CSCN=%d ", numval);

  ret = OCINumberToInt(ocip->errp, (const OCINumber *)&scn,
                       sizeof(numval), OCI_NUMBER_UNSIGNED, &numval);

  printf("  SCN=%d\n", numval);
}
Ejemplo n.º 5
0
static void print_parameter(int mode, char *ptr)
{

#define INSIDE(p,t) (ptr >= (char *) t && ptr < ((char *) t) + sizeof(t))

    /*
     * This is gross, but the best we can do on short notice.
     */
    if (INSIDE(ptr, time_table))
	print_time(mode, (CONFIG_TIME_TABLE *) ptr);
    if (INSIDE(ptr, bool_table))
	print_bool(mode, (CONFIG_BOOL_TABLE *) ptr);
    if (INSIDE(ptr, int_table))
	print_int(mode, (CONFIG_INT_TABLE *) ptr);
    if (INSIDE(ptr, str_table))
	print_str(mode, (CONFIG_STR_TABLE *) ptr);
    if (INSIDE(ptr, str_fn_table))
	print_str_fn(mode, (CONFIG_STR_FN_TABLE *) ptr);
    if (INSIDE(ptr, str_fn_table_2))
	print_str_fn_2(mode, (CONFIG_STR_FN_TABLE *) ptr);
    if (INSIDE(ptr, raw_table))
	print_raw(mode, (CONFIG_RAW_TABLE *) ptr);
    if (INSIDE(ptr, nint_table))
	print_nint(mode, (CONFIG_NINT_TABLE *) ptr);
    if (msg_verbose)
	vstream_fflush(VSTREAM_OUT);
}
Ejemplo n.º 6
0
void Stream::vprint(const char *format, va_list argptr) {
  DECLARE_STATIC_BUFFER(char, buffer, BUFLEN);
  if (jvm_vsnprintf(buffer, BUFLEN, format, argptr) < 0) {
    NOT_PRODUCT(warning("increase BUFLEN in Stream.cpp -- output truncated"));
    buffer[BUFLEN - 1] = 0;
  }
  print_raw(buffer);
}
Ejemplo n.º 7
0
int main(int argc, char** argv)
{
	Request* r = request_new();
	request_set_method(r, "GET");
	request_set_uri(r, "http://web.qq.com/hello.html?key=234");
	request_set_version(r, "HTTP/1.1");
	
	request_add_header(r, "Content-Lenght", "12345");
	request_add_header(r, "Host", "web.qq.com");
	
	gchar* s = "asdjfaslkdjfoqwiuertjakfdja;sldf";
	request_append_msg(r, s, strlen(s));
	request_append_msg(r, s, strlen(s));
	request_append_msg(r, s, strlen(s));
	request_append_msg(r, s, strlen(s));
	request_append_msg(r, s, strlen(s));
	request_append_msg(r, s, strlen(s));
	
	print_raw(request_tostring(r));
	g_printf("\n\n");
	
	s = "HTTP/1.1 200 OK\r\n"
"Date: Sun, 02 Jan 2011 19 19:09:55 GMT\r\n"
"Server: Tencent Login Server/2.0.0\r\n"
"Set-Cookie: pt2gguin=o0494498045; EXPIRES=Fri, 02-Jan-2020 00:00:00 GMT; PATH=/;DOMAIN=qq.com;\r\n"
"Set-Cookie: uin=o0494498045; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: skey=@EK66ZxUe8; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: clientuin=; EXPIRES=Fri, 02-Jan-1970 00:00:00 GMT; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: clientkey=; EXPIRES=Fri, 02-Jan-1970 00:00:00 GMT; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: zzpaneluin=; EXPIRES=Fri, 02-Jan-1970 00:00:00 GMT; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: zzpanelkey=; EXPIRES=Fri, 02-Jan-1970 00:00:00 GMT; PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie: ptisp=edu;PATH=/; DOMAIN=qq.com;\r\n"
"Set-Cookie:ptuserinfo=4b65726e656c;PATH=/;DOMAIN=ptlogin2.qq.com;\r\n"
"Set-Cookie: ptwebqq=b16f2ca37c56d8a2ce064a9494cc85044e78ac6c480041c3f5be450206ab6728;" "PATH=/; DOMAIN=qq.com;\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache; must-revalidate\r\n"
"Connection: Close\r\n"
"Content-Type: application/x-javascript; charset=utf-8\r\n";
	Response* rps = response_new_parse(g_string_new(s));
	g_printf("%s\n",response_tostring(rps) -> str);
	g_printf("\n\n");
	print_raw(rps -> reason);
	print_raw(rps -> msg);
	return 0;
}
// ------------------------------------------------------------------
void xmlStream::va_tag(bool push, const char* format, va_list ap) {
  assert_if_no_error(!inside_attrs(), "cannot print tag inside attrs");
  char buffer[BUFLEN];
  size_t len;
  const char* kind = do_vsnprintf(buffer, BUFLEN, format, ap, false, len);
  see_tag(kind, push);
  print_raw("<");
  write(kind, len);
  _markup_state = (push ? HEAD : ELEM);
}
Ejemplo n.º 9
0
Archivo: kio.c Proyecto: LFUnion/LFOS
// bug
char * scanf() {
    char* tmp = (char*)malloc(150 * sizeof(char));
    char inp = ' ';
    int i = 0;
    vga_enable_cursor();

    do {
        vga_update_cursor();
        kbd_flush_buffer();
        inp = kbd_pull_char();

        if (inp != 0) {
            if (i > 149)
                break;
            else if (inp != '\b') {
                char* str = (char*)malloc(2*sizeof(char));
                str[0] = inp;
                str[1] = '\0';
                kprint_raw(str);
                free(str);

                if (inp != '\n')
                    tmp[i] = inp;

                i++;
            } else {
                if (i > 0) {
                    // Clear character in array
                    i--;
                    tmp[i] = 0;
                    // Remove character from screen
                    int new_pos = (vga_get_row() * 80 + vga_get_column()) - 1;
                    vga_set_position(new_pos / 80, new_pos % 80);
                    print_raw(" ");
                    vga_set_position(new_pos / 80, new_pos % 80);
                }
            }
        }
    } while (inp != '\n');

    tmp[i-1] = '\0';
    vga_disable_cursor();
    char* ret = (char*)malloc(strlen(tmp)+1 * sizeof(char));

    for (int ii = 0; ii < strlen(tmp); ii++)
        ret[ii] = tmp[ii];

    ret[strlen(tmp)] = '\0';
    free(tmp);
    return ret;
}
void xmlBuffer::print_raw(const char *str) {
size_t len=strlen(str);
print_raw(str,len);
}
Ejemplo n.º 11
0
void Stream::print_cr(const char* format, ...) {
  JVM_VSNPRINTF_TO_BUFFER(format, buffer, BUFLEN);
  print_raw(buffer);
  cr();
}
void generate_summary( char text[], int text_size, char **output_title, char **output_body, char **output_metakeywords, char **output_metadescription )
{
    // Variables for lexical analyzer:
    struct _sp_yy_extra	*se = (struct _sp_yy_extra*)malloc(sizeof(struct _sp_yy_extra));

    se->top = -1;
    se->stringtop = -1;

    // Set variables for lalr(1)-parser:

    // Fields 'title', 'meta keywords' and 'meta description', will only keep first 10240 bytes,
    // field body will only keep up to double original textsize (should be enough for all ordinary documents).

    struct parseExtra pE;

    pE.section = INIT;

    pE.newspan = 1;
    pE.newdiv = 1;
    pE.newhead = 0;
    pE.endhead = 0;
    pE.inspan = 0;
    pE.indiv = 0;
    pE.inhead = 0;

    pE.title = buffer_init( 10240 );
    pE.body = buffer_init( text_size*2 );
    pE.metakeyw = buffer_init( 10240 );
    pE.metadesc = buffer_init( 10240 );

    void	*pParser = summaryParseAlloc(malloc);
    int		yv;

    // Run parser:
    yyscan_t	scanner;

    summarylex_init( &scanner );
    summaryset_extra( se, scanner );

    YY_BUFFER_STATE	bs = summary_scan_bytes( text, text_size, scanner );

    se->token.space = 0;
    while ((yv = summarylex(scanner)) != 0)
	{
	    summaryParse(pParser, yv, se->token, &pE);
	    if (yv==WORD || yv==ESC)
		se->token.space = 0;
	}

    summaryParse(pParser, 0, se->token, &pE);
    summaryParseFree(pParser, free);

    summary_delete_buffer( bs, scanner );
    summarylex_destroy( scanner );

    if (pE.inspan)
        print_raw( "</span>", &pE.body );
    if (pE.inhead)
        print_raw( "\n</h2>", &pE.body );
    if (pE.indiv)
        print_raw( "\n</div>", &pE.body );

//    pE.rawbody.data[pE.rawbody.pos] = '\0';

//    print_with_escapes( pE.rawbody.data, &(pE.body) );		// pr_w_esc kjører free automagisk!!

    (*output_title) = buffer_exit( pE.title );
    (*output_body) = buffer_exit( pE.body );
    (*output_metakeywords) = buffer_exit( pE.metakeyw );
    (*output_metadescription) = buffer_exit( pE.metadesc );

    free( se );
}
Ejemplo n.º 13
0
vector<sinsp_sample_row>* sinsp_table::get_sample(uint64_t time_delta)
{
	//
	// No sample generation happens when the table is paused
	//
	if(!m_paused)
	{
		//
		// If we have a freetext filter, we start by filtering the sample
		//
		if(m_freetext_filter != "")
		{
			filter_sample();
			m_sample_data = &m_filtered_sample_data;
		}
		else
		{
			m_sample_data = &m_full_sample_data;
		}

		//
		// Sort the sample
		//
		sort_sample();
	}

	//
	// If required, emit the sample to stdout
	//
#ifndef _WIN32
	if(m_output_type != sinsp_table::OT_CURSES)
	{
#endif
		if(m_output_type == sinsp_table::OT_RAW)
		{
			print_raw(m_sample_data, time_delta);
		}
		else if(m_output_type == sinsp_table::OT_JSON)
		{
			print_json(m_sample_data, time_delta);
		}
		else
		{
			ASSERT(false);
		}
#ifndef _WIN32
	}
#endif

	//
	// Restore the lists used for event processing
	//
	m_types = &m_premerge_types;
	m_table = &m_premerge_table;
	m_n_fields = m_n_premerge_fields;
	m_vals_array_sz = m_premerge_vals_array_sz;
	m_fld_pointers = m_premerge_fld_pointers;
	m_extractors = &m_premerge_extractors;

	return m_sample_data;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
    /*! default at failure */
    int main_ret = 1;

    /*! input XML file, if specified */
    FILE *inp_xml_file = 0;

    /*! output XML file, if specified */
    FILE *out_xml_file = 0;

	/*! serial device path */
	const char *serial_device_path = SERIAL_DEVICE_PATH;

    /*! CPI instance */
    cpi_t *p_cpi = 0;

    /*! options for stdout */
    int print_putative_id = 0;
    int print_all = 0;
    int print_usage = 0;

    /*! options for power down and alarm */
    int do_shutdown = 0;
    int do_alarm = 0;
    uint32_t alarm_time = 0;

    /*! key id */
    uint16_t key_id = 0;

    /*! raw buffer, used to parse results */
    uint8_t *tmp_buffer1 = 0, *tmp_buffer2 = 0, *tmp_buffer3 = 0;

    /*! @hack @todo thread for monitoring timeout */
    pthread_t timeout_thread;

    /*! initialize timeout thread */
    pthread_create(&timeout_thread, 0, timeout_hack, 0);

    /*! print usage if there are no arguments */
    if(argc <= 1) { print_usage = 1; }

    /*! initialize temporary buffers */
    {
        tmp_buffer1 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer1 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer1\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }

        tmp_buffer2 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer2 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer2\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }

        tmp_buffer3 = (uint8_t*)malloc(CPI_MAX_RESULT_SIZE);

        if(tmp_buffer3 == 0)
        {
            fprintf(stderr, "Error: could not allocate %d bytes for tmp_buffer3\n", CPI_MAX_RESULT_SIZE);
            return 1;
        }
    }

    /*! parse command line */
    {
        int cur_arg = 0;

        for(cur_arg = 1; cur_arg < argc; cur_arg++)
        {
            /*! expect all options to begin with '-' character */
            if(argv[cur_arg][0] != '-')
            {
                fprintf(stderr, "Warning: Unrecognized option \"%s\"\n", argv[cur_arg]);
                continue;
            }

            /*! process command options */
            switch(argv[cur_arg][1])
            {
                case 'k':
                {
                    /*! skip over to key ID */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to parse key ID */
                    sscanf(argv[cur_arg], "%hu", &key_id);
                }
                break;

				case 't':
				{
					/*! Skip to port path */
					if (++cur_arg >= argc) { break; }

					serial_device_path = argv[cur_arg];
					fprintf( stderr, "Using non-default serial port %s\n", serial_device_path );
				}
				break;

                case 'r':
                {
                    /*! skip over to filename */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to open inpt file */
                    inp_xml_file = fopen(argv[cur_arg], "rt");

                    /*! report file open error to user */
                    if(inp_xml_file == 0)
                    {
                        fprintf(stderr, "Error: Could not open \"%s\" for reading.\n", argv[cur_arg]);
                    }
                }
                break;

                case 'w':
                {
                    /*! skip over to filename */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to open output file */
                    out_xml_file = fopen(argv[cur_arg], "wt");

                    /*! report file open error to user */
                    if(out_xml_file == 0)
                    {
                        fprintf(stderr, "Error: Could not open \"%s\" for writing\n", argv[cur_arg]);
                    }
                }
                break;

                case 'i':
                {
                    if(inp_xml_file == 0) { inp_xml_file = stdin; }
                }
                break;

                case 'o':
                {
                    if(out_xml_file == 0) { out_xml_file = stdout; }
                }
                break;

                case 'p':
                    print_putative_id = 1;
                    break;

                case 'a':
                {
                    do_alarm = 1;

                    /*! skip over to alarm time */
                    if(++cur_arg >= argc) { break; }

                    /*! attempt to parse key ID */
                    sscanf(argv[cur_arg], "%u", &alarm_time);
                }
                break;

                case 's':
                    do_shutdown = 1;
                    break;

                case 'd':
                    print_all = 1;
                    break;

                case '-':
                    print_usage = 1;
                    break;

                default:
                    fprintf(stderr, "Warning: Unrecognized option \"%s\"\n", argv[cur_arg]);
                    break;
            }
        }
    }

    /*! optionally, print usage */
    if(print_usage)
    {
        show_usage();
        goto cleanup;
    }

    /*! create CPI instance */
    {
        cpi_info_t cpi_info = { 0 };

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_create(&cpi_info, &p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_create failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    /*! initialize CPI instance */
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_init(p_cpi, serial_device_path);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_init failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    /*! optionally read input XML data */
    if(inp_xml_file != 0)
    {
        int size = 0;

        /*! read up to max buffer size minus null terminator */
        {
            size_t ret = fread(tmp_buffer1, 1, CPI_MAX_RESULT_SIZE-1, inp_xml_file);

            /*! update size */
            if(ret > 0) { size = ret; }

            /*! append null terminator */
            tmp_buffer1[size] = '\0';
        }

        /*! process XML data */
        {
            /*!< @hack @todo enable hung CPI timeout */
            enable_timeout(10);

            int ret = cpi_process_xml(p_cpi, (char*)tmp_buffer1, (char*)tmp_buffer2);

            if(CPI_FAILED(ret))
            {
                fprintf(stderr, "Error: cpi_process_xml failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
                goto cleanup;
            }
        }

        /*! optionally write XML output */
        if(out_xml_file != 0)
        {
            int size = strlen((char*)tmp_buffer2);

            /*! write output data to out_xml_file */
            if(size > 0)
            {
                size_t ret = fwrite(tmp_buffer2, 1, size, out_xml_file);

                if(ret != size)
                {
                    fprintf(stderr, "Error: fwrite returned %d, expected %d\n", ret, size);
                    goto cleanup;
                }
            }
        }

    }

    /*! get putative ID */
    if(print_all || print_putative_id)
    {
        char str[CPI_PUTATIVE_ID_SIZE];

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(4);

        int ret = cpi_get_putative_id(p_cpi, key_id, str);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_putative_id failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        /*! print to stdout in all format */
        if(print_all)
        {
            printf("Putative ID : %s\n", str);
        }
        /*! print only putative ID */
        else if(print_putative_id)
        {
            printf("%s\n", str);
        }
    }

    /*! get public key */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_public_key(p_cpi, key_id, (char*)tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_public_key failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        /*! public key contains an endline already */
        printf("Public Key : \n%s", tmp_buffer1);
    }

    /*! get version data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_version_data(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_version_data failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Version Data :\n");

        print_raw(tmp_buffer1, CPI_VERSION_SIZE);
    }

    /*! get current time */
    if(print_all)
    {
        uint32_t cur_time = 0;

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_current_time(p_cpi, &cur_time);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_current_time failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Current Time : %d seconds since last reboot\n", cur_time);
    }

    /*! get current owner key index */
    if(print_all)
    {
        uint32_t cur_oki = 0;

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_owner_key_index(p_cpi, &cur_oki);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_owner_key_index failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Current Owner Key Index : %d\n", cur_oki);
    }

    /*! get serial number data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_serial_number(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_serial_number failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Serial Number :\n");

        print_raw(tmp_buffer1, CPI_SERIAL_NUMBER_SIZE);
    }

    /*! get hardware version data */
    if(print_all)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_get_hardware_version_data(p_cpi, tmp_buffer1);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_get_hardware_version_data failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Hardware Version Data :\n");

        print_raw(tmp_buffer1, CPI_HARDWARE_VERSION_SIZE);
    }

    /*! issue challenge */
    if(print_all)
    {
        uint8_t rand_data[0x10] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

        memset(tmp_buffer1, 0, CPI_MAX_RESULT_SIZE);
        memset(tmp_buffer2, 0, CPI_MAX_RESULT_SIZE);
        memset(tmp_buffer3, 0, CPI_MAX_RESULT_SIZE);

        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_issue_challenge(p_cpi, key_id, rand_data, tmp_buffer1, tmp_buffer2, tmp_buffer3);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_issue_challenge failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("result1 : \n");

        /*! print result1 */
        print_raw(tmp_buffer1, CPI_RESULT1_SIZE);

        printf("result2 : \n");

        /*! print result1 */
        print_raw(tmp_buffer2, CPI_RESULT2_SIZE);

#if defined(CNPLATFORM_falconwing)        
	printf("result3 : \n");

        /*! print result1 */
        print_raw(tmp_buffer3, CPI_RESULT3_SIZE);
#endif
    }

    /*! set alarm */
    if(do_alarm)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_set_alarm_time(p_cpi, alarm_time);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_set_alarm_time failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }

        printf("Alarm was set for %d seconds from now\n", alarm_time);
    }

    /*! optionally, power down */
    if(do_shutdown)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_trigger_power_down(p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Error: cpi_trigger_power_down failed (%s)\n", CPI_RETURN_CODE_LOOKUP[ret]);
            goto cleanup;
        }
    }

    main_ret = 0;

cleanup:

    /*! cleanup input file handle(s) */
    if( (inp_xml_file != 0) && (inp_xml_file != stdin) )
    {
        fclose(inp_xml_file);
        inp_xml_file = 0;
    }

    /*! cleanup file handle(s) */
    if( (out_xml_file != 0) && (out_xml_file != stdout) )
    {
        fclose(out_xml_file);
        out_xml_file = 0;
    }

    if(tmp_buffer2 != 0)
    {
        free(tmp_buffer2);
        tmp_buffer2 = 0;
    }

    if(tmp_buffer1 != 0)
    {
        free(tmp_buffer1);
        tmp_buffer1 = 0;
    }

    /*! cleanup CPI instance */
    if(p_cpi != 0)
    {
        /*!< @hack @todo enable hung CPI timeout */
        enable_timeout(10);

        int ret = cpi_close(p_cpi);

        if(CPI_FAILED(ret))
        {
            fprintf(stderr, "Warning: cpi_close failed (0x%.08X)\n", ret);
            return 1;
        }
    }

    /*! cleanup timeout thread */
    {
        timeout_hack_stop = 1;
        pthread_join(timeout_thread, 0);
    }

    return main_ret;
}
Ejemplo n.º 15
0
Archivo: vga.c Proyecto: LFUnion/LFOS
void vga_use(const int func) {
    if (func == 1) {
        print_raw("Character: ");
        char * character = scanf();
        uint8_t character_i = atoui(character);
        print_raw("Color: ");
        char * color = scanf();
        uint8_t color_i = atoui(color);
        print_raw("Position: ");
        char * position = scanf();
        uint8_t position_i = atoui(position);
        print_raw("Line: ");
        char * line = scanf();
        uint8_t line_i = atoui(line);
        vga_api.pfunc[0].func_v_8_8_8_8 (character_i, color_i, line_i, position_i);
        free(character);
        free(color);
        free(position);
        free(line);
    } else if (func == 2) {
        print_raw("Character: ");
        char * character = scanf();
        uint8_t character_i = atoui(character);
        print_raw("Color: ");
        char * color = scanf();
        uint8_t color_i = atoui(color);
        print_raw("Position: ");
        char * position = scanf();
        uint8_t position_i = atoui(position);
        print_raw("Line: ");
        char * line = scanf();
        uint8_t line_i = atoui(line);
        vga_api.pfunc[1].func_v_8_8_8_8 (character_i, color_i, line_i, position_i);
        free(character);
        free(color);
        free(position);
        free(line);
    } else if (func == 3) {
        print_raw("Input output: ");
        char * text = scanf();
        vga_api.pfunc[2].func_v_cp (text);
        free(text);
    } else if (func == 4) {
        print_raw("Input normal output: ");
        char * text = scanf();
        vga_api.pfunc[3].func_v_cp (text);
        free(text);
    } else if (func == 5) {
        print_raw("Input highlighted output: ");
        char * text = scanf();
        vga_api.pfunc[4].func_v_cp (text);
        free(text);
    } else if (func == 6) {
        printf("Clear screen");
        vga_api.pfunc[5].func_v ();
    } else if (func == 7) {
        printf("Scroll lines");
        vga_api.pfunc[6].func_v ();
    } else if (func == 8) {
        print_raw("Row number: ");
        int i = vga_api.pfunc[7].func_i ();
        printf(itoa(i));
    } else if (func == 9) {
        print_raw("Print line position: ");
        int i = vga_api.pfunc[8].func_i ();
        printf(itoa(i));
    } else if (func == 10) {
        print_raw("Position: ");
        char * position = scanf();
        uint8_t position_i = atoui(position);
        print_raw("Line: ");
        char * line = scanf();
        uint8_t line_i = atoui(line);
        vga_api.pfunc[9].func_v_i_i (line_i, position_i);
        free(position);
        free(line);
    } else if (func == 11) {
        printf("Set cursor");
        vga_api.pfunc[10].func_v ();
    } else if (func == 12) {
        print_raw("Position of cursor: ");
        char * position = scanf();
        uint8_t position_i = atoui(position);
        print_raw("Line of cursor: ");
        char * line = scanf();
        uint8_t line_i = atoui(line);
        vga_api.pfunc[11].func_v_i_i (line_i, position_i);
        free(position);
    } else if (func == 13) {
        printf("Enable cursor");
        vga_api.pfunc[12].func_v ();
    } else if (func == 14) {
        printf("Disable cursor");
        vga_api.pfunc[13].func_v ();
    }
}
Ejemplo n.º 16
0
void Stream::put(char ch) {
  GUARANTEE(ch != 0, "please fix call site");
  char buf[] = { ch, '\0' };
  print_raw(buf);
}
Ejemplo n.º 17
0
static void print_pkcs7_info(gnutls_pkcs7_signature_info_st * info,
			     gnutls_buffer_st * str,
			     gnutls_certificate_print_formats_t format)
{
	unsigned i;
	char *oid;
	gnutls_datum_t data;
	char prefix[128];
	char s[42];
	size_t max;
	int ret;

	if (info->issuer_dn.size > 0)
		print_dn(str, "\tSigner's issuer DN", &info->issuer_dn);
	print_raw(str, "\tSigner's serial", &info->signer_serial);
	print_raw(str, "\tSigner's issuer key ID", &info->issuer_keyid);
	if (info->signing_time != -1) {
		struct tm t;
		if (gmtime_r(&info->signing_time, &t) == NULL) {
			addf(str, "error: gmtime_r (%ld)\n",
			     (unsigned long)info->signing_time);
		} else {
			max = sizeof(s);
			if (strftime(s, max, "%a %b %d %H:%M:%S UTC %Y", &t) ==
			    0) {
				addf(str, "error: strftime (%ld)\n",
				     (unsigned long)info->signing_time);
			} else {
				addf(str, "\tSigning time: %s\n", s);
			}
		}
	}

	addf(str, "\tSignature Algorithm: %s\n",
	     gnutls_sign_get_name(info->algo));

	if (format == GNUTLS_CRT_PRINT_FULL) {
		if (info->signed_attrs) {
			for (i = 0;; i++) {
				ret =
				    gnutls_pkcs7_get_attr(info->signed_attrs, i,
							  &oid, &data, 0);
				if (ret < 0)
					break;
				if (i == 0)
					addf(str, "\tSigned Attributes:\n");

				snprintf(prefix, sizeof(prefix), "\t\t%s", oid);
				print_raw(str, prefix, &data);
				gnutls_free(data.data);
			}
		}
		if (info->unsigned_attrs) {
			for (i = 0;; i++) {
				ret =
				    gnutls_pkcs7_get_attr(info->unsigned_attrs,
							  i, &oid, &data, 0);
				if (ret < 0)
					break;
				if (i == 0)
					addf(str, "\tUnsigned Attributes:\n");

				snprintf(prefix, sizeof(prefix), "\t\t%s", oid);
				print_raw(str, prefix, &data);
				gnutls_free(data.data);
			}
		}
	}
	adds(str, "\n");
}
Ejemplo n.º 18
0
int akmos_cli_digest(int argc, char **argv)
{
    struct opt_digest_s opt;
    struct opt_thread_s thr_opt[MAX_THREADS];
    const akmos_digest_xdesc_t *desc;
    pthread_t *thread;
    uint8_t *md;
    size_t i, j, thr_cnt;
    int err;

    err = EXIT_SUCCESS;

    memset(&opt, 0, sizeof(opt));
    err = parse_arg(&opt, argc, argv);
    if(err)
        return err;

    if(!opt.thr_num)
        opt.thr_num = DEFAULT_THREADS;

    if(opt.num < opt.thr_num)
        opt.thr_num = opt.num;

    thread = malloc(sizeof(pthread_t) * opt.thr_num);
    if(thread == NULL) {
        fprintf(stderr, "%s\n", strerror(errno));
        return err;
    }

    desc = akmos_digest_desc(algo);
    if(!desc)
        return akmos_perror(AKMOS_ERR_ALGOID);

    err = amalloc(&md, desc->outlen * opt.thr_num);
    if(err)
        goto out;

    for(i = 0, j = 0; i < opt.thr_num; i++, j += desc->outlen)
        thr_opt[i].md = md + j;

    for(i = 0, thr_cnt = opt.thr_num; i < opt.num; i += opt.thr_num, opt.input += opt.thr_num) {
        if((opt.num - i) < opt.thr_num)
            thr_cnt = opt.num - i;

        for(j = 0; j < thr_cnt; j++) {
            thr_opt[j].input = opt.input[j];

            err = pthread_create(&thread[j], NULL, &digest, &thr_opt[j]);
            if(err) {
                fprintf(stderr, "%s\n", strerror(errno));
                goto out;
            }
        }

        for(j = 0; j < thr_cnt; j++) {
            err = pthread_join(thread[j], NULL);
            if(err) {
                fprintf(stderr, "%s\n", strerror(errno));
                goto out;
            }
        }

        for(j = 0; j < thr_cnt; j++) {
            if(!opt.set.bin)
                print_hex(thr_opt[j].input, desc->name, thr_opt[j].md, desc->outlen);
            else
                print_raw(thr_opt[j].md, desc->outlen);
        }
    }

out:
    if(md)
        free(md);

    if(thread)
        free(thread);

    return err;
}