Пример #1
0
/*
* Get private data connected to a specific save as operation. The private 
* data might be used by the module to indicate which sub module that has
* started the operation. This function may be called after 
* msf_sas_handle_signal returned MSF_PACKAGE_OPERATION_COMPLETE.
* If success returns the private data, otherwise returns MSF_PACKAGE_ERROR.
*/
void*
msf_sas_get_private_data (msf_pck_handle_t* handle, MSF_INT32 id)
{
    msf_sas_handle_t* sas_handle = (msf_sas_handle_t*)handle;
    msf_sas_op_t *op = find_op_by_id (sas_handle, id);
    if (!op)
        return NULL;
    return op->priv_data;
}
Пример #2
0
/*
* Set private data connected to a specific save as operation. The private 
* data might be used by the module to indicate which sub module that started 
* the save as operation. This function may be called after a
* msf_sas_create_xxx function has been called.
* Returns TRUE if success, otherwise FALSE.
*/
int
msf_sas_set_private_data (msf_pck_handle_t* handle, MSF_INT32 id, void* p)
{
    msf_sas_handle_t* sas_handle = (msf_sas_handle_t*)handle;
    msf_sas_op_t *op = find_op_by_id (sas_handle, id);
    if (!op)
        return FALSE;
    op->priv_data = p;
    return TRUE;
}
Пример #3
0
/*
* Deletes a created save as operation. Any private data is not released by 
* this function. The module call this function when the module of any
* reason must delete the operation before the finished state has been
* reached.
* Returns TRUE  if success, otherwise FALSE.
*/
int
msf_sas_delete (msf_pck_handle_t* handle, MSF_INT32 id)
{
    msf_sas_handle_t* sas_handle = (msf_sas_handle_t*)handle;
    msf_sas_op_t *op = find_op_by_id (sas_handle, id);

    if (!op)
        return FALSE;

    free_sas_op(sas_handle, op);
    return TRUE;
}
Пример #4
0
/**
 * Type of a function to call when we receive a message
 * from the service.
 *
 * @param cls closure
 * @param msg message received, NULL on timeout or fatal error
 */
