Exemplo n.º 1
0
int ident_client_protocol(struct conn_table_st *ct, int i,
			  char *msg, size_t msg_size){
  /*
   * This function tries to identify the client's protocol from
   * the msg sent, using the default if it could not identify a particular one.
   * It also stores the protocol's id in the data portion of the client's
   * conn structure (libconn). If the protocol was already defined it
   * returns an error code (see below).
   *
   * Returns
   *	0 => protocol identified with no errors
   *   -1 => (memory) error setting storing the data 
   *    1 => the default protocol was used
   *    2 => the protocol was already defined
   */
  size_t p_len;
  int p = PROTOCOL_DEFAULT;
  int r = 1;  /* the default was used */
  int status = 0;

  if(get_client_protocol(ct, i) != PROTOCOL_UNKNOWN){
    /*
     * The protocol was already identified.
     */
    return(2);
  }

  /*
   * At the moment we have three to check. Perhaps
   * the best thing is organize them in an array.
   */

  p_len = strlen(PROTOCOL_NBS1_STR);
  if((msg_size == p_len) && (strncmp(msg, PROTOCOL_NBS1_STR, p_len) == 0)){
    p = PROTOCOL_NBS1;
    r = 0;
  }

  if(r == 1){
    p_len = strlen(PROTOCOL_NBS2_STR);
    if((msg_size == p_len) && (strncmp(msg, PROTOCOL_NBS2_STR, p_len) == 0)){
      p = PROTOCOL_NBS2;
      r = 0;
    }
  }

  if(r == 1){
    p_len = strlen(PROTOCOL_EMWIN_STR);
    if((msg_size == p_len) && (strncmp(msg, PROTOCOL_EMWIN_STR, p_len) == 0)){
      p = PROTOCOL_EMWIN;
      r = 0;
    }
  }

  status = set_client_protocol(ct, i, p);
  if(status != 0)
    r = -1;

  return(r);
}
Exemplo n.º 2
0
int start_client_1(char *ip)
{
/* NOTE JC_0024_1
 * Jerry:
 * HoHa, why do I split start_client into 1 and 2?
 * En, maybe I'm tired execrably, HTC human-outsourcing?
 * Now, I'm writing rather than coding, am I?
 * Oct29, 2012,
 * My God, tommorrow perhaps is the last day for THE EARTH.
 * Breath deeply and happlily.
 * My love daugther and honey!
 * BTW, one more cholocate on codeing next
 * If you see this comments, that's say I have gone from DR building....
 */
	int ret = 0;
	struct client_protocol protocol_c;
	struct service_client client;

	set_client_control(&g_manager.control[SERVICE_CLIENT_MODE]);
	get_client_protocol(&protocol_c);
	set_client_protocol(&protocol_c);
	get_client_service(&client);
	set_client_service(&client);

	g_manager.control[SERVICE_CLIENT_MODE].init_service();
	g_manager.current_mode = SERVICE_CLIENT_MODE;
	g_manager.status[SERVICE_CLIENT_MODE] = STATUS_STOP;

	//client_connect_server(ip, "KEY");
	return ret;
}
Exemplo n.º 3
0
int ident_client_protocol(struct conn_table_st *ct, int i,
			  char *msg, size_t msg_size){
  /*
   * This function tries to identify the client's protocol from
   * the msg sent, using the default if it could not identify a particular one.
   * It also stores the protocol's id in the data portion of the client's
   * conn structure (libconn). If the protocol was already defined it
   * returns an error code (see below).
   *
   * Returns
   *	0 => protocol identified with no errors
   *   -1 => (memory) error setting storing the data 
   *    1 => the default protocol was used
   *    2 => the protocol was already defined
   *
   * The msg is a string (not '\0' terminated) of the form
   *
   *	ByteBlast Client|[email protected]|V<n>
   *
   * Here we look only for the V1 or V2
   */
  char *s;	/* point to V<n> within msg */
  size_t p_len;
  int p = PROTOCOL_DEFAULT;
  int r = 1;  /* the default was used */
  int status = 0;

  if(get_client_protocol(ct, i) != PROTOCOL_UNKNOWN){
    /*
     * The protocol was already identified.
     */
    return(2);
  }

  /*
   * At the moment we have two to check. Perhaps
   * the best thing is organize them in an array.
   */

  p_len = strlen(PROTOCOL_EMWIN1_STR);
  if(msg_size >= p_len){
    s = &msg[msg_size - p_len];
    if(strncmp(s, PROTOCOL_EMWIN1_STR, p_len) == 0){
      p = PROTOCOL_EMWIN1;
      r = 0;
    }
  }

  if(r == 1){
    p_len = strlen(PROTOCOL_EMWIN2_STR);
    if(msg_size >= p_len){
      s = &msg[msg_size - p_len];
      if(strncmp(s, PROTOCOL_EMWIN2_STR, p_len) == 0){
	p = PROTOCOL_EMWIN2;
	r = 0;
      }
    }
  }

  status = set_client_protocol(ct, i, p);
  if(status != 0)
    r = -1;

  return(r);
}