Пример #1
0
// part:headers(t)
static int lcurl_mime_part_headers(lua_State *L){
  lcurl_mime_part_t *p = lcurl_getmimepart(L);
  struct curl_slist *list;
  CURLcode ret;

  if(IS_FALSE(L, 2)){
    list = NULL;
  }
  else{
    list = lcurl_util_to_slist(L, 2);
    luaL_argcheck(L, list || IS_TABLE(L, 2), 2, "array or null expected");
  }

  ret = curl_mime_headers(p->part, list, 1);

  if(ret != CURLE_OK){
    if(list) curl_slist_free_all(list);
    return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, ret);
  }

  lua_settop(L, 1);
  return 1;
}
Пример #2
0
static int lcurl_mime_part_assing_ext(lua_State *L, int part, int i){
#define UNSET_VALUE (const char*)-1

  const char *mime_type = NULL, *mime_name = NULL, *mime_fname = NULL;
  int headers = 0;
  CURLcode ret;
  lcurl_mime_part_t *p = lcurl_getmimepart_at(L, part);

  if(IS_TABLE(L, i)) headers = i;
  else if (IS_OPTSTR(L, i)) {
    mime_type = IS_FALSE(L, i) ? UNSET_VALUE : lua_tostring(L, i);
    if(IS_TABLE(L, i+1)) headers = i+1;
    else if(IS_OPTSTR(L, i+1)){
      mime_name = IS_FALSE(L, i+1) ? UNSET_VALUE : lua_tostring(L, i+1);
      if(IS_TABLE(L, i+2)) headers = i+2;
      else if(IS_OPTSTR(L, i+2)){
        mime_fname = IS_FALSE(L, i+2) ? UNSET_VALUE : lua_tostring(L, i+2);
        if(IS_TABLE(L, i+3)) headers = i+3;
        else if(IS_FALSE(L, i+3)){
          headers = -1;
        }
      }
    }
  }

  if(mime_type){
    ret = curl_mime_type(p->part, mime_type == UNSET_VALUE ? NULL : mime_type);
    if(ret != CURLE_OK){
      return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, ret);
    }
  }

  if(mime_name){
    ret = curl_mime_name(p->part, mime_name == UNSET_VALUE ? NULL : mime_name);
    if(ret != CURLE_OK){
      return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, ret);
    }
  }

  if(mime_fname){
    ret = curl_mime_filename(p->part, mime_fname == UNSET_VALUE ? NULL : mime_fname);
    if(ret != CURLE_OK){
      return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, ret);
    }
  }

  if(headers){
    if(-1 == headers){
      ret = curl_mime_headers(p->part, NULL, 0);
      if(ret != CURLE_OK){
        return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, ret);
      }
    }
    else
      return lcurl_mime_part_assing_table(L, part, headers);
  }

  return 0;

