Пример #1
0
static void
data_cb(
    globus_xio_handle_t                         handle,
    globus_result_t                             result,
    globus_byte_t *                             buffer,
    globus_size_t                               len,
    globus_size_t                               nbytes,
    globus_xio_data_descriptor_t                data_desc,
    void *                                      user_arg)
{
    globus_result_t                             res;
    char *                                      timeout_type;

    timeout_type = (char *) user_arg;
    if(strcmp(timeout_type, "D") == 0)
    {
        if(!result_is_timeout(result) && globus_l_timeout)
        {
            failed_exit("Read/Write did not timeout.");
        }
    }

    globus_mutex_lock(&globus_l_mutex);
    {
        res = globus_xio_register_close(
                handle,
                NULL,
                close_cb,
                user_arg);
        test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
    }
    globus_mutex_unlock(&globus_l_mutex);
}
Пример #2
0
static void
data_cb(
    globus_xio_handle_t                     handle,
    globus_result_t                         result,
    globus_byte_t *                         buffer,
    globus_size_t                           len,
    globus_size_t                           nbytes,
    globus_xio_data_descriptor_t            data_desc,
    void *                                  user_arg)
{
    globus_result_t                         res;

    globus_mutex_lock(&globus_l_mutex);
    {
        res = globus_xio_register_close(
                handle,
                NULL,
                close_cb,
                user_arg);
        if(globus_l_close_called)
        {
            if(res == GLOBUS_SUCCESS)
            {
                failed_exit("close should have failed the second time.\n");
            }
        }
        else
        {
            test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
        }
        globus_l_close_called = GLOBUS_TRUE;
    }
    globus_mutex_unlock(&globus_l_mutex);
}
Пример #3
0
static
void
gfork_l_child_error(
    gfork_i_lib_handle_t *              handle,
    globus_result_t                     in_result)
{
    globus_result_t                     result;

    switch(handle->state)
    {
    /* we are already doing it */
    case GFORK_STATE_CLOSING:
        break;

    case GFORK_STATE_OPEN:
        handle->error_obj = globus_error_get(in_result);
        result = globus_xio_register_close(
                     handle->write_xio, NULL,
                     gfork_l_child_write_close_cb, handle);
        if(result != GLOBUS_SUCCESS)
        {
            /* wtf ? */
        }
        handle->state = GFORK_STATE_CLOSING;

        break;

    default:
        globus_assert(0 && "Invalid state");
    }
}
Пример #4
0
static
void
gfs_l_xio_close_write_handles(
    gfs_i_xio_cp_handle_t *             cp_h)
{
    globus_xio_handle_t                 xio_h;

    while(!globus_fifo_empty(cp_h->write_all_q))
    {
        xio_h = (globus_xio_handle_t)
            globus_fifo_dequeue(cp_h->write_all_q);

        result = globus_xio_register_close(
            xio_h,
            NULL,
            gfs_l_xio_cp_write_close_cb,
            cp_h);
        if(result != GLOBUS_SUCCESS)
        {
            cp_h->write_handle_count--;
        }
    }

    if(cp_h->write_handle_count == 0)
    {
        globus_callback_register_oneshot(
            NULL,
            NULL,
            gfs_l_xio_cp_close_os,
            cp_h);
    }
}
Пример #5
0
static void
open_cb(
    globus_xio_handle_t                         handle,
    globus_result_t                             result,
    void *                                      user_arg)
{
    globus_result_t                             res;
    int                                         ctr;
    test_info_t *                               info;
    globus_bool_t                               data = GLOBUS_FALSE;

    info = (test_info_t *) user_arg;

    test_res(GLOBUS_XIO_TEST_FAIL_FINISH_OPEN, result, __LINE__, __FILE__);

    globus_mutex_lock(&info->mutex);
    {
        for(ctr = 0; ctr < info->write_count; ctr++)
        {
            res = globus_xio_register_write(
                      handle,
                      info->buffer,
                      info->buffer_length,
                      info->buffer_length,
                      NULL,
                      write_cb,
                      user_arg);
            test_res(GLOBUS_XIO_TEST_FAIL_PASS_WRITE, res, __LINE__, __FILE__);
            data = GLOBUS_TRUE;
        }

        for(ctr = 0; ctr < info->read_count; ctr++)
        {
            res = globus_xio_register_read(
                      handle,
                      info->buffer,
                      info->buffer_length,
                      info->buffer_length,
                      NULL,
                      read_cb,
                      user_arg);
            test_res(GLOBUS_XIO_TEST_FAIL_PASS_READ, res, __LINE__, __FILE__);
            data = GLOBUS_TRUE;
        }

        if(!data)
        {
            res = globus_xio_register_close(
                      handle,
                      NULL,
                      close_cb,
                      user_arg);
            test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
        }
    }
    globus_mutex_unlock(&info->mutex);
}
Пример #6
0
void mdsip_test_result(globus_xio_handle_t xio_handle,globus_result_t res,mdsip_client_t *ctx,char *msg)
{
  if(res != GLOBUS_SUCCESS)
  {
    fprintf(stderr, "ERROR:%s ---\n       %s\n", 
	    msg,globus_object_printable_to_string(globus_error_get(res)));
    if (xio_handle != NULL)
      globus_xio_register_close(xio_handle,NULL,mdsip_close_cb,ctx);
  }

}
Пример #7
0
static
void
gfork_l_child_write_close_cb(
    globus_xio_handle_t                 xio_handle,
    globus_result_t                     result,
    void *                              user_arg)
{
    gfork_i_lib_handle_t *            handle;

    handle = (gfork_i_lib_handle_t *) user_arg;

    result = globus_xio_register_close(
                 handle->read_xio, NULL,
                 gfork_l_child_read_close_cb, handle);
    if(result != GLOBUS_SUCCESS)
    {
        gfork_l_child_read_close_cb(handle->read_xio, GLOBUS_SUCCESS, handle);
    }

}
Пример #8
0
/*
 * called locked
 */
