⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wspprocm.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
                                    &SConnectCnfData->ServerSDUSize,
                                    &SConnectCnfData->ProtocolOptions,
                                    &SConnectCnfData->MethodMOR,
                                    &SConnectCnfData->PushMOR))
    return SDL_False;

  if (!wap_cvt_bytevector (&cvt_obj,
                           SConnectCnfData->HeadersLen,
                           (BYTE **)&SConnectCnfData->ServerHeaders))
    return SDL_False;

  /* Release PDU buffer given as in-parameter. */
  pdubuf_release (pdu);
  
  return SDL_True;
}

/*
 * Create a Disconnect PDU.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed.
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreateDisconnectPDU (SDL_Integer SessionID)
{
/*
 * A Disconnect PDU has the following content:
 *     UINT8    PDU type
 *     UintVar  Server Session ID
 */
  wap_cvt_t cvt_obj;
  UINT32    sid = (UINT32)SessionID;
  UINT8     pdu_type = DISCONNECT_PDU_TYPE;
  pdubuf   *pdu;
  UINT32    pdulen;        /* Calculated length of PDU */

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE_SIZE, NULL, 0);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &sid))
    return NULL;

  pdulen = cvt_obj.pos;

  /* Get new PDU buffer, of size PDUlen plus room for WTP headers */
  if ((pdu = pdubuf_new ((UINT16)(pdulen + WTP_MAX_HEADER_SIZE))) == NULL) {
    /* Error, no buffers available. */
    return NULL;
  }
  pdubuf_setLength (pdu, (UINT16)pdulen);

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE, pdubuf_getStart (pdu), pdulen);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &sid))
    return NULL;

  return pdu;
}

/*
 * Extract the fields from a Disconnect PDU.
 * Sets the session ID value, and then releases the PDU buffer.
 * In case of error, the PDU buffer is NOT released.
 * Returns FALSE on error, TRUE otherwise.
 */
extern SDL_Boolean
ExtractDisconnectPDU (pdubuf *pdu,
                      SDL_Natural *ServerSessionId)
{
/*
 * A Disconnect PDU has the following content:
 *     UINT8    PDU type (always 5)
 *     UintVar  Server Session ID
 */
  wap_cvt_t cvt_obj;
  UINT8     pdu_type;

  wap_cvt_init (&cvt_obj, WAP_CVT_DECODE,
                pdubuf_getStart (pdu), pdubuf_getLength (pdu));
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      (pdu_type != DISCONNECT_PDU_TYPE) ||
      !wap_cvt_uintvar (&cvt_obj, ServerSessionId))
    return SDL_False;

  /* Release PDU buffer given as in-parameter. */
  pdubuf_release (pdu);

  return SDL_True;
}

/*
 * Create a PDU for a Get or similar request.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed. Also deallocates the VOIDSTAR buffers that are
 * given as in-parameters (unless the routine returns NULL).
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreateMethodPDU (SMethodInvokeReqType *SMethodInvokeReqData)
{
/*
 * A Get PDU has the following content:
 *     UINT8    PDU Type
 *     UintVar  Length of URI
 *     Octets   URI
 *     Octets   Headers
 */
  wap_cvt_t cvt_obj;
  UINT8     pdu_type = SMethodInvokeReqData->Method;
  UINT32    urilen;
  UINT32    headlen;  /* Length of header */
  UINT32    pdulen;   /* Calculated length of PDU */
  pdubuf   *pdu;      /* PDU buffer */

  urilen = SMethodInvokeReqData->URILen;
  headlen = SMethodInvokeReqData->HeadersLen;

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE_SIZE, NULL, 0);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &urilen) ||
      !wap_cvt_bytevector (&cvt_obj, urilen, NULL) ||
      !wap_cvt_bytevector (&cvt_obj, headlen, NULL))
    return NULL;

  pdulen = cvt_obj.pos;

  /* Get new PDU buffer, of size PDUlen plus room for WTP headers. */
  if ((pdu = pdubuf_new ((UINT16)(pdulen + WTP_MAX_HEADER_SIZE))) == NULL) {
    /* Error, no buffers available. */
    return NULL;
  }
  pdubuf_setLength (pdu, (UINT16)pdulen);

  /* Place PDU type, URI length, Headers length, Request URI,
     Request headers, and Request body in the PDU */
  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE,
                pdubuf_getStart (pdu), pdubuf_getLength (pdu));
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &urilen) ||
      !wap_cvt_bytevector (&cvt_obj, urilen,
                           (BYTE **)&SMethodInvokeReqData->RequestURI) ||
      !wap_cvt_bytevector (&cvt_obj, headlen,
                           (BYTE **)&SMethodInvokeReqData->RequestHeaders))
    return NULL;

  /* Release buffers given as in-parameters. */
  DEALLOC (&SMethodInvokeReqData->RequestURI);
  DEALLOC (&SMethodInvokeReqData->RequestHeaders);
  DEALLOC (&SMethodInvokeReqData->RequestBody);

  return pdu;
}

