Esempio n. 1
0
static void handle_message(struct cfw_message *msg, void *param)
{
	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CIRCULAR_STORAGE_PUSH_REQ:
		handle_push(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_POP_REQ:
		handle_pop(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_PEEK_REQ:
		handle_peek(msg);
		break;
	case MSG_ID_CIRCULAR_STORAGE_CLEAR_REQ:
		handle_clear(msg);
		break;
	case MSG_ID_LL_CIRCULAR_STORAGE_SHUTDOWN_REQ:
		cfw_send_message(CFW_MESSAGE_PRIV(msg));
		break;
	case MSG_ID_CIRCULAR_STORAGE_GET_REQ:
		handle_get(msg);
	default:
		cfw_print_default_handle_error_msg(LOG_MODULE_MAIN,
						   CFW_MESSAGE_ID(
							   msg));
		break;
	}

	cfw_msg_free(msg);
}
Esempio n. 2
0
/* handle an incoming packet, acking it if it is a data packet for us
 * returns the message length > 0 if this was a valid data message from a peer.
 * if it gets a valid key, returns -1 (details below)
 * Otherwise returns 0 and does not fill in any of the following results.
 *
 * if it is a data or ack, it is saved in the xchat log
 * if it is a valid data message from a peer or a broadcaster,
 * fills in verified and broadcast
 * fills in contact, message (to point to malloc'd buffers, must be freed)
 * if not broadcast, fills in desc (also malloc'd), sent (if not null)
 * and duplicate.
 * if verified and not broadcast, fills in kset.
 * the data message (if any) is null-terminated
 *
 * if kcontact and ksecret1 are not NULL, assumes we are also looking
 * for key exchange messages sent to us matching either of ksecret1 or
 * (if not NULL) ksecret2.  If such a key is found, returns -1.
 * there are two ways of calling this:
 * - if the user specified the peer's secret, first send initial key,
 *   then call handle_packet with our secret in ksecret1 and our
 *   peer's secret in ksecret2.
 * - otherwise, put our secret in ksecret1, make ksecret2 and kaddr NULL,
 *   and handle_packet is ready to receive a key.
 * In either case, if a matching key is received, it is saved and a
 * response is sent (if a response is a duplicate, it does no harm).
 * kmax_hops specifies the maximum hop count of incoming acceptable keys,
 * and the hop count used in sending the key.
 *
 * if subscription is not null, listens for a reply containing a key
 * matching the subscription, returning -2 if a match is found.
 */
int handle_packet (int sock, char * packet, int psize,
                   char ** contact, keyset * kset,
                   char ** message, char ** desc,
                   int * verified, time_t * sent,
                   int * duplicate, int * broadcast,
                   char * kcontact, char * ksecret1, char * ksecret2,
                   int kmax_hops,
                   char * subscription, 
                   unsigned char * addr, int nbits)
{
  if (! is_valid_message (packet, psize))
    return 0;

  struct allnet_header * hp = (struct allnet_header *) packet;
  int hsize = ALLNET_SIZE (hp->transport);
  if (psize < hsize)
    return 0;

#ifdef DEBUG_PRINT
  if (hp->hops > 0)  /* not my own packet */
    print_packet (packet, psize, "xcommon received", 1);
#endif /* DEBUG_PRINT */

  if (hp->message_type == ALLNET_TYPE_ACK) {
    handle_ack (sock, packet, psize, hsize);
    return 0;
  }

  if (hp->message_type == ALLNET_TYPE_CLEAR) { /* a broadcast packet */
    if ((subscription != NULL) && (addr != NULL)) {
      int sub = handle_sub (sock, hp, packet + hsize, psize - hsize,
                            subscription, addr, nbits);
#ifdef DEBUG_PRINT
      printf ("handle_sub (%d, %p, %p, %d, %s, %p, %d) ==> %d\n",
              sock, hp, packet + hsize, psize - hsize, subscription,
              addr, nbits, sub);
#endif /* DEBUG_PRINT */
      if (sub > 0)   /* received a key in response to our subscription */
        return sub;
    }
#ifdef DEBUG_PRINT
    else
      printf ("subscription %p, addr %p, did not call handle_sub\n",
              subscription, addr);
#endif /* DEBUG_PRINT */
    return handle_clear (hp, packet + hsize, psize - hsize,
                         contact, message, verified, broadcast);
  }

  if (hp->message_type == ALLNET_TYPE_DATA) /* an encrypted data packet */
    return handle_data (sock, hp, packet + hsize, psize - hsize,
                        contact, kset, message, desc, verified, sent,
                        duplicate, broadcast);

  if (hp->message_type == ALLNET_TYPE_KEY_XCHG)
    return handle_key (sock, hp, packet + hsize, psize - hsize,
                       kcontact, ksecret1, ksecret2, kmax_hops);

  return 0;
}
static void handle_message(struct cfw_message * msg, void * param)
{
    switch (CFW_MESSAGE_ID(msg)) {
    case MSG_ID_LL_ERASE_BLOCK_REQ:
        handle_erase_block(msg);
        break;
    case MSG_ID_LL_READ_PARTITION_REQ:
        handle_read_partition(msg);
        break;
    case MSG_ID_LL_WRITE_PARTITION_REQ:
        handle_write_partition(msg);
        break;
#ifdef CONFIG_SERVICES_QUARK_SE_STORAGE_CIRCULAR
    case MSG_ID_LL_CIR_STOR_INIT_REQ:
        handle_cir_stor_init(msg);
        break;
    case MSG_ID_LL_PUSH_REQ:
        handle_push(msg);
        break;
    case MSG_ID_LL_POP_REQ:
        handle_pop(msg);
        break;
    case MSG_ID_LL_PEEK_REQ:
        handle_peek(msg);
        break;
    case MSG_ID_LL_CLEAR_REQ:
        handle_clear(msg);
        break;
#endif
    default:
        cfw_print_default_handle_error_msg(LOG_MODULE_MAIN, CFW_MESSAGE_ID(msg));
        break;
    }

    cfw_msg_free(msg);
}
Esempio n. 4
0
static void
handle_send()
{
    char c  = (char)0;
    off_t pos;
    int cc = 0;
    int i = 0;

    pos = lseek(tmon_temp, (off_t) 0, SEEK_SET);

    if (pos != 0)
	fprintf(stderr, "Bogus file position\n");

    if (Verbose)
	printf("\n");

    /* discard leading white space */
    while ( ( cc = read(tmon_temp,&c,1) ) != 0 && isspace((int)c))
	continue;

    if ( cc != 0 ) {
	pos = lseek(tmon_temp, (off_t) -1, SEEK_CUR);
    }

    if (SingleStepMode) {
	char buf[1024];
	fprintf(stdout, "\n*******************************************************************************\n");
	while ((cc = read(tmon_temp,buf,1024))>0) {
	    buf[cc] = '\0';
	    fprintf(stdout, "%s", buf);
	}
	fprintf(stdout, "\n*******************************************************************************\n\n");
	(void)lseek(tmon_temp, (off_t)pos, SEEK_SET);
    }

    query_buffer[0] = 0;

    /*
     *  Stripping out comments (if any) from the query (should really be
     *  handled in the parser, of course).
     */
    while ( ( cc = read(tmon_temp,&c,1) ) != 0) {
	switch(c) {
	case '\n':
	    query_buffer[i++] = ' ';
	    break;
	case '-': {
	    int temp; 
	    char temp_c;
	    if ((temp = read(tmon_temp,&temp_c,1)) > 0) {
		if (temp_c == '-' ) {
		    /* read till end of line */
		    while ((temp = read(tmon_temp,&temp_c,1)) != 0) {
			if (temp_c=='\n')
			    break;
		    }
		}else {
		    query_buffer[i++] = c;
		    query_buffer[i++] = temp_c;
		}
	    } else {
		query_buffer[i++] = c;
	    }
	    break;
	}
	case '$': {
	    int temp;
	    char temp_c[4];
	    /*
	     * monitor feature, not POSTGRES SQL. When monitor sees $PWD,
	     * it will substitute in the current directory.
	     */
	    if ((temp = read(tmon_temp,temp_c,3)) > 0) {
		temp_c[temp] = '\0';
		if (!strncmp(temp_c, "PWD", 3)) {
		    int len;
		    char cwdPath[MAXPATHLEN];
		    if (getcwd(cwdPath, MAXPATHLEN)==NULL) {
			fprintf(stderr,
				"cannot get current working directory\n");
			break;
		    }
		    len = strlen(cwdPath);
		    query_buffer[i] = '\0';
		    strcat(query_buffer, cwdPath);
		    i += len;
		} else {
		    int j;
		    query_buffer[i++] = c;
		    for(j = 0; j < temp; j++) {
			query_buffer[i++] = temp_c[j];
		    }
		}
	    } else {
		query_buffer[i++] = c;
	    }
	    break;
	}
	default:
	    query_buffer[i++] = c;
	    break;
	}
    }

    if (query_buffer[0] == 0) {
        query_buffer[0] = ' ';
        query_buffer[1] = 0;
    }

    if (Verbose && !SingleStepMode)
	fprintf(stdout,"Query sent to backend is \"%s\"\n", query_buffer);

    fflush(stderr);
    fflush(stdout);
    
    /*
     * Repeat commands until done.
     */

	handle_execution(query_buffer);

    /* clear the query buffer and temp file -- this is very expensive */
    handle_clear();
    memset(query_buffer,0,i);
}
Esempio n. 5
0
static void
do_input(FILE *ifp)
{
    int c;
    char escape;

    /*
     *  Processing user input.
     *  Basically we stuff the user input to a temp. file until
     *  an escape char. is detected, after which we switch
     *  to the appropriate routine to handle the escape.
     */

    if (ifp == stdin) {
	if (Verbose)
	    fprintf(stdout,"\nGo \n* ");
	else {
	    if (!Silent)
		fprintf(stdout, "* ");
	}
    }
    while ((c = getc(ifp)) != EOF ) {
	if ( c == '\\') {
	    /* handle escapes */
	    escape = getc(ifp);
	    switch( escape ) {
	      case 'e':
		handle_editor();
		break;
	      case 'g':
		handle_send();
		break;
	      case 'i':
		{
		    bool oldVerbose;

		    if (SingleStepMode) {
			oldVerbose = Verbose;
			Verbose = false;
		    }
		    handle_file_insert(ifp);
		    if (SingleStepMode)
			Verbose = oldVerbose;
		}
		break;
	      case 'p':
		handle_print();
		break;
	      case 'q':
		handle_exit(0);
		break;
	      case 'r':
		handle_clear();
		break;
	      case 's':
		handle_shell();
		break;
	      case 't':
		handle_print_time();
		break;
	      case 'w':
		handle_write_to_file();
		break;
	      case '?':
	      case 'h':
		handle_help();
		break;
	      case '\\':
		c = escape;
		stuff_buffer(c); 
		break;
	      case ';':
		c = escape;
		stuff_buffer(c);
		break;
	      default:
		fprintf(stderr, "unknown escape given\n");
		break;
	    } /* end-of-switch */
	    if (ifp == stdin && escape != '\\') {
		if (Verbose)
		    fprintf(stdout,"\nGo \n* ");
		else {
		    if (!Silent)
			fprintf(stdout, "* ");
		}
	    }
	} else {
	    stuff_buffer(c);
	    if (c == ';' && SemicolonIsGo) {
		handle_send();
		if (Verbose)
		    fprintf(stdout,"\nGo \n* ");
		else {
		    if (!Silent)
			fprintf(stdout, "* ");
		}
	    }
	}
    }
}