Example #1
0
void FZHttpPost::SendPost()
{
   // Send current array contents to server
   // The 'user' (=fDBUserName) and 'category' (=fDBCategory) fields are added to the POST

   if(!fPostPairs) return;// nothing to send

   // add the 2 'header' elements to the POST (=> corresponds to value of fNHdrElements)
   // N.B. if the number of these elements changes you should modify fNHdrElements!
   AddKeyValuePair("user",fDBUserName);
   AddKeyValuePair("category",fDBCategory);

   //std::cout << "Sending " << fLineNumber+1 << "lines (" << fPostPairs << " key-value pairs) to server" << std::endl;

   curl_easy_setopt(fCURL, CURLOPT_HTTPPOST, formpost);
   /* CURLcode res = */ curl_easy_perform(fCURL);
/*
   if (res != CURLE_OK)
      std::cout << "curl_easy_perform() failed: " << curl_easy_strerror(res);
*/
   curl_formfree(formpost);
   formpost = lastptr = NULL;

   // reset line number (this is also the first array index, i.e. 'par[fLineNumber][some-key]')
   fLineNumber=0;
   // reset total number of key-value pairs in post
   fPostPairs=0;
}
Example #2
0
void FZHttpPost::AddToPost(const std::string& p, const std::string& v)
{
   // Add a 'parameter=value' pair to the current POST array member
   // i.e. we effectively define the following member of the PHP array:
   //
   //    fPHPArrayName[fLineNumber][p] = v
   //
   // Example:
   //    SetPHPArrayName("par");
   //    NewPost();
   //    AddToPost("toto","tata");
   // --> par[0][toto]='tata'

   char supp[50];
   std::string array_element;
   
   sprintf(supp, fPHPArrayFormatString.data(), fLineNumber, p.data()); 
   //array_element.Form(fPHPArrayFormatString.data(), fLineNumber, p.data());

   array_element = supp;

   AddKeyValuePair(array_element,v);
}
Example #3
0
int IniFile::Load(const string &filename)
{
    int err;
    string line;  // 带注释的行
    string cleanLine;  // 去掉注释后的行
    string comment;
    string rightComment;
    IniSection *currSection = NULL;  // 初始化一个字段指针

    release();

    fname_ = filename;
    std::ifstream ifs(fname_);
    if (!ifs.is_open()) {
        cout << "open file failed\n";
        return -1;
    }

    //增加默认段,即 无名段""
    currSection = new IniSection();
    currSection->name = "";
    sections_vt.push_back(currSection);

    // 每次读取一行内容到line
    while (std::getline(ifs, line)) {
        trim(line);

        // step 0,空行处理,如果长度为0,说明是空行,添加到comment,当作是注释的一部分
        if (line.length() <= 0) {
            comment += delim;
            continue;
        }

        // step 1
        // 如果行首不是注释,查找行尾是否存在注释
        // 如果该行以注释开头,添加到comment,跳过当前循环,continue
        if (IsCommentLine(line)) {
            comment += line + delim;
            continue;
        }

        // 如果行首不是注释,查找行尾是否存在注释,若存在,切割该行,将注释内容添加到rightComment
        split(line, commentHead, &cleanLine, &rightComment);


        // step 2,判断line内容是否为段或键
        //段开头查找 [
        if (cleanLine[0] == '[') {
            err = UpdateSection(cleanLine, comment, rightComment, &currSection);
        } else {
            // 如果该行是键值,添加到section段的items容器
             err = AddKeyValuePair(cleanLine, comment, rightComment, currSection);
        }

        if (err != 0) {
            ifs.close();
            return err;
        }

        // comment清零
        comment = "";
        rightComment = "";
    }

    ifs.close();

    return 0;
}