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

📄 wspprocm.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
  wap_cvt_t cvt_obj;
  UINT8     pdu_type = RESUME_PDU_TYPE;
  UINT32    caplen = 0;
  UINT32    headlen;
  UINT32    pdulen;        /* Calculated length of PDU */
  pdubuf   *pdu;           /* PDU buffer */

  /* caplen = SResumeReqData->CapabilitiesLen; */
  headlen = SResumeReqData->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, &sessionId) ||
      !wap_cvt_uintvar (&cvt_obj, &caplen) ||
      !wap_cvt_bytevector (&cvt_obj, caplen, 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, session Id, capabilites length, capabilites and
   * headers 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) ||
      !wap_cvt_uintvar (&cvt_obj, &caplen) ||
      !wap_cvt_bytevector (&cvt_obj, caplen, NULL) ||
      /* !wap_cvt_bytevector (&cvt_obj, caplen,
         &SResumeReqData->RequestedCapabilities) || */
      !wap_cvt_bytevector (&cvt_obj, headlen,
                           (BYTE **)&SResumeReqData->ClientHeaders))
    return NULL;


  /* Release buffers given as in-parameters. */
  /* DEALLOC (&SResumeReqData->RequestedCapabilities); */
  DEALLOC (&SResumeReqData->ClientHeaders);

  return pdu;
}


/*
 * Extract the fields from a redirect PDU.
 * Sets a reason code, a redirect security indication,
 * and places the redirect addresses in a newly allocated buffer,
 * and finally releases the PDU buffer.
 * Returns FALSE in case of error, in which case the PDU buffer
 * is NOT released.
 * NOTE: it is the caller's responsibility to deallocate the VOIDSTAR buffer
 * (unless the routine returns FALSE).
 */
extern SDL_Boolean
ExtractRedirectPDU (pdubuf *pdu, SDL_Octet *ReasonCode,
                    SDL_Boolean *RedirectSecurity,
                    VOIDSTAR *RedirectedAddresses,
                    SDL_Natural *AddressLen)
{
/*
 * A Redirect PDU has the following content:
 *     UINT8     PDU type
 *     UINT8     Flags
 *     Octets    Redirect addresses
 */
  wap_cvt_t cvt_obj;
  UINT8     pdu_type;
  UINT8     flags;

  wap_cvt_init (&cvt_obj, WAP_CVT_DECODE,
                pdubuf_getStart (pdu), pdubuf_getLength (pdu));

  if (!wap_cvt_uint8 (&cvt_obj, &pdu_type) ||
      (pdu_type != REDIRECT_PDU_TYPE) ||
      !wap_cvt_uint8 (&cvt_obj, &flags))
    return SDL_False;

  *ReasonCode = (flags & REDIRECT_FLAGS_PERMANENT) ? 0x31 : 0x32;
  *RedirectSecurity =
    (flags & REDIRECT_FLAGS_REUSE_SEC) ? SDL_True : SDL_False;

  *AddressLen = cvt_obj.length - cvt_obj.pos;
  if (!wap_cvt_bytevector (&cvt_obj, *AddressLen,
                           (BYTE **)RedirectedAddresses))
    return SDL_False;

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

  return SDL_True;
}

typedef struct {
  UINT8  id;
  union {
    UINT32 value32;
    UINT8  value8;
  } _u;
} wsp_capability_t;

static INT16
wsp_cvt_capability (wap_cvt_t *obj, wsp_capability_t *p)
{
  UINT32 length, oldlen;

  switch (obj->operation) {
  case WAP_CVT_DECODE:
  case WAP_CVT_DECODE_STATIC:
    if (!wap_cvt_uintvar (obj, &length) ||
        !wap_cvt_uint8 (obj, &p->id) ||
        (length + obj->pos > obj->length + 1))
      return FALSE;

    oldlen = obj->length;
    obj->length = obj->pos + length - 1;
    switch (p->id) {
    case CAP_CLIENT_SDU_SIZE:
    case CAP_SERVER_SDU_SIZE:
      if (!wap_cvt_uintvar (obj, &p->_u.value32))
        return FALSE;
      break;

    case CAP_METHOD_MOR:
    case CAP_PUSH_MOR:
      if (!wap_cvt_uint8 (obj, &p->_u.value8))
        return FALSE;
      break;

    case CAP_PROTOCOL_OPTIONS:
      if (!wap_cvt_uint8 (obj, &p->_u.value8))
        return FALSE;
      break;
    }
    obj->pos = obj->length;
    obj->length = oldlen;
    break;

  case WAP_CVT_ENCODE:
  case WAP_CVT_ENCODE_SIZE:
    switch (p->id) {
    case CAP_CLIENT_SDU_SIZE:
    case CAP_SERVER_SDU_SIZE:
      length = 1 + wap_cvt_uintvar_len (p->_u.value32);
      if (!wap_cvt_uintvar (obj, &length) ||
          !wap_cvt_uint8 (obj, &p->id) ||
          !wap_cvt_uintvar (obj, &p->_u.value32))
        return FALSE;
      break;

    default:
      length = 2;
      if (!wap_cvt_uintvar (obj, &length) ||
          !wap_cvt_uint8 (obj, &p->id) ||
          !wap_cvt_uint8 (obj, &p->_u.value8))
        return FALSE;
      break;
    }
    break;

  case WAP_CVT_FREE:
    break;

  default:
    return FALSE;
  }

  return TRUE;
}

