Exemple #1
0
void ProcessImage::initCamera()
{
    vd = new VideoDevice(QString("/dev/video0"));

    connect(vd, SIGNAL(display_error(QString)), this,SLOT(display_error(QString)));

    rs = vd->open_device();
    if(-1==rs)
    {
        return;
    }

    rs = vd->init_device();
    if(-1==rs)
    {
        vd->close_device();
        return;
    }

    rs = vd->start_capturing();
    if(-1==rs)
    {
        vd->close_device();
        return;
    }

}
Exemple #2
0
/* DDS3.2.6: Get Rotation */
void get_rotation(const struct electorate *elec)
{
	struct http_vars *reply;
	unsigned int i;
	char ecodestr[INT_CHARS];
	struct http_vars request[]
		= { { (char*)"ecode", ecodestr }, { NULL, NULL } };

	sprintf(ecodestr, "%u", elec->code);

	reply = http_exchange(SERVER_ADDRESS, SERVER_PORT, ROBSON_CGI,request);
	if (!reply)
		display_error(ERR_SERVER_UNREACHABLE);

	/* Some error occurred? */
	if (http_error(reply))
		display_error(http_error(reply));

	for (i = 0; i < elec->num_seats; i++) {
		char varname[strlen("rotation")
			    + sizeof(STRINGIZE(MAX_ELECTORATE_SEATS))];
		const char *val;

		sprintf(varname, "rotation%u", i);
		val = http_string(reply, varname);
		current_rotation.rotations[i] = atoi(val);
		assert(current_rotation.rotations[i] < elec->num_seats);
	}
	/* DDS3.2.6: Save Rotation */
	current_rotation.size = elec->num_seats;
	http_free(reply);
}
void MainWindow::submit()
{
    if(check_pages_input()){
        int read_pages = read_pages_text_edit->text().toInt();
        int all_pages = all_pages_text_edit->text().toInt();

        int pages_to_read = all_pages - read_pages;
        int days_to_read = get_days_difference();

        int pages_per_day;

        if(days_to_read > 0){
            pages_per_day = ceil(pages_to_read / days_to_read); //round upwards so that it is accurate

            //sometimes when there are too many days, pages_per_day becomes zero, so this if fixes that
            if(pages_per_day == 0)
                result_label->setText("You should read less than 1 page per day");
            else
                result_label->setText("You should read " + QString::number(pages_per_day) + " pages per day");
        }
        else{
            result_label->setText("Try again!");
            display_error("Please select a valid date!");
        }
    }
    else{
        display_error("The given input is invalid!");
    }
}
Exemple #4
0
ProcessImage::ProcessImage(QWidget *parent):QWidget(parent)
{
    printf("create ProcessImage\n");
    canCapture = false;
    canDisplay = false;


    pp = (unsigned char *)malloc(LCDWIDTH * LCDHEIGHT* 3 * sizeof(char));
    painter = new QPainter(this);
    frame = new QImage(pp,LCDWIDTH,LCDHEIGHT,QImage::Format_RGB888);

    label = new QLabel();
    vd = new VideoDevice(tr("/dev/video0"));

    connect(vd, SIGNAL(display_error(QString)), this,SLOT(display_error(QString)));

    connect(&client, SIGNAL(newMessage(QString,QString)),
            this, SLOT(updatePP(QString,QString)));
    connect(&client,SIGNAL(newMessage(QString,QString)),
            this,SLOT(update()));

//    timer->start(30);
    QHBoxLayout *mainLayout = new QHBoxLayout();
    mainLayout->addWidget(label);
    setLayout(mainLayout);

    counter = 0;
}
Exemple #5
0
static int cert_stuff(struct connectdata *conn,
                      int sockindex, char *cert_file, char *key_file)
{
  struct SessionHandle *data = conn->data;
  int rv = 0;

  if(cert_file) {
    rv = nss_load_cert(&conn->ssl[sockindex], cert_file, PR_FALSE);
    if(!rv) {
      if(!display_error(conn, PR_GetError(), cert_file))
        failf(data, "Unable to load client cert %d.", PR_GetError());
      return 0;
    }
  }
  if(key_file || (is_file(cert_file))) {
    if(key_file)
      rv = nss_load_key(conn, sockindex, key_file);
    else
      /* In case the cert file also has the key */
      rv = nss_load_key(conn, sockindex, cert_file);
    if(!rv) {
      if(!display_error(conn, PR_GetError(), key_file))
        failf(data, "Unable to load client key %d.", PR_GetError());

      return 0;
    }
  }
  return 1;
}
Exemple #6
0
/// Sets up STARTUPINFO structure, and launches redirected child. Start command.
///
/// \param sCommand_line    fully command line, after modify
/// \param hChildStdOut     child std out pipe
/// \param hChildStdIn      child std in pipe
/// \param hChildStdErr     child std error pipe
///
/// no return value
static void prep_and_launch_redirected_child(char *sCommand_line, HANDLE hChildStdOut, HANDLE hChildStdIn, HANDLE hChildStdErr)
{
    PROCESS_INFORMATION pi;
    STARTUPINFO si;

    // Set up the start up info struct.
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.hStdOutput = hChildStdOut;
    si.hStdInput = hChildStdIn;
    si.hStdError = hChildStdErr;
    si.wShowWindow = SW_HIDE; 

    // Launch the process that you want to redirect.
    if (!CreateProcess(
        NULL,                // command line
        sCommand_line,        // command line, with argument
        NULL,                // process security attributes
        NULL,                // primary thread security attributes
        TRUE,                // handles are inherited
        CREATE_NO_WINDOW,    // creation flags, CREATE_NO_WINDOW to prevent console window
        NULL,                // use parent's environment
        NULL,                // use parent's current direct
        &si,                // STARTUPINFO pointer
        &pi))                // receives PROCESS_INFORMATION
        display_error("prep_and_launch_redirected_child - CreateProcess", TRUE);

    // Close any unnecessary handles.
    if ( !CloseHandle(pi.hProcess) && !CloseHandle(pi.hThread)) 
        display_error("prep_and_launch_redirected_child - CloseHandle - after redirect", TRUE);
}
Exemple #7
0
int VideoDevice::start_capturing()
{
    printf("start capturing\n");
    unsigned int i;
    for(i = 0; i < n_buffers; ++i)
    {
        v4l2_buffer buf;
        CLEAR(buf);

        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        buf.memory =V4L2_MEMORY_MMAP;
        buf.index = i;
//        fprintf(stderr, "n_buffers: %d\n", i);

        if(-1 == ioctl(fd, VIDIOC_QBUF, &buf))
        {
            emit display_error(tr("VIDIOC_QBUF: %1").arg(QString(strerror(errno))));
            return -1;
        }
    }

    v4l2_buf_type type;
    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    if(-1 == ioctl(fd, VIDIOC_STREAMON, &type))
    {
        emit display_error(tr("VIDIOC_STREAMON: %1").arg(QString(strerror(errno))));
        return -1;
    }
    return 0;
}
int lowlevel_init(void)
{
	  unsigned por_cfg = READ_CBUS_REG(ASSIST_POR_CONFIG);
	if (((por_cfg & POR_ROM_BOOT_ENABLE) == 0)) {
		// take me as a spi rom boot mode
		romboot_info->por_cfg = POR_ROM_BOOT_ENABLE | POR_INTL_SPI;
		romboot_info->boot_id = 0;
	}

	WRITE_CBUS_REG(PAD_PULL_UP_REG0,-1);
	WRITE_CBUS_REG(PAD_PULL_UP_REG1,-1);
	WRITE_CBUS_REG(PAD_PULL_UP_REG2,-1);
	WRITE_CBUS_REG(PAD_PULL_UP_REG3,-1);

	//changed by Elvis, add uart rx pull up
	//pull up LINUX_RX(B15--->GPIOE_19) reg (7422y v1.pdf)
	//GPIOE_19(M1-Apps v25- 2010-07-19-BGA372_297-6.xls serach B15)
	WRITE_CBUS_REG( PAD_PULL_UP_REG3, READ_CBUS_REG(PAD_PULL_UP_REG3) & ~(1<<2) );	// Meson-pull-up-down_table.xlsx ( GPIOE_19 is PAD_PULL_UP_REG3---0x203e 2bits)
	
	//Adjust 1us timer base
	WRITE_CBUS_REG_BITS(PREG_CTLREG0_ADDR,CONFIG_CRYSTAL_MHZ,4,5);
	pll_initial(); //running under default freq now . Before we fixed the PLL stable problem

	unsigned clk;
	if ((readl(P_HHI_MPEG_CLK_CNTL) & (1 << 8)) == 0) {
		clk = CONFIG_CRYSTAL_MHZ * 1000000;
	} else {
		clk = romboot_info->clk81;
	}
	unsigned memory_size;
	
	memory_size = PHYS_MEMORY_SIZE;
	serial_init_with_clk(clk);
	writel((1<<22)|1000000,P_WATCHDOG_TC);
	do {
		unsigned ret1, ret2, ret3, ret4;
		ret1 = ret2 = ret3 = ret4 = 0;
		por_cfg = 0;
		ret1 = initial_ddr(&__hw_setting.ddr, __hw_setting.ddr.lane);
		display_error(ret1, "DDr Init");

#ifdef CONFIG_MEM_TEST
		ret2=memTestDevice((volatile datum *)PHYS_MEMORY_START,memory_size);
		display_error(ret2,"TestDevice");
		por_cfg=ret2;
#endif
		ret3 = memTestDataBus((volatile datum *) PHYS_MEMORY_START);
		display_error(ret3, "TestDataBus");
		ret4 = memTestAddressBus((volatile datum *) PHYS_MEMORY_START,
				memory_size);

		display_error(ret4, "TestAddressBus");

		por_cfg = ret1 | ret2 | ret3 | ret4;

	} while (por_cfg != 0);
	writel(0,P_WATCHDOG_RESET);
	return 0;

}
Exemple #9
0
/// Set up socket for listen on 'DEFAULT_PORT' port.
///
/// No parameter
///
/// Return a socket number which is for listen socket(sListenSocket)
/// Return -1 for socket error, program should be terminate
static SOCKET socket_setup()
{
    int iResult;            // system information with error message
    char host_name[128];    // host name
    SOCKET sListenSocket;

    struct addrinfo hints;
    struct addrinfo *result = NULL;

    // Initial socket information
    ZeroMemory(&hints, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    hints.ai_flags = AI_PASSIVE;

    // Resolve the server address and port
    gethostname(host_name, sizeof(host_name));
    sprintf_s(g_sLogMessage, SZ_MAX_LOG, "Calling gethostname with %s\r\n", host_name);
    write_log();
    iResult = getaddrinfo(host_name, DEFAULT_PORT, &hints, &result);
    if (iResult != 0) {
        WSACleanup();
        display_error("main - getaddrinfo", FALSE);
        return -1;
    }

    // Create a SOCKET for connecting to server
    sListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
    if (sListenSocket == INVALID_SOCKET) {
        freeaddrinfo(result);
        WSACleanup();
        display_error("main - socket", FALSE);
        return -1;
    }

    // Setup the TCP listening socket
    iResult = bind(sListenSocket, result->ai_addr, (int)result->ai_addrlen);
    if (iResult == SOCKET_ERROR) {
        freeaddrinfo(result);
        closesocket(sListenSocket);
        WSACleanup();
        display_error("main - bind", FALSE);
        return -1;
    }

    freeaddrinfo(result);
    
    iResult = listen(sListenSocket, SOMAXCONN);
    if (iResult == SOCKET_ERROR) {
        closesocket(sListenSocket);
        WSACleanup();
        display_error("main - listen", FALSE);
        return -1;
    }

    return sListenSocket;
}
Exemple #10
0
/*
 * Offer to disable other MTA's
 */
void disable_other_mta(const char *mta) {
    char buf[SIZ];
    FILE *fp;
    int lines = 0;
    int rv;

    snprintf(buf, sizeof buf,
             "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null; "
             "/bin/ls -l /etc/rc.d/rc*.d/S*%s 2>/dev/null",
             mta, mta
            );
    fp = popen(buf, "r");
    if (fp == NULL) return;

    while (fgets(buf, sizeof buf, fp) != NULL) {
        ++lines;
    }
    fclose(fp);
    if (lines == 0) return;		/* Nothing to do. */

    /* Offer to replace other MTA with the vastly superior Citadel :)  */

    snprintf(buf, sizeof buf,
             "%s \"%s\" %s%s%s%s%s%s%s",
             _("You appear to have the "),
             mta,
             _(" email program\n"
               "running on your system.  If you want Citadel mail\n"
               "connected with "),
             mta,
             _(" you will have to manually integrate\n"
               "them.  It is preferable to disable "),
             mta,
             _(", and use Citadel's\n"
               "SMTP, POP3, and IMAP services.\n\n"
               "May we disable "),
             mta,
             _("so that Citadel has access to ports\n"
               "25, 110, and 143?\n")
            );
    if (yesno(buf, 1) == 0) {
        return;
    }


    snprintf(buf, sizeof buf, "for x in /etc/rc*.d/S*%s; do mv $x `echo $x |sed s/S/K/g`; done >/dev/null 2>&1", mta);
    rv = system(buf);
    if (rv != 0)
        display_error("%s %s.\n", _("failed to disable other mta"), mta);

    snprintf(buf, sizeof buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
    rv = system(buf);
    if (rv != 0)
        display_error(" %s.\n", _("failed to disable other mta"), mta);
}
Exemple #11
0
int AudioDevice::init_device(void)
{
    int buffarg;
    int frag = 0;
    fragnum &= 0xFFFF;
    for(buffarg = 0; fragsize > 1; buffarg++, fragsize >>= 1)
        ;
    frag = FRAG(fragnum, buffarg);
    if(-1 == ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag))
    {
        emit display_error(tr("SNDCTL_DSP_SETFRAGMENT: %1").arg(QString(strerror(errno))));
//        perror("setting fragments");
        return -1;
    }
    fprintf(stderr,"set frag\n");

    if(-1 == ioctl(fd, SNDCTL_DSP_SETFMT, &sample_size))
    {
        emit display_error(tr("SNDCTL_DSP_SETFMT: %1").arg(QString(strerror(errno))));
//        perror("setting sample size");
        return -1;
    }
    fprintf(stderr,"set sample\n");

    if(-1 == ioctl(fd, SNDCTL_DSP_CHANNELS, &channels))
    {
        emit display_error(tr("SNDCTL_DSP_CHANNELS: %1").arg(QString(strerror(errno))));
//        perror("setting channels");
        return -1;
    }
    fprintf(stderr, "set channels\n");

    if(-1 == ioctl(fd, SNDCTL_DSP_SPEED, &sample_rate))
    {
        emit display_error(tr("SNDCTRL_DSP_SPEED: %1").arg(QString(strerror(errno))));
//        perror("setting sample rate");
        return -1;
    }
    fprintf(stderr, "set rate\n");

    audio_buf_info bi;
    if(-1 == ioctl(fd, SNDCTL_DSP_GETOSPACE, &bi))
    {
        emit display_error(tr("SNDCTL_DSP_GETOSPACE: %1").arg(QString(strerror(errno))));
//        perror("getospace");
        return -1;
    }
    fprintf(stderr,"bytes %d,fragments %d,fragsize %d, fragstotal %d\n",
            bi.bytes, bi.fragments, bi.fragsize, bi.fragstotal);
    return 0;

}
Exemple #12
0
void display_error(io_state_stream const & ios, pos_info_provider const * p, throwable const & ex) {
    flycheck_error err(ios);
    if (auto k_ex = dynamic_cast<ext_exception const *>(&ex)) {
        display_error(ios, p, *k_ex);
    } else if (auto e_ex = dynamic_cast<unifier_exception const *>(&ex)) {
        display_error(ios, p, *e_ex);
    } else if (p) {
        display_error_pos(ios, p->get_file_name(), p->get_some_pos().first, p->get_some_pos().second);
        ios << " " << ex.what() << endl;
    } else {
        ios << "error: " << ex.what() << endl;
    }
}
Exemple #13
0
/// Receive command from MBA and send to child through pipe 'lpvThreadParam'.
///
/// \param lpvThreadParam    child input pipe
///
/// Return DWORD WINAPI
static DWORD WINAPI get_and_send_input_thread(LPVOID lpvThreadParam)
{
    CHAR cInBuf[SZ_MAX_CMD];            // input buffer, write to child
    CHAR errorbuf[sizeof(MSG_REC_SUCCESS)];
    
    DWORD nBytesRead, 
          nBytesWrote;
          
    HANDLE hPipeWrite = (HANDLE)lpvThreadParam;

    /// Get input from our console and send it to child through the pipe.
    /// Two conditions to break the inifinite loop
    ///      1. The child process is terminated, causing broken pipe
    ///      2. The main thread detects child process termination and close the DUPLICATED socket,
    ///         causing the recv failed with return <= 0
    while( TRUE ) {
        nBytesRead = recv(g_sClientDupSocket, cInBuf, SZ_MAX_CMD, MSG_WAITALL);
        if( nBytesRead > 0 ) {

            if( !WriteFile(hPipeWrite, cInBuf, strlen(cInBuf), &nBytesWrote, NULL) ) {
                if (GetLastError() == ERROR_NO_DATA) 
                    break;  // Pipe was closed (normal exit path).
                else
                    display_error("get_and_send_input_thread - WriteFile", TRUE);
            }
        }
        else
            break;
        
    }
    return 0;
}
Exemple #14
0
int VideoDevice::get_frame(void **frame_buf, size_t* len)
{
    printf("get frame\n");
    v4l2_buffer queue_buf;
    CLEAR(queue_buf);

    queue_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    queue_buf.memory = V4L2_MEMORY_MMAP;

    if(-1 == ioctl(fd, VIDIOC_DQBUF, &queue_buf))
    {
        switch(errno)
        {
        case EAGAIN:
//            perror("dqbuf");
            return -1;
        case EIO:
            return -1 ;
        default:
            emit display_error(tr("VIDIOC_DQBUF: %1").arg(QString(strerror(errno))));
            return -1;
        }
    }

    *frame_buf = buffers[queue_buf.index].start;
    *len = buffers[queue_buf.index].length;
    index = queue_buf.index;

    return 0;

}
Exemple #15
0
/* Boucle principale du jeu */
int	game_loop(char board[3][3])
{
  int	win;
  int	turn;
  int	error;
  int	player;
  char	input[64];
  int	insert_nb;

  win = -1;
  turn = 0;
  error = -42;
  while (win == -1)
    {
      player = turn % 2;
      system("clear");
      display_board(board);
      display_error(error);
      printf("Player %d enter the case number where to put an %c : ", player + 1, player == 0 ? 'X' : 'O');
      scanf("%s", input);
      error = check_input(board, input);
      if (error == -42)
	{
	  insert_nb = input[0] - '1';
	  board[insert_nb / 3][insert_nb % 3] = player;
	  win = check_winner(board, player);
	  if (win >= 0)
	    return (player);
	  else if (turn >= 8)
	    return (2);
	  turn++;
	}
    }
  return (0);
}
Exemple #16
0
/// Monitors handle for input. Exits when child exits or pipe breaks.
///
/// \param hPipeRead        child output pipe
///
/// No return value
static void read_and_handle_output(HANDLE hPipeRead)
{
    CHAR  cOutBuf[4096];        // output buffer, read from child
    CHAR  cInBuf[sizeof(MSG_REC_SUCCESS)];
    DWORD nBytesRead;

    // send ready message for agent 'execute' action
    send( g_sClientSocket, MSG_EXEC_READY, sizeof(MSG_EXEC_READY), 0 );

    while (TRUE) {
        
        ZeroMemory(cOutBuf, sizeof(cOutBuf));
        
        // Get the stdout from child process
        if (!ReadFile(hPipeRead, cOutBuf, sizeof(cOutBuf), &nBytesRead, NULL) || !nBytesRead)
        {
            if (GetLastError() == ERROR_BROKEN_PIPE)
                break;  // pipe done - normal exit path.
            else
                display_error("read_and_handle_output - ReadFile", TRUE);
        }

        send(g_sClientSocket, (const char*)&nBytesRead, sizeof(nBytesRead), 0);
        send(g_sClientSocket, cOutBuf, nBytesRead, 0);
        
    }
}
Exemple #17
0
/*
 * On systems which use xinetd, see if we can offer to install Citadel as
 * the default telnet target.
 */
void check_xinetd_entry(void)
{
    char *filename = "/etc/xinetd.d/telnet";
    FILE *fp;
    char buf[SIZ];
    int already_citadel = 0;
    int rv;

    fp = fopen(filename, "r+");
    if (fp == NULL) return;		/* Not there.  Oh well... */

    while (fgets(buf, sizeof buf, fp) != NULL) {
        if (strstr(buf, "/citadel") != NULL) {
            already_citadel = 1;
        }
    }
    fclose(fp);
    if (already_citadel) return;	/* Already set up this way. */

    /* Otherwise, prompt the user to create an entry. */
    if (getenv("CREATE_XINETD_ENTRY") != NULL) {
        if (strcasecmp(getenv("CREATE_XINETD_ENTRY"), "yes")) {
            return;
        }
    }
    else {
        snprintf(buf, sizeof buf,
                 _("Setup can configure the \"xinetd\" service to automatically\n"
                   "connect incoming telnet sessions to Citadel, bypassing the\n"
                   "host system login: prompt.  Would you like to do this?\n"
                  )
                );
        if (yesno(buf, 1) == 0) {
            return;
        }
    }

    fp = fopen(filename, "w");
    fprintf(fp,
            "# description: telnet service for Citadel users\n"
            "service telnet\n"
            "{\n"
            "	disable	= no\n"
            "	flags		= REUSE\n"
            "	socket_type	= stream\n"
            "	wait		= no\n"
            "	user		= root\n"
            "	server		= /usr/sbin/in.telnetd\n"
            "	server_args	= -h -L %s/citadel\n"
            "	log_on_failure	+= USERID\n"
            "}\n",
            ctdl_bin_dir);
    fclose(fp);

    /* Now try to restart the service */
    rv = system("/etc/init.d/xinetd restart >/dev/null 2>&1");
    if (rv != 0) {
        display_error(_("failed to restart xinetd.\n"));
    }
}
Exemple #18
0
int		main(int ac, char **av)
{
  t_args	option;

  if (ac < 5)
    return (usage(av[0]));
  signal(SIGINT, &signal_handler);
  signal(SIGPIPE, SIG_IGN);
  srand(time(NULL) + getpid());
  init_args(&option);
  if (check_args(ac, av, &option) == false
      || check_all_args(&option) == false)
    return (usage(av[0]));
  display_init(&option);
  g_s.global_time = 0;
  g_s.id_egg = 1;
  g_s.other_size = 0;
  if ((g_s.sock = init_server(option.port)) == -1)
    return (display_error("Error : Could not init the server.\n"));
  printf("**** Initialization done\n");
  init_map(&g_s, option.width, option.height);
  init_team(&g_s, option.nb_client, option.team_name);
  init_stone(&g_s, option.width * option.height);
  g_s.option = &option;
  server_loop(&g_s);
  xclose(g_s.sock);
  return (0);
}
Exemple #19
0
int get_initial_cursor(const struct electorate *elec)
{
  struct http_vars *reply;
  int initial_cursor;
  /* SIPL 2011-09-26 Added one to length of array.  There was
     no chance of a buffer overflow, but do this to make it consistent
     with all other uses of INT_CHARS. */
  char ecodestr[INT_CHARS+1];
  struct http_vars request[]
    = { { (char*)"ecode", ecodestr }, { NULL, NULL } };

  sprintf(ecodestr, "%u", elec->code);

  reply = http_exchange(SERVER_ADDRESS, SERVER_PORT, CURSOR_CGI,request);
  if (!reply)
    display_error(ERR_SERVER_UNREACHABLE);

  initial_cursor = atoi(http_string(reply, "cursor"));

  http_free(reply);

  cursor = initial_cursor;

  return initial_cursor;
}
Exemple #20
0
client_t * extract_json(char *text) {
	json_t *root, *rtinfo, *node;
	json_error_t error;
	unsigned int i;
	client_t *clients;
	
	
	if(!(root = json_loads(text, 0, &error))) {
		display_error("json errors\n");
		return NULL;
	}
	
	json_check_object(root);
	
	rtinfo = json_object_get(root, "rtinfo");
	json_check_array(rtinfo);
	
	clients = client_create(json_array_size(rtinfo));
	
	for(i = 0; i < json_array_size(rtinfo); i++) {
		node = json_array_get(rtinfo, i);
		json_check_object(node);
		
		extract_json_head(node, &clients->clients[i]);
		extract_json_summary(node, &clients->clients[i]);
		extract_json_network(node, &clients->clients[i]);
		extract_json_disk(node, &clients->clients[i]);
	}
	
	json_decref(root);
	
	return clients;
}
Exemple #21
0
	/* needed to shut the compilor up */
	return(0);
}

