Esempio n. 1
0
static void
frame_number_add_add_clicked(struct MessageNewViewData *data, Evas_Object * obj,
			     void *event_info)
{
	char *number = strdup(elm_entry_entry_get(data->entry));
	string_strip_html(number);

	if (string_is_number(number)) {
		GHashTable *properties =
			g_hash_table_new(g_str_hash, g_str_equal);
		char *name = phonegui_contact_cache_lookup(number);
		if (!name || !*name)
			name = "Number";
		g_hash_table_insert(properties, strdup("name"), strdup(name));
		g_hash_table_insert(properties, strdup("number"),
				    strdup(number));
		g_ptr_array_add(data->recipients, properties);

		data->mode = MODE_RECIPIENT;
		window_frame_show(data->win, data, frame_recipient_show,
				  frame_recipient_hide);
	}

	free(number);
}
Esempio n. 2
0
static void parse_args(const int argc, char** argv) {
    int i;

    for (i = 0; i < argc; ++i) {
        const char* argument = argv[i];

        if (*argument != '-') {
            if (string_is_number(argument)) {
                if (!board_width) {
                    board_width = atoi(argument);
                }
                else if (!board_height) {
                    board_height = atoi(argument);
                } else {
                    assert(0);
                }
            }
            else if (!tsumego_name) {
                tsumego_name = argument;
            } else {
                assert(0);
            }
            continue;
        }
        else if (argument[1] == 'k') {
            ko_threats = atoi(argument + 2);
        }
        else if (argument[1] == 'l') {
            num_layers = atoi(argument + 2);
        } else {
            assert(0);
        }
    }
    if (board_width) {
        assert(board_height);
        assert(!tsumego_name);
    }
    else if (!tsumego_name) {
        assert(0);
    }
}
Esempio n. 3
0
int rtobject_search_data_ports(const rtobject_t* rtobj,\
			     const char *search_pattern,\
			     int search_type, ll_head* results){
  int ret, state;
  int *curr_int;

  /*sanity check*/
  if (*results){
    printf("search data_ports error: result list not intially empty\n");
    return -1;
  }

  /*check if search pattern is just a data_port index*/
  if (string_is_number(search_pattern) != 0){
    
    /*validate data_port index*/
    if (!(rtobject_get_data_port(rtobj, atoi(search_pattern)))){
      return -1;
    }

    /*allocate an integer*/
    if (!(curr_int = (int*)malloc(sizeof(int)))){
      return -1;
    }

    *curr_int = atoi(search_pattern);

    /*append integer to result list*/
    if (!(ll_append(results, (void*)curr_int))){
      free(curr_int);
      return -1;
    }
     
    return 1;
  }

  /*search data_port names, appending matching indexes to result list*/
  state = 0;
  while ((ret = ns_search_pos(rtobj->data_port_ns, search_pattern,\
			      state, search_type)) >= 0){

    /*allocate an integer*/
    if (!(curr_int = (int*)malloc(sizeof(int)))){
      ll_free_all(results);
      return -1;
    }

    *curr_int = ret;

    /*append integer to result list*/
    if (!(ll_append(results, (void*)curr_int))){
      ll_free_all(results);
      free(curr_int);
      return -1;
    }
    
    ++state;
  }

  return ll_get_size(results);
}
Esempio n. 4
0
int http_resp_read_body(http_resp *a_resp, http_req *a_req, http_trans_conn *a_conn)
{
	int      l_return = 0;
	char    *l_content_length = NULL;
	char    *l_transfer_encoding = NULL;
	char    *l_connection = NULL;

	if ((!a_resp) || (!a_conn))
		return -1;
	a_conn->io_buf_flush_en = 1;
	ghttpDebug("a_req->type: %d \n", a_req->type);
	/* check to see if we have to jump in anywhere. */
	if (a_conn->sync == HTTP_TRANS_ASYNC)
	{
		ghttpDebug("body_state: %d \n", a_resp->body_state);
		if (a_resp->body_state == http_resp_body_read_content_length)
			goto http_resp_body_read_content_length_jump;
		if (a_resp->body_state == http_resp_body_read_chunked)
			goto http_resp_body_read_chunked_jump;
		if (a_resp->body_state == http_resp_body_read_standard)
			goto http_resp_body_read_standard_jump;
	}
	
	/* check to see if there should be an entity body. */
	/* check to see if there's a content length */
	l_content_length =
	    http_hdr_get_value(a_resp->headers,
	                       http_hdr_Content_Length);
	/* check to see if there's a transfer encoding */
	l_transfer_encoding =
	    http_hdr_get_value(a_resp->headers,
	                       http_hdr_Transfer_Encoding);
	/* check to see if the connection header is set */
	l_connection =
	    http_hdr_get_value(a_resp->headers,
	                       http_hdr_Connection);
	ghttpDebug("content_length: %s \n", l_content_length ? l_content_length : "null");
	ghttpDebug("transfer_encoding: %s \n", l_transfer_encoding ? l_transfer_encoding : "null");
	ghttpDebug("connection: %s \n", l_connection ? l_connection : "null");
	/* if there's a content length, do your stuff */
	if (l_content_length && (a_req->type != http_req_type_head))
	{
		if (string_is_number(l_content_length) == 0)
		{
			a_conn->errstr = "Content length in http response was not a number";
			return -1;
		}
		a_resp->content_length = atoi(l_content_length);
		/* set the state */
		a_resp->body_state = http_resp_body_read_content_length;
http_resp_body_read_content_length_jump:
		ghttpDebug("read_body_content_length ... \n");
		l_return = read_body_content_length(a_resp, a_req, a_conn);
	}
	else if (l_content_length)
	{
		/* this happens in a head request with content length. */
		return HTTP_TRANS_DONE;
	}
	else if (l_transfer_encoding)
	{
		/* check to see if it's using chunked transfer encoding */
		if (!strcasecmp(l_transfer_encoding, "chunked"))
		{
			/* set the state */
			a_resp->body_state = http_resp_body_read_chunked;
http_resp_body_read_chunked_jump:
			ghttpDebug("read_body_chunked ... \n");
			l_return = read_body_chunked(a_resp, a_req, a_conn);
			ghttpDebug("l_return: %d \n", l_return);
		}
		else
		{
			/* what kind of encoding? */
			a_conn->errstr = "Unknown encoding type in http response";
			return -1;
		}
	}
	else
	{
		a_resp->body_state = http_resp_body_read_standard;
		/* set the state */
http_resp_body_read_standard_jump:
		ghttpDebug("read_body_standard ... \n");
		l_return = read_body_standard(a_resp, a_req, a_conn);
		/* after that the connection gets closed */
		if (l_return == HTTP_TRANS_DONE)
		{	
			ghttpDebug("close connection \n");
			close(a_conn->sock);
			a_conn->sock = -1;
		}
	}
	/* check to see if the connection should be closed */
	if (l_connection && (l_return != HTTP_TRANS_NOT_DONE))
	{
		if (!strcasecmp(l_connection, "close"))
		{
			ghttpDebug("close connection \n");
			close (a_conn->sock);
			a_conn->sock = -1;
		}
	}
	if (l_return == HTTP_TRANS_DONE)
		a_resp->body_state = http_resp_body_start;
	return l_return;
}