static void
message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_PSYCSTORE_Handle *h = cls;
  struct GNUNET_PSYCSTORE_OperationHandle *op;
  const struct OperationResult *opres;
  const struct CountersResult *cres;
  const struct FragmentResult *fres;
  const struct StateResult *sres;
  const char *str;

  if (NULL == msg)
  {
    reschedule_connect (h);
    return;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Received message of type %d from PSYCstore service.\n",
       ntohs (msg->type));
  uint16_t size = ntohs (msg->size);
  uint16_t type = ntohs (msg->type);
  switch (type)
  {
  case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE:
    if (size < sizeof (struct OperationResult))
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received message of type %d with length %lu bytes. "
           "Expected >= %lu\n",
           type, size, sizeof (struct OperationResult));
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    opres = (const struct OperationResult *) msg;
    str = (const char *) &opres[1];
    if ( (size > sizeof (struct OperationResult)) &&
	 ('\0' != str[size - sizeof (struct OperationResult) - 1]) )
    {
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }
    if (size == sizeof (struct OperationResult))
      str = "";

    op = find_op_by_id (h, GNUNET_ntohll (opres->op_id));
    if (NULL == op)
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "No callback registered for operation with ID %" PRIu64 ".\n",
           type, GNUNET_ntohll (opres->op_id));
    }
    else
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "Received result message (type %d) with operation ID: %" PRIu64 "\n",
           type, op->op_id);

      int64_t result_code = GNUNET_ntohll (opres->result_code) + INT64_MIN;
      GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
      if (NULL != op->res_cb)
      {
        const struct StateSyncRequest *ssreq;
        switch (ntohs (op->msg->type))
        {
        case GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC:
          ssreq = (const struct StateSyncRequest *) op->msg;
          if (!(ssreq->flags & STATE_OP_LAST
                || GNUNET_OK != result_code))
            op->res_cb = NULL;
          break;
        }
      }
      if (NULL != op->res_cb)
        op->res_cb (op->cls, result_code, str, size - sizeof (*opres));
      GNUNET_free (op);
    }
    break;

  case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS:
    if (size != sizeof (struct CountersResult))
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received message of type %d with length %lu bytes. "
           "Expected %lu\n",
           type, size, sizeof (struct CountersResult));
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    cres = (const struct CountersResult *) msg;

    op = find_op_by_id (h, GNUNET_ntohll (cres->op_id));
    if (NULL == op)
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "No callback registered for operation with ID %" PRIu64 ".\n",
           type, GNUNET_ntohll (cres->op_id));
    }
    else
    {
      GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
      if (NULL != op->data_cb)
        ((GNUNET_PSYCSTORE_CountersCallback)
         op->data_cb) (op->cls,
                       ntohl (cres->result_code),
                       GNUNET_ntohll (cres->max_fragment_id),
                       GNUNET_ntohll (cres->max_message_id),
                       GNUNET_ntohll (cres->max_group_generation),
                       GNUNET_ntohll (cres->max_state_message_id));
      GNUNET_free (op);
    }
    break;

  case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT:
    if (size < sizeof (struct FragmentResult))
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received message of type %d with length %lu bytes. "
           "Expected >= %lu\n",
           type, size, sizeof (struct FragmentResult));
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    fres = (const struct FragmentResult *) msg;
    struct GNUNET_MULTICAST_MessageHeader *mmsg =
      (struct GNUNET_MULTICAST_MessageHeader *) &fres[1];
    if (size != sizeof (struct FragmentResult) + ntohs (mmsg->header.size))
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received message of type %d with length %lu bytes. "
           "Expected = %lu\n",
           type, size,
           sizeof (struct FragmentResult) + ntohs (mmsg->header.size));
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    op = find_op_by_id (h, GNUNET_ntohll (fres->op_id));
    if (NULL == op)
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "No callback registered for operation with ID %" PRIu64 ".\n",
           type, GNUNET_ntohll (fres->op_id));
    }
    else
    {
      if (NULL != op->data_cb)
        ((GNUNET_PSYCSTORE_FragmentCallback)
         op->data_cb) (op->cls, mmsg, ntohl (fres->psycstore_flags));
    }
    break;

  case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE:
    if (size < sizeof (struct StateResult))
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received message of type %d with length %lu bytes. "
           "Expected >= %lu\n",
           type, size, sizeof (struct StateResult));
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    sres = (const struct StateResult *) msg;
    const char *name = (const char *) &sres[1];
    uint16_t name_size = ntohs (sres->name_size);

    if (name_size <= 2 || '\0' != name[name_size - 1])
    {
      LOG (GNUNET_ERROR_TYPE_ERROR,
           "Received state result message (type %d) with invalid name.\n",
           type);
      GNUNET_break (0);
      reschedule_connect (h);
      return;
    }

    op = find_op_by_id (h, GNUNET_ntohll (sres->op_id));
    if (NULL == op)
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "No callback registered for operation with ID %" PRIu64 ".\n",
           type, GNUNET_ntohll (sres->op_id));
    }
    else
    {
      if (NULL != op->data_cb)
        ((GNUNET_PSYCSTORE_StateCallback)
         op->data_cb) (op->cls, name, (char *) &sres[1] + name_size,
                       ntohs (sres->header.size) - sizeof (*sres) - name_size);
    }
    break;

  default:
    GNUNET_break (0);
    reschedule_connect (h);
    return;
  }

  GNUNET_CLIENT_receive (h->client, &message_handler, h,
                         GNUNET_TIME_UNIT_FOREVER_REL);
}
Пример #5
0
int
msf_sas_get_result (msf_pck_handle_t  *handle,
                    MSF_INT32          id,
                    msf_pck_result_t  *result)
{
    msf_sas_handle_t          *sas_handle = (msf_sas_handle_t*)handle;
    msf_sas_op_t              *op;
    msf_sas_result_save_as_t  *res;

    if (!handle)
        return FALSE;

    op = find_op_by_id (sas_handle, id);
    if (op == NULL)
        return FALSE;

    result->type = MSF_SAS_TYPE;
    res = result->_u.data = MSF_MEM_ALLOCTYPE (sas_handle->modid, msf_sas_result_save_as_t);
    res->file_name = NULL;
    res->fn_posix  = NULL;
    res->result = op->status;

    if (op->status != MSF_SAS_RETURN_NOT_AVAILABLE)
    {
        if(op->file_handle)
            FS_Close(op->file_handle);
        
        if(op->pipe_handle)
        {
            MSF_PIPE_CLOSE(op->pipe_handle);
        }
        
        if (op->data_type == MSF_PCK_DATA_TYPE_PIPE)
        {
            MSF_PIPE_DELETE(op->pathname);
        }

        if (op->status != MSF_SAS_RETURN_OK)
        {
            if (op->file_name)
                FS_Delete((const WCHAR *)op->file_name);

            if (op->status == MSF_SAS_RETURN_CANCELLED)
            {
                HDIa_widgetExtShowPopup(sas_handle->modid, 
                    MSF_WIDGET_STRING_GET_PREDEFINED(BRA_STR_ID_SAS_OPERATION_CANCELED), 
                    MsfInfo,
                    0);
            }
        }
        else
        {
            extern kal_uint8 wap_status;
            extern char contentUrl[256];

            if (wap_status != WAP_RUNNING)
            {
                /* Obigo will return MSF_SAS_RETURN_OK when shutdown mobile suite, 
                * but the file might be truncated.
                */
                FS_Delete((const WCHAR *)op->file_name);
            }
            else
            {
                msf_sas_send_dl_ind(sas_handle->modid, op->data_type, contentUrl, op->mime_type, (const kal_uint8 *)op->file_name);
                res->file_name = msf_cmmn_strdup (sas_handle->modid, op->file_name);
                res->fn_posix = msf_cmmn_strdup (sas_handle->modid, op->dst_posix);
            }
        }
        free_sas_op(sas_handle, op);
    }
    return TRUE;
}