//admin only command: lists registered bot users
static int msg_listusers(const char *replyto, struct userlist *user, const char * UNUSED(data))
{
	info_log("Requested listusers by %s\n", user->userinfo->nick);
	int i=0;
	struct userdata *userdata_curr;
	userdata_curr=conf_userdata;
	while(userdata_curr != NULL){
		msgreply(user, replyto, "      %s",userdata_curr->usernick);
		userdata_curr=userdata_curr->next;
		i++;
	}
	msgreply(user, replyto, "--- %i users total ---",i);
	return(0);
}


static int msg_version(const char *replyto, struct userlist *user, const char * UNUSED(data))
{
	msgreply(user, replyto, "Version: %s", botinfo->ver);
	return(0);
}

static int msg_time(const char *replyto, struct userlist *user, const char * UNUSED(data))
{
	char timestr[50];

	time(&currtime);

	strftime(timestr, sizeof(timestr), "%a %b %d %H:%M:%Y",
		 localtime(&currtime));

	msgreply(user, replyto, "The current time is: %s", timestr);
	return(0);
}

static int msg_reload(const char *replyto, struct userlist *user, const char * UNUSED(data))
{
	info_log("Reload by %s\n", user->userinfo->nick);
	acid_reload("reloading\n");
	//msgreply(user, replyto, "Reload complete.");
	msgreply(user, replyto, "Professore ho ricaricato Utenti e Log sulla navetta siamo pronti a consegnarli.");

	return(0);
}