/*
 * Create a PDU for a Post request.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed. Also deallocates the VOIDSTAR buffers that are
 * given as in-parameters (unless the routine returns NULL).
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreatePostPDU (SMethodInvokeReqType *SMethodInvokeReqData)
{
/*
 * A Post PDU has the following content:
 *     UINT8   PDU type (always 0x60)
 *     UintVar Length of URI
 *     UintVar Length of content type and headers fields combined
 *     Octets  URI
 *     Octets  Content type
 *     Octets  Headers
 *     Octets  Data
 */
  wap_cvt_t cvt_obj;
  pdubuf   *pdu;      /* PDU buffer */
  UINT8     pdu_type = POST_PDU_TYPE;
  UINT32    pdulen;   /* Calculated length of PDU */
  UINT32    urilen;
  UINT32    headlen;  /* Length of header */
  UINT32    bodylen;

  urilen = SMethodInvokeReqData->URILen;
  headlen = SMethodInvokeReqData->HeadersLen;
  bodylen = SMethodInvokeReqData->BodyLen;

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE_SIZE, NULL, 0);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &urilen) ||
      !wap_cvt_uintvar (&cvt_obj, &headlen) ||
      !wap_cvt_bytevector (&cvt_obj, urilen, NULL) ||
      !wap_cvt_bytevector (&cvt_obj, headlen, NULL) ||
      !wap_cvt_bytevector (&cvt_obj, bodylen, NULL))
    return NULL;
  pdulen = cvt_obj.pos;

  /* Get new PDU buffer, of size PDUlen plus romm for WTP headers. */
  if ((pdu = pdubuf_new ((UINT16)(pdulen + WTP_MAX_HEADER_SIZE))) == NULL) {
    /* Error, no buffers available. */
    return NULL;
  }
  pdubuf_setLength (pdu, (UINT16)pdulen);

  /* Place PDU type, URI length, Headers length, Request URI,
     Request headers, and Request body in the PDU */
  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE, pdubuf_getStart (pdu), pdulen);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &urilen) ||
      !wap_cvt_uintvar (&cvt_obj, &headlen) ||
      !wap_cvt_bytevector (&cvt_obj, urilen,
                           (BYTE **)&SMethodInvokeReqData->RequestURI) ||
      !wap_cvt_bytevector (&cvt_obj, headlen,
                           (BYTE **)&SMethodInvokeReqData->RequestHeaders) ||
      !wap_cvt_bytevector (&cvt_obj, bodylen,
                           (BYTE **)&SMethodInvokeReqData->RequestBody))
    return NULL;

  /* Release buffers given as in-parameters. */
  DEALLOC (&SMethodInvokeReqData->RequestURI);
  DEALLOC (&SMethodInvokeReqData->RequestHeaders);
  DEALLOC (&SMethodInvokeReqData->RequestBody);

  return pdu;
}

/*
 * Create a PDU for more Data.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed. Also deallocates the VOIDSTAR buffers that are
 * given as in-parameters (unless the routine returns NULL).
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreateMoreDataPDU (SMethodInvokeReqType *SMethodInvokeReqData)
{
/*
 * A MoreData PDU has the following content:
 *     Octets  Data
 */
  pdubuf *pdu;     /* PDU buffer */
  UINT32  datalen;

  datalen = SMethodInvokeReqData->BodyLen;

  /* Get new PDU buffer, of size datalen plus room for WTP headers. */
  if ((pdu = pdubuf_new ((UINT16)(datalen + WTP_MAX_HEADER_SIZE))) == NULL) {
    /* Error, no buffers available. */
    return NULL;
  }
  pdubuf_setLength (pdu, (UINT16)datalen);

  /* Place data in the PDU. */
  memcpy (pdubuf_getStart (pdu), SMethodInvokeReqData->RequestBody, datalen);

  /* Release buffers given as in-parameters. */
  DEALLOC (&SMethodInvokeReqData->RequestBody);

  return pdu;
}

/*
 * Create a PDU for a Suspend request.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed.
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreateSuspendPDU (SDL_Natural sessionId)
{
/*
 * A Suspend PDU has the following content:
 *     UINT8   PDU type
 *     UintVar Session ID
 */
  wap_cvt_t cvt_obj;
  UINT8     pdu_type = SUSPEND_PDU_TYPE;
  UINT32    pdulen;    /* Calculated length of PDU */
  pdubuf   *pdu;       /* PDU buffer */

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE_SIZE, NULL, 0);
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &sessionId))
    return NULL;

  pdulen = cvt_obj.pos;

  /* Get new PDU buffer, of size PDUlen plus room for WTP headers. */
  if ((pdu = pdubuf_new ((UINT16)(pdulen + WTP_MAX_HEADER_SIZE))) == NULL) {
    /* Error, no buffers available. */
    return NULL;
  }
  pdubuf_setLength (pdu, (UINT16)pdulen);

  /* Place PDU type and session Id in the PDU */
  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE,
                pdubuf_getStart (pdu), pdubuf_getLength (pdu));
  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      !wap_cvt_uintvar (&cvt_obj, &sessionId))
    return NULL;

  return pdu;
}

/*
 * Create a PDU for a Resume request.
 * Returns a pointer to a PDU buffer where the relevant data has
 * been placed. Also deallocates the VOIDSTAR buffers that are
 * given as in-parameters (unless the routine returns NULL).
 * Returns NULL in case of error.
 * NOTE: it is the caller's responsibility to deallocate the returned buffer.
 */
extern pdubuf *
CreateResumePDU (SDL_Natural sessionId, SResumeReqType *SResumeReqData)
{
/*
 * A Resume PDU has the following content:
 *     UINT8   PDU type
 *     UintVar Session ID
 *     UintVar Length of capabilities field (Currently always 0)
 *     Octets  Capabilities                 (Currently always empty)
 *     Octets  Headers
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -