Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
 virtual status visit(const sub &node) {
     return handle_sub(node);
 }
Ejemplo n.º 3
0
void handle(node *n) {
	if (n->type == type_id) {
		vlog("[code_gen] handle: identifier\n");
		handle_identifier(n);
	} else if (n->type == type_con) {
		vlog("[code_gen] handle: constant\n");
		handle_constant(n);
	} else if (n->type == type_string) {
		vlog("[code_gen] handle: string constant\n");
		handle_string(n);
	} else {

	if (strcmp(n->id,"postfix_expr") == 0) {
		vlog("[code_gen] handle: postfix_expr \n");
		handle_postfix_expr(n);
	} else if (strcmp(n->id,"argument_expr_list") == 0) {
		vlog("[code_gen] handle: argument_expr_list \n");
		handle_argument_expr_list(n);
	} else if (strcmp(n->id,"unary_expr") == 0) {
		vlog("[code_gen] handle: unary_expr \n");
		handle_unary_expr(n);
	} else if (strcmp(n->id,"sizeof") == 0) {
		vlog("[code_gen] handle: sizeof \n");
		handle_sizeof(n);
	} else if (strcmp(n->id,"cast_expr") == 0) {
		vlog("[code_gen] handle: cast_expr \n");
		handle_cast_expr(n);
	} else if (strcmp(n->id,"multiply") == 0) {
		vlog("[code_gen] handle: multiply \n");
		handle_multiply(n);
	} else if (strcmp(n->id,"divide") == 0) {
		vlog("[code_gen] handle: divide \n");
		handle_divide(n);
	} else if (strcmp(n->id,"mod") == 0) {
		vlog("[code_gen] handle: mod \n");
		handle_mod(n);
	} else if (strcmp(n->id,"add") == 0) {
		vlog("[code_gen] handle: add \n");
		handle_add(n);
	} else if (strcmp(n->id,"sub") == 0) {
		vlog("[code_gen] handle: sub \n");
		handle_sub(n);
	} else if (strcmp(n->id,"shift_left") == 0) {
		vlog("[code_gen] handle: shift_left \n");
		handle_shift_left(n);
	} else if (strcmp(n->id,"shift_right") == 0) {
		vlog("[code_gen] handle: shift_right \n");
		handle_shift_right(n);
	} else if (strcmp(n->id,"less_than") == 0) {
		vlog("[code_gen] handle: less_than \n");
		handle_less_than(n);
	} else if (strcmp(n->id,"greater_than") == 0) {
		vlog("[code_gen] handle: greater_than \n");
		handle_greater_than(n);
	} else if (strcmp(n->id,"less_equal_than") == 0) {
		vlog("[code_gen] handle: less_equal_than \n");
		handle_less_equal_than(n);
	} else if (strcmp(n->id,"greater_equal_than") == 0) {
		vlog("[code_gen] handle: greater_equal_than \n");
		handle_greater_equal_than(n);
	} else if (strcmp(n->id,"equality") == 0) {
		vlog("[code_gen] handle: equality \n");
		handle_equality(n);
	} else if (strcmp(n->id,"equality_not") == 0) {
		vlog("[code_gen] handle: equality_not \n");
		handle_equality_not(n);
	} else if (strcmp(n->id,"bitwise_and") == 0) {
		vlog("[code_gen] handle: bitwise_and \n");
		handle_bitwise_and(n);
	} else if (strcmp(n->id,"bitwise_xor") == 0) {
		vlog("[code_gen] handle: bitwise_xor \n");
		handle_bitwise_xor(n);
	} else if (strcmp(n->id,"bitwise_or") == 0) {
		vlog("[code_gen] handle: bitwise_or \n");
		handle_bitwise_or(n);
	} else if (strcmp(n->id,"logical_and") == 0) {
		vlog("[code_gen] handle: logical_and \n");
		handle_logical_and(n);
	} else if (strcmp(n->id,"logical_or") == 0) {
		vlog("[code_gen] handle: logical_or \n");
		handle_logical_or(n);
	} else if (strcmp(n->id,"conditional") == 0) {
		vlog("[code_gen] handle: conditional \n");
		handle_conditional(n);
	} else if (strcmp(n->id,"assignment") == 0) {
		vlog("[code_gen] handle: assignment \n");
		handle_assignment(n);
	} else if (strcmp(n->id,"expression") == 0) {
		vlog("[code_gen] handle: expression \n");
		handle_expression(n);
	} else if (strcmp(n->id,"declaration") == 0) {
		vlog("[code_gen] handle: declaration \n");
		handle_declaration(n);
	} else if (strcmp(n->id,"declaration_specifier") == 0) {
		vlog("[code_gen] handle: declaration_specifier \n");
		handle_declaration_specifier(n);
	} else if (strcmp(n->id,"init_declarator_list") == 0) {
		vlog("[code_gen] handle: init_declarator_list \n");
		handle_init_declarator_list(n);
	} else if (strcmp(n->id,"init_declarator") == 0) {
		vlog("[code_gen] handle: init_declarator \n");
		handle_init_declarator(n);
	} else if (strcmp(n->id,"struct_union") == 0) {
		vlog("[code_gen] handle: struct_union \n");
		handle_struct_union(n);
	} else if (strcmp(n->id,"struct_declaration_list") == 0) {
		vlog("[code_gen] handle: struct_declaration_list \n");
		handle_struct_declaration_list(n);
	} else if (strcmp(n->id,"struct_declaration") == 0) {
		vlog("[code_gen] handle: struct_declaration \n");
		handle_struct_declaration(n);
	} else if (strcmp(n->id,"specifier_qualifier_list") == 0) {
		vlog("[code_gen] handle: specifier_qualifier_list \n");
		handle_specifier_qualifier_list(n);
	} else if (strcmp(n->id,"struct_declarator_list") == 0) {
		vlog("[code_gen] handle: struct_declarator_list \n");
		handle_struct_declarator_list(n);
	} else if (strcmp(n->id,"struct_declarator") == 0) {
		vlog("[code_gen] handle: struct_declarator \n");
		handle_struct_declarator(n);
	} else if (strcmp(n->id,"enum_specifier") == 0) {
		vlog("[code_gen] handle: enum_specifier \n");
		handle_enum_specifier(n);
	} else if (strcmp(n->id,"enum_list") == 0) {
		vlog("[code_gen] handle: enum_list \n");
		handle_enum_list(n);
	} else if (strcmp(n->id,"enumerator") == 0) {
		vlog("[code_gen] handle: enumerator \n");
		handle_enumerator(n);
	} else if (strcmp(n->id,"declarator") == 0) {
		vlog("[code_gen] handle: declarator \n");
		handle_declarator(n);
	} else if (strcmp(n->id,"direct_declarator") == 0) {
		vlog("[code_gen] handle: direct_declarator \n");
		handle_direct_declarator(n);
	} else if (strcmp(n->id,"pointer") == 0) {
		vlog("[code_gen] handle: pointer \n");
		handle_pointer(n);
	} else if (strcmp(n->id,"type_qualifier_list") == 0) {
		vlog("[code_gen] handle: type_qualifier_list \n");
		handle_type_qualifier_list(n);
	} else if (strcmp(n->id,"parameter_type_list") == 0) {
		vlog("[code_gen] handle: parameter_type_list \n");
		handle_parameter_type_list(n);
	} else if (strcmp(n->id,"parameter_list") == 0) {
		vlog("[code_gen] handle: parameter_list \n");
		handle_parameter_list(n);
	} else if (strcmp(n->id,"parameter_declaration") == 0) {
		vlog("[code_gen] handle: parameter_declaration \n");
		handle_parameter_declaration(n);
	} else if (strcmp(n->id,"identifier_list") == 0) {
		vlog("[code_gen] handle: identifier_list \n");
		handle_identifier_list(n);
	} else if (strcmp(n->id,"type_name") == 0) {
		vlog("[code_gen] handle: type_name \n");
		handle_type_name(n);
	} else if (strcmp(n->id,"abstract_declarator") == 0) {
		vlog("[code_gen] handle: abstract_declarator \n");
		handle_abstract_declarator(n);
	} else if (strcmp(n->id,"direct_abstract_declarator") == 0) {
		vlog("[code_gen] handle: direct_abstract_declarator \n");
		handle_direct_abstract_declarator(n);
	} else if (strcmp(n->id,"initializer") == 0) {
		vlog("[code_gen] handle: initializer \n");
		handle_initializer(n);
	} else if (strcmp(n->id,"initializer_list") == 0) {
		vlog("[code_gen] handle: initializer_list \n");
		handle_initializer_list(n);
	} else if (strcmp(n->id,"labeled_statement") == 0) {
		vlog("[code_gen] handle: labeled_statement \n");
		handle_labeled_statement(n);
	} else if (strcmp(n->id,"compound_statement") == 0) {
		vlog("[code_gen] handle: compound_statement \n");
		handle_compound_statement(n);
	} else if (strcmp(n->id,"declaration_list") == 0) {
		vlog("[code_gen] handle: declaration_list \n");
		handle_declaration_list(n);
	} else if (strcmp(n->id,"statement_list") == 0) {
		vlog("[code_gen] handle: statement_list \n");
		handle_statement_list(n);
	} else if (strcmp(n->id,"expression_statement") == 0) {
		vlog("[code_gen] handle: expression_statement \n");
		handle_expression_statement(n);
	} else if (strcmp(n->id,"selection_statement") == 0) {
		vlog("[code_gen] handle: selection_statement \n");
		handle_selection_statement(n);
	} else if (strcmp(n->id,"iteration_statement") == 0) {
		vlog("[code_gen] handle: iteration_statement \n");
		handle_iteration_statement(n);
	} else if (strcmp(n->id,"jump_statement") == 0) {
		vlog("[code_gen] handle: jump_statement \n");
		handle_jump_statement(n);
	} else if (strcmp(n->id,"translation_unit") == 0) {
		vlog("[code_gen] handle: translation_unit \n");
		handle_translation_unit(n);
	} else if (strcmp(n->id,"function_definition") == 0) {
		vlog("[code_gen] handle: function_definition \n");
		handle_function_definition(n);
	} else if (strcmp(n->id,"asm") == 0) {
		vlog("[code_gen] handle: inline_assembly \n");
		handle_asm(n);
	}

	}
}