#if 0 /* too ugly to live */
static int msg_help(const char *replyto, struct userlist *user, const char *data)
{
	char *line;
	FILE *fp_help;

	/* This is not ideal.. spending this much time inside a routine will
	   make it hard for the bot to handle outside events in a timely manor */

	if ((line = malloc(100)) == NULL) {
		display_error("execute: Malloc error!\n");
		return (-1);
	}
	if ((fp_help = fopen("../docs/help", "r")) == NULL) {
		info_log("Cant open help file! \n");
		free(line);
		msgreply(user, replyto, "Cant open help file! ");
		return(0);
	}
	while (fgets(line, 100, fp_help) != NULL) {
		if (msgreply(user, replyto, "%s", line) == -1) {
			free(line);
			return (-1);
		}
		/* give the server time to accept the input */
		sleep(1);
	}
	free(line);
	return (0);
}
Exemple #22
0
void sshsocket::AcceptHost(QString title, QString hostname, QString username, QString password, qint32 port )
{
    host = new Host(title, hostname, username, port) ;
#ifdef Q_WS_SIMULATOR
     host->setPassword(password);
#else
     QByteArray clearData ;
     clearData.append(password) ;
     RAWDATA_PTR cipherData = NULL;
     size_t cipherLength = 0;
     aegis_crypto_result rc = aegis_crypto_encrypt(clearData.data(), clearData.length(), NULL, &cipherData, &cipherLength) ;
     if (aegis_crypto_ok != rc) {
             AEGIS_ERROR("%s: aegis_crypto_encrypt failed (%s)", __func__,
                        aegis_crypto_last_error_str());
     }
     QByteArray encrypted((char *)cipherData, cipherLength);
     host->setSecret(encrypted);
    // aegis_crypto_free(cipherData);
#endif
    socket = new QTcpSocket(this) ;
    qint16 port_value = host->port() ;
    socket->connectToHost(host->hostname(), port_value);
    connect(socket, SIGNAL(connected()), this, SLOT(socket_connected_slot())) ;
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(display_error(QAbstractSocket::SocketError))) ;
}
Exemple #23
0
t_dir		*get_dir(char *path, t_option *option) {
  DIR		*rep;
  FDIR          *file;
  FSTAT		sfile;
  t_dir		*dir;
  char		*tfile;
  
  rep = opendir(path);
  dir = 0;
  if (rep == 0) {
    display_error(path);
    return (0);
  }
  while ((file = readdir(rep)) != 0) {
    tfile = cat_path(path, file->d_name);
    if (option->opt[7] == 1)
      stat(tfile, &sfile);
    else
      lstat(tfile, &sfile);
    dir = push_dir(dir, file->d_name, sfile, tfile);
    free(tfile);
  }
  closedir(rep);
  return (dir);
}
Exemple #24
0
receive_file::receive_file(QWidget *parent,QString msg,QString my,int portt) :
    QWidget(parent),
    ui(new Ui::receive_file)
{
    ui->setupUi(this);
    msg_from=msg;
    myname=my;
    port=portt;
    ///////////////////
    QPalette pal;
    QPixmap mypix(QDir::toNativeSeparators("./resorces/login.jpg"));
    pal.setBrush(QPalette::Window, QBrush(mypix));
    setPalette(pal);
    ////////////////////////



    trans=new QTcpSocket();///建立一个与文件传输server的链接;
    totalBytes = 0;
    bytesReceived = 0;
    fileNameSize = 0;

    connect(trans,SIGNAL(connected()),this,SLOT(start_tranfor()));
  //  connect(trans,SIGNAL(bytesWritten(qint64)),this,SLOT(update_clientprocess()));
    connect(trans,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(display_error(QAbstractSocket::SocketError)));
    connect(trans,SIGNAL(readyRead()),this,SLOT(update_clientprocess()));
}
Exemple #25
0
/*****************************************************************************
 * Startup the printing interface
 * Done at start of program
*****************************************************************************/
void StartTextPrnt(void)
{
   memset( &pd, 0, sizeof(PRINTDLG) );
   pd.lStructSize = sizeof(PRINTDLG);

   memset( &lf, 0, sizeof(LOGFONT) );

   strcpy( lf.lfFaceName, "LinePrinter BM" );
   offsetx = 450;
   offsety = 200;
   savelpi = 8;
   savecpi = 16;
   SetCPI( MAKELONG(savecpi,savelpi) );
   lf.lfWidth = lf.lfHeight = 1;
   lf.lfWeight = 400;
   lf.lfPitchAndFamily = FF_MODERN|FIXED_PITCH;
   // Get a DC handle to the system`s default printer. using
   // the PD_RETURNDEFAULT flag ensures that no dialog is opened.
   pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT | PD_NOSELECTION;
   PrintDlg(&pd);
   if ( pd.hDevMode == NULL )
   {
      display_error(78,"Unable to initialise default printer",FALSE);
      return;
   }
   SetOrient( DMORIENT_PORTRAIT );
}
Exemple #26
0
BOOL ShellEntry::launch_entry(HWND hwnd, UINT nCmdShow)
{
	CONTEXT("ShellEntry::launch_entry()");

	SHELLEXECUTEINFO shexinfo;

	shexinfo.cbSize = sizeof(SHELLEXECUTEINFO);
	shexinfo.fMask = SEE_MASK_INVOKEIDLIST;	// SEE_MASK_IDLIST is also possible.
	shexinfo.hwnd = hwnd;
	shexinfo.lpVerb = NULL;
	shexinfo.lpFile = NULL;
	shexinfo.lpParameters = NULL;
	shexinfo.lpDirectory = NULL;
	shexinfo.nShow = nCmdShow;

	ShellPath shell_path = create_absolute_pidl();
	shexinfo.lpIDList = &*shell_path;

	 // add PIDL to the recent file list
	SHAddToRecentDocs(SHARD_PIDL, shexinfo.lpIDList);

	BOOL ret = TRUE;

	if (!ShellExecuteEx(&shexinfo)) {
		display_error(hwnd, GetLastError());
		ret = FALSE;
	}

	return ret;
}
Exemple #27
0
int __cdecl main( int argc, char* argv[] )
{
    
    ShowWindow(GetConsoleWindow(),SW_HIDE);
    
    int iResult;
    
    WSADATA wsaData;
    SOCKET sListenSocket = INVALID_SOCKET;  // listen socket
    
    GetLocalTime(&localTime);
    
    g_hLog = create_log_file( NULL );
    if (g_hLog == INVALID_HANDLE_VALUE) {
        display_error("main - CreateFile - log file", FALSE);
        return 1;
    }

    // Initialize Winsock using Windows socket API version 2.2
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        display_error("main - WSAStartup", FALSE);
        return 2;
    }

    // Server socket setup
    sListenSocket = socket_setup();
    if (sListenSocket == -1) {
        display_error("main - socket_setup", FALSE);
        return 3;
    }

    // Giving welcom message
    sprintf_s(g_sLogMessage, SZ_MAX_LOG, "================ Welcome to MBA Agent ================\r\n");
    write_log();

    // Server infinite loop
    server_mainloop( sListenSocket );

    // Cleanup
    WSACleanup();
    closesocket(sListenSocket);
    CloseHandle(g_hLog);

    return 0;
}
Exemple #28
0
void execute(char ** args)
{
    pid_t pid;
    int background = 0;

    char ** argsInd = args;
    while(*argsInd != '\0')
    {
        if(background)
        {
            background = 0;
        }

        if(strcmp(*argsInd, "&") == 0)
        {
            background = 1;
        }

        argsInd++;
    }

    if(background)
    {
        *(argsInd - 1) = '\0';
    }

    if((pid = fork()) < 0)
    {
        fail_with_error("Could not fork new process.");
    }
    else if(pid == 0)
    {
        if(execvp(*args, args) < 0) // Check execution success.
        {
            display_error("Execution failed.");
        }
    }
    else if(!background)
    {
        if(wait(NULL) == -1)
        {
            display_error("Process did not return on wait.");
        }
    }
}
Exemple #29
0
/* DDS3.2.14: Get Preference Number Image */
struct image *get_preference_image(unsigned int ecode, unsigned int number)
{
	struct image *preference;

	if((preference = get_preference_image_mayfail(ecode,number))==NULL){
		display_error(ERR_SERVER_UNREACHABLE);
	}

	return(preference);
}
Exemple #30
0
int l_display_error(lua_State *l)
{
  const gchar *message;

  luaL_checktype(l, 1, LUA_TSTRING);
  message = lua_tostring(l, 1);

  display_error(message);
  return 0;
}