#undef UNSET_VALUE
}
Пример #3
0
/* toss $n $dice $table for $face */
void
char__do_toss (CHAR_DATA * ch, char *argument, int cmd)
{
    register short int nArg = 0;
    register short int nDiceArg = 0;
    register short int nTableArg = 0;
    register short int nFaceArg = 0;
    register short int nFacet = 0;
    register short int nMaxFacet = 0;
    size_t nIndex = 0;
    register int nCount = 0;

    char *p = NULL;
    char buf[AVG_STRING_LENGTH * 10] = "";
    char arg[5][AVG_STRING_LENGTH / 5] = { "", "", "", "", "" };
    char key[AVG_STRING_LENGTH] = "";
    char strFacet[AVG_STRING_LENGTH] = "";
    char strFacetList[AVG_STRING_LENGTH] = "";
    OBJ_DATA *dice = NULL;
    OBJ_DATA *table = NULL;

    nArg =
        sscanf (argument, "%s %s %s %s %s", arg[0], arg[1], arg[2], arg[3],
                arg[4]);

    if (nArg <= 0)
    {
        send_to_char ("Toss what?\n", ch);
        return;
    }

    nCount = strtol (arg[0], &p, 10);
    if (errno == ERANGE || nCount == 0 || strlen (p) != 0)
    {
        nCount = 0;
    }
    else
    {
        nDiceArg = 1;
    }

    switch (nArg - nDiceArg)
    {
    case 3:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 1]) == 0) ? nDiceArg + 2 : -1;
        break;
    case 4:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 2]) == 0) ? nDiceArg + 3 : -1;	/* NO BREAK HERE goes to next case */
    case 2:
        nTableArg = nDiceArg + 1;
        break;
    default:
        break;
    }

    if (nFaceArg < 0)
    {
        send_to_char ("Toss them how?\n", ch);
        return;
    }

    if (!(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->right_hand)) &&
            !(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->left_hand)))
    {
        sprintf (buf, "You don't have a '%s'.\n", arg[nDiceArg]);
        send_to_char (buf, ch);
        return;
    }
    if (dice->obj_flags.type_flag != ITEM_TOSSABLE
            && dice->obj_flags.type_flag != ITEM_MONEY)
    {
        send_to_char ("Did you mean to #6throw#0 that object?\n", ch);
        return;
    }

    if (dice->count > 12 && (nCount == 0 || nCount > 12))
    {
        send_to_char ("You can't toss that many at once.\n", ch);
        return;
    }

    if (nTableArg && arg[nTableArg][0] &&
            (!(table = get_obj_in_list_vis (ch, arg[nTableArg], ch->room->contents))
             || !IS_TABLE(table)))
    {
        sprintf (buf, "You don't see any furniture like '%s'.\n",
                 arg[nTableArg]);
        send_to_char (buf, ch);
        return;
    }

    obj_from_char (&dice, nCount);

    if (dice->obj_flags.type_flag == ITEM_MONEY)
    {
        strcpy (key, " obverse reverse ");
        nMaxFacet = 2;
    }
    else if (dice->desc_keys)
    {
        sprintf (key, " %s ", dice->desc_keys);
    }
    else
    {
        strcpy (key,
                " one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty ");
    }

    if (nFaceArg && dice->o.od.value[1])
    {
        /*
           nFacet = strtol(arg[nFaceArg],&p,10);
           if ( errno == ERANGE || nFacet == 0 || strlen(p) != 0 ) {
           strcpy(strFacet,strstr(key,arg[nFaceArg]));
           if () {
           }
           else {
           nFacet = 0;
           }
           }
           else {
           }
         */

    }
    nMaxFacet = (nMaxFacet) ? nMaxFacet : dice->o.od.value[0];
    for (nCount = 0; nCount < dice->count; nCount++)
    {

        nFacet = number (1, nMaxFacet);

        for (nIndex = 0; nIndex < strlen (key); nIndex++)
        {
            if (key[nIndex] == ' ' && --nFacet <= 0)
                break;
        }

        sscanf (key + nIndex + 1, "%s %s", strFacet, buf);
        sprintf (strFacetList + strlen (strFacetList), "#6%s%s#0%s",
                 (nMaxFacet == 2) ? "the " : "a ", strFacet,
                 (nCount ==
                  dice->count - 2) ? " and " : ((nCount !=
                                                dice->count - 1) ? ", " : ""));
    }

    sprintf (buf, "You toss $p onto %s%s%s%s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground",
             (nFaceArg) ? ", trying for #6a " : "",
             (nFaceArg) ? arg[nFaceArg] : "", (nFaceArg) ? "#0" : "",
             (nCount > 1) ? "s" : "", (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_CHAR | _ACT_FORMAT);

    sprintf (buf, "$n tosses $p onto %s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground", (nCount > 1) ? "s" : "",
             (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_ROOM | _ACT_FORMAT);

    if (nTableArg)
    {
        obj_to_obj (dice, table);
    }
    else
    {
        obj_to_room (dice, ch->in_room);
    }
}