static
void
gfs_l_xio_cp_error(
    gfs_i_xio_cp_handle_t *             cp_h,
    globus_result_t                     result)
{
    globus_xio_handle_t                 xio_h;

    /* call this for shutdown in error cases, but some error cases will
        be a result of closing. */
    if(cp_h->state != GFS_CIO_CP_STATE_OPEN)
    {
        return;
    }

    cp_h->state = GFS_CIO_CP_STATE_ERROR;
    cp_h->err_obj = globus_error_get(result);

    while(!globus_fifo_empty(cp_h->read_all_q))
    {
        xio_h = (globus_xio_handle_t) globus_fifo_dequeue(cp_h->read_all_q);

        result = globus_xio_register_close(
            xio_h,
            NULL,
            gfs_l_xio_cp_read_close_cb,
            cp_h);
        if(result != GLOBUS_SUCCESS)
        {
            cp_h->read_handle_count--;
        }
    }

    if(cp_h->read_handle_count <= 0)
    {
        gfs_l_xio_close_write_handles(cp_h);
    }
}
Пример #9
0
static void
read_cb(
    globus_xio_handle_t                         handle,
    globus_result_t                             result,
    globus_byte_t *                             buffer,
    globus_size_t                               len,
    globus_size_t                               nbytes,
    globus_xio_data_descriptor_t                data_desc,
    void *                                      user_arg)
{
    test_info_t *                               info;
    globus_result_t                             res;

    if(!globus_xio_error_is_eof(result) &&
            !globus_xio_error_is_canceled(result))
    {
        test_res(GLOBUS_XIO_TEST_FAIL_FINISH_READ, result, __LINE__, __FILE__);
    }

    info = (test_info_t *) user_arg;

    globus_mutex_lock(&info->mutex);
    {
        if(len < nbytes)
        {
            failed_exit("read wait for has failed");
        }
        else if(nbytes > len)
        {
            failed_exit("too many bytes were read.");
        }

        info->nread += nbytes;

        if(info->nread >= info->total_read_bytes && !info->read_done)
        {
            info->closed++;
            info->read_done = GLOBUS_TRUE;
            if(info->closed == 2 || info->write_count == 0)
            {
                res = globus_xio_register_close(
                          handle,
                          NULL,
                          close_cb,
                          user_arg);
                test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
            }
        }
        else if(!info->read_done)
        {
            res = globus_xio_register_read(
                      handle,
                      info->buffer,
                      info->buffer_length,
                      info->buffer_length,
                      NULL,
                      read_cb,
                      user_arg);
            test_res(GLOBUS_XIO_TEST_FAIL_PASS_READ, res, __LINE__, __FILE__);
        }
    }
    globus_mutex_unlock(&info->mutex);
}
Пример #10
0
void mdsip_authenticate_cb(
		globus_xio_handle_t xio_handle, 
		globus_result_t result,
                globus_byte_t *buffer,
		globus_size_t len,
		globus_size_t nbytes,
		globus_xio_data_descriptor_t data_desc,
		void *user_arg)
{
  mdsip_client_t *ctx = (mdsip_client_t *)user_arg;
  char *remote_user = strncpy(malloc(nbytes+1),buffer,nbytes);
  remote_user[nbytes]=0;

  mdsip_test_result(xio_handle,result,ctx,"mdsip_authenticate_cb");
  if (result == GLOBUS_SUCCESS)
  {
    int status;
    globus_result_t res;
    short dummy;
    mdsip_message_t *reply = (mdsip_message_t *)memset(malloc(sizeof(mdsip_message_t)),0,sizeof(mdsip_message_t));
    char *contact;
    res = globus_xio_handle_cntl(xio_handle, 
				 (globus_xio_driver_t)ctx->options->tcp_driver, 
				 GLOBUS_XIO_TCP_GET_REMOTE_CONTACT, 
				 &contact);
    mdsip_test_result(xio_handle,res,ctx,"mdsip_authenticate_cb,GET_REMOTE_CONTACT");
    ctx->host = strcpy(malloc(strlen(contact)+1),contact);
    ctx->host[strcspn(ctx->host,":")]=0;
    res = globus_xio_handle_cntl(xio_handle, 
				 (globus_xio_driver_t)ctx->options->tcp_driver, 
				 GLOBUS_XIO_TCP_GET_REMOTE_NUMERIC_CONTACT, 
				 &contact);
    mdsip_test_result(xio_handle,res,ctx,"mdsip_authenticate_cb,GETREMOTE_NUMERIC_CONTACT");
    ctx->ipaddr = strcpy(malloc(strlen(contact)+1),contact);
    ctx->ipaddr[strcspn(ctx->ipaddr,":")]=0;
    mdsip_host_to_ipaddr(ctx->host,&ctx->addr,&dummy);
    if (ctx->options->security_level > 0)
    {
      gss_buffer_desc                         buffer_desc = GSS_C_EMPTY_BUFFER;
      gss_buffer_t                            buffer = &buffer_desc;
      OM_uint32                               status;
      globus_xio_driver_t driver = (globus_xio_driver_t)ctx->options->gsi_driver;
      globus_result_t res;
      gss_name_t name;
      res = globus_xio_handle_cntl((globus_xio_handle_t)xio_handle, 
				   driver, 
				   GLOBUS_XIO_GSI_GET_PEER_NAME, 
				   &name);
      gss_export_name(&status, name, buffer);
      ctx->remote_user=strcpy(malloc(strlen((char *)buffer->value)+1),(char *)buffer->value);
    }
    else
    {
      ctx->remote_user=remote_user;
    }
    status = mdsip_find_user_mapping(ctx->options->hostfile, ctx->ipaddr,ctx->host,ctx->remote_user,&ctx->local_user);
    if (status & 1 && ctx->options->port_name == 0)
      status = mdsip_become_user(ctx->local_user,ctx->remote_user);
    reply->h.msglen = sizeof(mdsip_message_header_t);
    reply->h.status = status;
    if (status & 1)
    {
      if (ctx->options->security_level > 0)
      {
        fprintf(stdout,"%s, CONNECT - %s/%s@%s(%s)\n",mdsip_current_time(),ctx->remote_user,remote_user,ctx->host,ctx->ipaddr);
        free(remote_user);
      }
      else
        fprintf(stdout,"%s, CONNECT - %s@%s(%s)\n",mdsip_current_time(),ctx->remote_user,ctx->host,ctx->ipaddr);
    }
    else
    {
      fprintf(stdout,"%s, REJECT - %s@%s(%s)\n",mdsip_current_time(),ctx->remote_user,ctx->host,ctx->ipaddr);
    }
    free(ctx->message);
    mdsip_write((void *)xio_handle,ctx,reply,0);
    if (status & 1)
    {
      ctx->mdsip_read_cb = mdsip_do_message_cb;
      res = globus_xio_register_read(xio_handle,(globus_byte_t *)&ctx->header, sizeof(mdsip_message_header_t), sizeof(mdsip_message_header_t),
			       NULL,mdsip_read_header_cb,ctx);
      mdsip_test_result(xio_handle,res,ctx,"mdsip_authenticate_cb,globus_xio_register_read");
    }
    else
      globus_xio_register_close(xio_handle,NULL,mdsip_close_cb,ctx);
  }
  return;
}
Пример #11
0
static
void
state_machine(
    void *                              user_arg)
{
    globus_reltime_t                    delay;
    globus_result_t                     result;
    globus_l_timeout_info_t *           info = user_arg;

    /* If the timeout is to be caused by this side of the transfer, then check
     * current state, and if it's the timeout state, then we'll clear the
     * cause_timeout flag and then reregister this oneshot with the delay of
     * (timeout * 5) and continue the state machine.
     */

    globus_mutex_lock(&lock);
    if (info->cause_timeout && info->timeout_state == info->state)
    {
        /* register oneshot at (timeout * 5) */
        GlobusTimeReltimeSet(delay,
                0,
                (info->timeout * 5 * 1000));

        info->cause_timeout = GLOBUS_FALSE;
        info->state = GLOBUS_XIO_OPERATION_TYPE_CLOSE;

        globus_callback_register_oneshot(
                NULL,
                &delay,
                state_machine,
                info);
        globus_mutex_unlock(&lock);
        return;
    }

    /* process current state */
    switch (info->state)
    {
        case GLOBUS_XIO_OPERATION_TYPE_ACCEPT:
            globus_assert(info->server);
            result = globus_xio_server_register_accept(
                    info->server,
                    accept_callback,
                    info);
            break;

        case GLOBUS_XIO_OPERATION_TYPE_OPEN:
            result = globus_xio_register_open(
                    info->handle,
                    info->contact,
                    info->attr,
                    open_close_callback,
                    info);
            break;

        case GLOBUS_XIO_OPERATION_TYPE_READ:
            result = globus_xio_register_read(
                    info->handle,
                    info->buffer,
                    sizeof(info->buffer),
                    1,
                    NULL,
                    data_callback,
                    info);
            break;

        case GLOBUS_XIO_OPERATION_TYPE_WRITE:
            strcpy((char *) info->buffer, "ok\n");

            result = globus_xio_register_write(
                    info->handle,
                    info->buffer,
                    strlen((char *) info->buffer),
                    strlen((char *) info->buffer),
                    NULL,
                    data_callback,
                    info);
            break;

        case GLOBUS_XIO_OPERATION_TYPE_CLOSE:
            result = globus_xio_register_close(
                    info->handle,
                    NULL,
                    open_close_callback,
                    info);
            break;

        case GLOBUS_XIO_OPERATION_TYPE_FINISHED:
            globus_cond_signal(&cond);
            info->state = GLOBUS_XIO_OPERATION_TYPE_NONE;
            break;

        case GLOBUS_XIO_OPERATION_TYPE_NONE:
        case GLOBUS_XIO_OPERATION_TYPE_DRIVER:
        case GLOBUS_XIO_OPERATION_TYPE_DD:
        case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT:
            fprintf(stderr,
                    "Error: unexpected state: %d\n",
                    info->state);
            info->result = GLOBUS_FAILURE;
            info->state = GLOBUS_XIO_OPERATION_TYPE_NONE;
            globus_cond_signal(&cond);
            break;
    }
    globus_mutex_unlock(&lock);
}
Пример #12
0
static void
open_cb(
    globus_xio_handle_t                         handle,
    globus_result_t                             result,
    void *                                      user_arg)
{
    globus_result_t                             res;
    globus_byte_t *                             buffer;
    globus_size_t                               buffer_length;
    char *                                      timeout_type;

    buffer = globus_l_test_info.buffer;
    buffer_length = globus_l_test_info.buffer_length;

    timeout_type = (char *) user_arg;
    globus_mutex_lock(&globus_l_mutex);
    {
        if(strcmp(timeout_type, "O") == 0)
        {
            if(!result_is_timeout(result) && globus_l_timeout)
            {
                failed_exit("Open did not timeout.");
            }
            else if(result == GLOBUS_SUCCESS)
            {
                res = globus_xio_register_close(
                        handle,
                        NULL,
                        close_cb,
                        user_arg);
                test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
            }
            else
            {
                globus_l_closed = GLOBUS_TRUE;
                globus_cond_signal(&globus_l_cond);
            }
        }
        else
        {
            if(globus_l_test_info.write_count > 0)
            {
                res = globus_xio_register_write(
                        handle,
                        buffer,
                        buffer_length,
                        buffer_length,
                        NULL,
                        data_cb,
                        user_arg);
            }
            else
            {
                res = globus_xio_register_read(
                        handle,
                        buffer,
                        buffer_length,
                        buffer_length,
                        NULL,
                        data_cb,
                        user_arg);
            }
            test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__);
        }
    }
    globus_mutex_unlock(&globus_l_mutex);
}
Пример #13
0
static
void
gfs_l_xio_cp_read_cb(
    globus_xio_handle_t                 handle,
    globus_result_t                     result,
    globus_byte_t *                     buffer,
    globus_size_t                       len,
    globus_size_t                       nbytes,
    globus_xio_data_descriptor_t        data_desc,
    void *                              user_arg)
{
    gfs_l_xio_read_buffer_t *           read_buf;
    gfs_i_xio_cp_handle_t *             cp_h;

    read_buf = (gfs_l_xio_read_buffer_t *) user_arg;
    cp_h = read_buf->whos_my_daddy;

    globus_mutex_lock(&cp_h->mutex);
    {
        read_buf->nbytes = nbytes;
        if(result != GLOBUS_SUCCESS)
        {
            if(eof)
            {
                read_buf->eof = GLOBUS_TRUE;
            }
            else
            {
                /* what if this is just EOF */
                goto error;
            }
        }
        /* it is possible to get here in the CLOSING state without an error */
        if(cp_h->state == GFS_CIO_CP_STATE_ERROR)
        {
            goto error;
        }

        /* XXX need to get an offset for this buffer */
        read_buf->nbytes = nbytes;
        result = globus_xio_data_descriptor_cntl(
            data_desc,
            NULL,
            GLOBUS_XIO_DD_GET_OFFSET,
            &offset);
        if(result != GLOBUS_SUCCESS)
        {
            goto error;
        }
        read_buf->offset = offset;

        if(!globus_fifo_empty(cp_h->write_q))
        {
            read_buf->write_xio = 
                (globus_xio_handle_t) globus_fifo_dequeue(cp_h->write_q);
            result = globus_xio_handle_cntl(
                read_buf->write_xio,
                GLOBUS_XIO_QUERY,
                GLOBUS_XIO_SEEK,
                read_buf->offset);
            if(result != GLOBUS_SUCCESS)
            {
                goto error;
            }

            result = globus_xio_register_write(
                read_buf->write_xio,
                read_buf->buffer,
                read_buf->nbytes,
                read_buf->nbytes,
                NULL,
                gfs_l_xio_cp_write_cb,
                read_buf);
            if(result != GLOBUS_SUCCESS)
            {
                goto error;
            }
        }
        else
        {
            /* stick this one in the queue */
            globus_fifo_enqueue(&cp_h->read_buffer_q, read_buf);
        }

        if(!eof)
        {
            /* make and post a new one */
            read_buf = (gfs_l_xio_read_buffer_t *)
                globus_calloc(sizeof(gfs_l_xio_read_buffer_t)+block_size, 1);
            read_buf->block_size = cp_h->block_size;
            read_buf->whos_my_daddy = cp_h;
            /* do this last since it can inspire the CLOSING state */
            gfs_l_xio_cp_post_read(xio_h, read_buf);
        }
        else
        {
            /* remove it from close q and close */
            globus_fifo_remove(cp_h->read_all_q, read_buf->read_xio);
            result = globus_xio_register_close(
                read_buf->read_xio,
                NULL,
                gfs_l_xio_cp_close_cb,
                cp_h);
            if(result != GLOBUS_SUCCESS)
            {
                cp_h->read_handle_count--;
            }
            if(cp_h->read_handle_count <= 0)
            {
                gfs_l_xio_close_write_handles(cp_h);
            }
        }
    }
    globus_mutex_unlock(&cp_h->mutex);

    return;

error:
    globus_free(read_buf);
    gfs_l_xio_cp_error(cp_h, result);
    globus_mutex_unlock(&cp_h->mutex);
}