/*
 * Returns FALSE on error, TRUE otherwise.
 */
static INT16
wsp_create_capabilities_list (SDL_Natural client_sdu_size,
                              SDL_Natural server_sdu_size,
                              SDL_Octet protocol_options,
                              SDL_Octet method_mor,
                              SDL_Octet push_mor,
                              void **caplist, SDL_Natural *caplen)
{
  wap_cvt_t        cvt_obj;
  wsp_capability_t cap_client_sdu_size;
  wsp_capability_t cap_server_sdu_size;
#ifdef CONFIG_PUSH
  wsp_capability_t cap_protocol_options;
#endif
  wsp_capability_t cap_method_mor;
#ifdef CONFIG_PUSH
  wsp_capability_t cap_push_mor;
#endif


	push_mor = push_mor;					/*Added by integration, MALU*/
	protocol_options = protocol_options;	/*Added by integration, MALU*/

  cap_client_sdu_size.id = CAP_CLIENT_SDU_SIZE;
  cap_client_sdu_size._u.value32 = client_sdu_size;

  cap_server_sdu_size.id = CAP_SERVER_SDU_SIZE;
  cap_server_sdu_size._u.value32 = server_sdu_size;

#ifdef CONFIG_PUSH
  cap_protocol_options.id = CAP_PROTOCOL_OPTIONS;
  cap_protocol_options._u.value8 = protocol_options;
#endif

  cap_method_mor.id = CAP_METHOD_MOR;
  cap_method_mor._u.value8 = method_mor;

#ifdef CONFIG_PUSH
  cap_push_mor.id = CAP_PUSH_MOR;
  cap_push_mor._u.value8 = push_mor;
#endif

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE_SIZE, NULL, 0);
  if (!wsp_cvt_capability (&cvt_obj, &cap_client_sdu_size)
      || !wsp_cvt_capability (&cvt_obj, &cap_server_sdu_size)
#ifdef CONFIG_PUSH
      || !wsp_cvt_capability (&cvt_obj, &cap_protocol_options)
#endif
      || !wsp_cvt_capability (&cvt_obj, &cap_method_mor)
#ifdef CONFIG_PUSH
      || !wsp_cvt_capability (&cvt_obj, &cap_push_mor)
#endif
      )
    return FALSE;

  *caplen = cvt_obj.pos;
  *caplist = OSConnectorAlloc (*caplen);

  wap_cvt_init (&cvt_obj, WAP_CVT_ENCODE, *caplist, *caplen);
  if (!wsp_cvt_capability (&cvt_obj, &cap_client_sdu_size)
      || !wsp_cvt_capability (&cvt_obj, &cap_server_sdu_size)
#ifdef CONFIG_PUSH
      || !wsp_cvt_capability (&cvt_obj, &cap_protocol_options)
#endif
      || !wsp_cvt_capability (&cvt_obj, &cap_method_mor)
#ifdef CONFIG_PUSH
      || !wsp_cvt_capability (&cvt_obj, &cap_push_mor)
#endif
      )
    return FALSE;

  return TRUE;
}

/*
 * Returns FALSE on error, and TRUE otherwise.
 */
static INT16
wsp_check_capabilities_list (wap_cvt_t *obj, SDL_Natural caplen,
                             SDL_Natural *client_sdu_size,
                             SDL_Natural *server_sdu_size,
                             SDL_Octet *protocol_options,
                             SDL_Octet *method_mor,
                             SDL_Octet *push_mor)
{
  wsp_capability_t cap;
  UINT32           savedlen;

  savedlen = obj->length;
  obj->length = obj->pos + caplen;
  while (obj->pos < obj->length) {
    if (!wsp_cvt_capability (obj, &cap))
      return FALSE;

    switch (cap.id) {
    case CAP_CLIENT_SDU_SIZE:
      if (cap._u.value32 != 0) {
        if (*client_sdu_size == 0)
          *client_sdu_size = cap._u.value32;
        else
          *client_sdu_size = MIN (*client_sdu_size, cap._u.value32);
      }
      break;

    case CAP_SERVER_SDU_SIZE:
      if (cap._u.value32 != 0) {
        if (*server_sdu_size == 0)
          *server_sdu_size = cap._u.value32;
        else
          *server_sdu_size = MIN (*server_sdu_size, cap._u.value32);
      }
      break;

    case CAP_PROTOCOL_OPTIONS:
      *protocol_options = cap._u.value8;
      break;

    case CAP_METHOD_MOR:
      if (cap._u.value8 != 0) {
        if (*method_mor == 0)
          *method_mor = cap._u.value8;
        else
          *method_mor = MIN (*method_mor, cap._u.value8);
      }
      break;
      

    case CAP_PUSH_MOR:
      if (cap._u.value8 != 0) {
        if (*push_mor == 0)
          *push_mor = cap._u.value8;
        else
          *push_mor = MIN (*push_mor, cap._u.value8);
      }
      break;

    default:
      /* Ignore */
      break;
    }
  }
  obj->length = savedlen;

  return TRUE;
}

⌨️ 快捷键说明

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