December 12th Wednesday (十二月 十二日 水曜日)

/* Parse form data from a string. The input string is NOT preserved. */
static apr_hash_t *parse_form_from_string(request_rec *r, char *args)
{
  apr_hash_t *form;
  apr_array_header_t *values;
  char *pair;
  char *eq;
  const char *delim = "&";
  char *last;
  char **ptr;

  if (args == NULL) {
    return NULL;
  }

  /* Split the input on '&' */
  for (pair = apr_strtok(args, delim, &last); pair != NULL;
  pair = apr_strtok(NULL, delim, &last)) {
  for (eq = pair; *eq; ++eq) {
    if (*eq == '+') {
      *eq = ' ';
    }
  }
  /* split into Key / Value and unescape it */
  eq = strchr(pair, '=');
  if (eq) {
    *eq++ = '/0';
    ap_unescape_url(pair);
    ap_unescape_url(eq);
  }
  else {
    eq = "";
    ap_unescape_url(pair);
  }
  /* Store key/value pair in our form hash. Given that there
  * may be many values for the same key, we store values
  * in an array (which we'll have to create the first
  * time we encounter the key in question).
  */
  values = apr_hash_get(form, pair, APR_HASH_KEY_STRING);
  if (values == NULL) {
    values = apr_array_make(r->pool, 1, sizeof(const char*));
    apr_hash_set(form, pair, APR_HASH_KEY_STRING, values);
  }
  ptr = apr_array_push(values);
  *ptr = apr_pstrdup(r->pool, eq);
  }
  return form;
}

  This scheme is based on parsing the entire input data from a single input buffer.  It works well where the total size of
a form submission is reasonably small, as is generally the case with normal web forms.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值