text:
using System;
using System.Threading.Tasks;
using TS3QueryLib.Net.Core.Common;
using TS3QueryLib.Net.Core.Common.Responses;

namespace TS3QueryLib.Net.Core
{
    public interface IQueryClient : ICommandExecutor
    {
        bool Connected { get; }
        string Host { get; }
        int Port { get; }

        QueryClient.ConnectResponse Connect();
        Task<QueryClient.ConnectResponse> ConnectAsync();
        void Disconnect();
        string Send(string messageToSend);
        Task<string> SendAsync(string messageToSend);

        /// <summary>
        /// Raised when a ban was detected
        /// </summary>
        event EventHandler<EventArgs<ICommandResponse>> BanDetected;

        /// <summary>
        /// Raised when the connection to the server was closed
        /// </summary>
        event EventHandler<EventArgs<string>> ConnectionClosed;

        void SetCommunicationLog(ICommunicationLog log);
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.geode.cache.configuration;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.geode.annotations.Experimental;

/**
 *
 * A "disk-dirs" element specifies the region's disk directories.
 *
 *
 *

 * Java class for disk-dirs-type complex type.
 *
 *

 * The following schema fragment specifies the expected content contained within this class.
 *
 *

 * <complexType name="disk-dirs-type">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="disk-dir" type="{http://geode.apache.org/schema/cache}disk-dir-type" maxOccurs="unbounded"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "disk-dirs-type", namespace = "http://geode.apache.org/schema/cache",
    propOrder = {"diskDirs"})
@Experimental
public class DiskDirsType implements Serializable {

  @XmlElement(name = "disk-dir", namespace = "http://geode.apache.org/schema/cache",
      required = true)
  protected List<DiskDirType> diskDirs;

  /**
   * Gets the value of the diskDir property.
   *
   *

   * This accessor method returns a reference to the live list,
   * not a snapshot. Therefore any modification you make to the
   * returned list will be present inside the JAXB object.
   * This is why there is not a set method for the diskDir property.
   *
   *

   * For example, to add a new item, do as follows:
   *
   *

   * getDiskDirs().add(newItem);
   *

   *
   *
   *

   * Objects of the following type(s) are allowed in the list
   * {@link DiskDirType }
   *
   *
   */
  public List<DiskDirType> getDiskDirs() {
    if (diskDirs == null) {
      diskDirs = new ArrayList<>();
    }
    return this.diskDirs;
  }

}


text:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;
using System.Net.Sockets;
using Manager.Manager;

namespace SManager
{
    public class SManager : AManager
    {
        private string[] _input;

        public SManager()
        {
            BwTask = new BackgroundWorker()
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = true
            };
            BwTask.DoWork += ExecuteTask;
        }

        public override void SettingList(Dictionary<string, object> lists)
        {
            DirectoryCover = lists["Directories"] as List<DirectoryModel>;
            dynamic tmp;
            if (lists.TryGetValue("SortingRules", out tmp))
                SortRules = tmp as List<SortByRule>;
        }

        protected override void ExecuteTask(object sender, DoWorkEventArgs e)
        {
            base.ExecuteTask(sender, e);

            int res = 0;
            List<Tuple<int, string>> output = new List<Tuple<int, string>>();

            foreach (var des in DirectoryCover)
            {
                try
                {
                    if (!des.Activated)
                        continue;
                    res = DoSort(des.Path);
                }
                catch (Exception ex)
                {
                    output.Add(new Tuple<int, string>(-1, ex.Message));
                }
                if (BwTask.CancellationPending)
                {
                    e.Cancel = true;
                    e.Result = res;
                    return;
                }
                e.Result = res;
            }

        }

        private int DoSort(string mainDirectory)
        {
            int res = 0;
            _input = Directory.GetDirectories(mainDirectory);
            for (int i = 0; i < _input.Length; i++)
            {
                Debug.WriteLine(_input[i]);
                var nDir = DoCheckRules(_input[i]);
                if (nDir != "")
                {

                    moveDirectory(mainDirectory, _input[i], nDir);
                    res++;
                    int save = _input.Length;
                    _input = Directory.GetDirectories(mainDirectory);
                    if (save != _input.Length)
                        i = 0;
                }
            }
            return res;
        }

        private void moveDirectory(string mainDirectory, string target, string ndir)
        {
            if (Directory.Exists(mainDirectory + "\\" + ndir))
            {
                Debug.WriteLine("Target : " + target + " move to :" + mainDirectory + "\\" + ndir + Path.GetFileName(target));
                Directory.Move(target, mainDirectory + "\\" + ndir + "\\" + Path.GetFileName(target));
            }
            else
            {
                Debug.WriteLine("Create Directory : " + mainDirectory + "\\" + ndir);
                Directory.CreateDirectory(mainDirectory + "\\" + ndir);
                Debug.WriteLine("Target : " + target + " move to :" + mainDirectory + "\\" + ndir + "\\" + Path.GetFileName(target));
                Directory.Move(target, mainDirectory + "\\" + ndir + "\\" + Path.GetFileName(target));
            }
        }

        private string DoCheckRules(string p)
        {
            foreach (var rule in SortRules)
            {
                if (!rule.IsActivated)
                    continue;
                var tmp = Regex.Match(Path.GetFileNameWithoutExtension(p), @rule.Strings).Groups[0].Value;
                Debug.WriteLine("Result of sort regex : " + tmp);
                if (tmp != "")
                {
                    return tmp;
                }
            }
            return "";
        }
    }
}


text:
#include "cpu/thread_context.hh"

#include "arch/kernel_stats.hh"
#include "base/misc.hh"
#include "base/trace.hh"
#include "config/the_isa.hh"
#include "cpu/base.hh"
#include "cpu/quiesce_event.hh"
#include "debug/Context.hh"
#include "debug/Quiesce.hh"
#include "params/BaseCPU.hh"
#include "sim/full_system.hh"

void
ThreadContext::compare(ThreadContext *one, ThreadContext *two)
{
    DPRINTF(Context, "Comparing thread contexts\n");

    // First loop through the integer registers.
    for (int i = 0; i < TheISA::NumIntRegs; ++i) {
        TheISA::IntReg t1 = one->readIntReg(i);
        TheISA::IntReg t2 = two->readIntReg(i);
        if (t1 != t2)
            panic("Int reg idx %d doesn't match, one: %#x, two: %#x",
                  i, t1, t2);
    }

    // Then loop through the floating point registers.
    for (int i = 0; i < TheISA::NumFloatRegs; ++i) {
        TheISA::FloatRegBits t1 = one->readFloatRegBits(i);
        TheISA::FloatRegBits t2 = two->readFloatRegBits(i);
        if (t1 != t2)
            panic("Float reg idx %d doesn't match, one: %#x, two: %#x",
                  i, t1, t2);
    }
    for (int i = 0; i < TheISA::NumMiscRegs; ++i) {
        TheISA::MiscReg t1 = one->readMiscRegNoEffect(i);
        TheISA::MiscReg t2 = two->readMiscRegNoEffect(i);
        if (t1 != t2)
            panic("Misc reg idx %d doesn't match, one: %#x, two: %#x",
                  i, t1, t2);
    }

    // loop through the Condition Code registers.
    for (int i = 0; i < TheISA::NumCCRegs; ++i) {
        TheISA::CCReg t1 = one->readCCReg(i);
        TheISA::CCReg t2 = two->readCCReg(i);
        if (t1 != t2)
            panic("CC reg idx %d doesn't match, one: %#x, two: %#x",
                  i, t1, t2);
    }
    if (!(one->pcState() == two->pcState()))
        panic("PC state doesn't match.");
    int id1 = one->cpuId();
    int id2 = two->cpuId();
    if (id1 != id2)
        panic("CPU ids don't match, one: %d, two: %d", id1, id2);

    const ContextID cid1 = one->contextId();
    const ContextID cid2 = two->contextId();
    if (cid1 != cid2)
        panic("Context ids don't match, one: %d, two: %d", id1, id2);

}

void
ThreadContext::quiesce()
{
    if (!getCpuPtr()->params()->do_quiesce)
        return;

    DPRINTF(Quiesce, "%s: quiesce()\n", getCpuPtr()->name());

    suspend();
    if (getKernelStats())
       getKernelStats()->quiesce();
}

void
ThreadContext::quiesceTick(Tick resume)
{
    BaseCPU *cpu = getCpuPtr();

    if (!cpu->params()->do_quiesce)
        return;

    EndQuiesceEvent *quiesceEvent = getQuiesceEvent();

    cpu->reschedule(quiesceEvent, resume, true);

    DPRINTF(Quiesce, "%s: quiesceTick until %lu\n", cpu->name(), resume);

    suspend();
    if (getKernelStats())
        getKernelStats()->quiesce();
}

void
serialize(ThreadContext &tc, CheckpointOut &cp)
{
    using namespace TheISA;

    FloatRegBits floatRegs[NumFloatRegs];
    for (int i = 0; i < NumFloatRegs; ++i)
        floatRegs[i] = tc.readFloatRegBitsFlat(i);
    // This is a bit ugly, but needed to maintain backwards
    // compatibility.
    arrayParamOut(cp, "floatRegs.i", floatRegs, NumFloatRegs);

    IntReg intRegs[NumIntRegs];
    for (int i = 0; i < NumIntRegs; ++i)
        intRegs[i] = tc.readIntRegFlat(i);
    SERIALIZE_ARRAY(intRegs, NumIntRegs);

#ifdef ISA_HAS_CC_REGS
    CCReg ccRegs[NumCCRegs];
    for (int i = 0; i < NumCCRegs; ++i)
        ccRegs[i] = tc.readCCRegFlat(i);
    SERIALIZE_ARRAY(ccRegs, NumCCRegs);
#endif

    tc.pcState().serialize(cp);

    // thread_num and cpu_id are deterministic from the config
}

void
unserialize(ThreadContext &tc, CheckpointIn &cp)
{
    using namespace TheISA;

    FloatRegBits floatRegs[NumFloatRegs];
    // This is a bit ugly, but needed to maintain backwards
    // compatibility.
    arrayParamIn(cp, "floatRegs.i", floatRegs, NumFloatRegs);
    for (int i = 0; i < NumFloatRegs; ++i)
        tc.setFloatRegBitsFlat(i, floatRegs[i]);

    IntReg intRegs[NumIntRegs];
    UNSERIALIZE_ARRAY(intRegs, NumIntRegs);
    for (int i = 0; i < NumIntRegs; ++i)
        tc.setIntRegFlat(i, intRegs[i]);

#ifdef ISA_HAS_CC_REGS
    CCReg ccRegs[NumCCRegs];
    UNSERIALIZE_ARRAY(ccRegs, NumCCRegs);
    for (int i = 0; i < NumCCRegs; ++i)
        tc.setCCRegFlat(i, ccRegs[i]);
#endif

    PCState pcState;
    pcState.unserialize(cp);
    tc.pcState(pcState);

    // thread_num and cpu_id are deterministic from the config
}

void
takeOverFrom(ThreadContext &ntc, ThreadContext &otc)
{
    assert(ntc.getProcessPtr() == otc.getProcessPtr());

    ntc.setStatus(otc.status());
    ntc.copyArchRegs(&otc);
    ntc.setContextId(otc.contextId());
    ntc.setThreadId(otc.threadId());

    if (FullSystem) {
        assert(ntc.getSystemPtr() == otc.getSystemPtr());

        BaseCPU *ncpu(ntc.getCpuPtr());
        assert(ncpu);
        EndQuiesceEvent *oqe(otc.getQuiesceEvent());
        assert(oqe);
        assert(oqe->tc == &otc);

        BaseCPU *ocpu(otc.getCpuPtr());
        assert(ocpu);
        EndQuiesceEvent *nqe(ntc.getQuiesceEvent());
        assert(nqe);
        assert(nqe->tc == &ntc);

        if (oqe->scheduled()) {
            ncpu->schedule(nqe, oqe->when());
            ocpu->deschedule(oqe);
        }
    }

    otc.setStatus(ThreadContext::Halted);
}


text:
require 'test_helper'

class BasketTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
end


text:
using System.Collections.Generic;
using eShopLegacyMVC.Models;
using System;
using eShopLegacyMVC.ViewModel;

namespace eShopLegacyMVC.Services
{
    public interface ICatalogService : IDisposable
    {
        CatalogItem FindCatalogItem(int id);
        IEnumerable<CatalogBrand> GetCatalogBrands();
        PaginatedItemsViewModel<CatalogItem> GetCatalogItemsPaginated(int pageSize, int pageIndex);
        IEnumerable<CatalogType> GetCatalogTypes();
        void CreateCatalogItem(CatalogItem catalogItem);
        void UpdateCatalogItem(CatalogItem catalogItem);
        void RemoveCatalogItem(CatalogItem catalogItem);
    }
}


text:
#define NOMINMAX
#include <memory.h>
#include "twitcurl.h"
#include "urlencode.h"

/*++
 * @method: twitCurl::twitCurl
 *
 * @description: constructor
 *
 * @input: none
 *
 * @output: none
 *
 *--*/
twitCurl::twitCurl() :
    m_curlHandle(NULL),
    m_curlProxyParamsSet(false),
    m_curlLoginParamsSet(false),
    m_curlCallbackParamsSet(false),
    m_eApiFormatType(twitCurlTypes::eTwitCurlApiFormatXml),
    m_eProtocolType(twitCurlTypes::eTwitCurlProtocolHttp) {
    /* Clear callback buffers */
    clearCurlCallbackBuffers();

    /* Initialize cURL */
    m_curlHandle = curl_easy_init();
    if (NULL == m_curlHandle) {
        std::string dummyStr;
        getLastCurlError(dummyStr);
    }
}

/*++
 * @method: twitCurl::~twitCurl
 *
 * @description: destructor
 *
 * @input: none
 *
 * @output: none
 *
 *--*/
twitCurl::~twitCurl() {
    /* Cleanup cURL */
    if (m_curlHandle) {
        curl_easy_cleanup(m_curlHandle);
        m_curlHandle = NULL;
    }
}

/*++
 * @method: twitCurl::clone
 *
 * @description: creates a clone of twitcurl object
 *
 * @input: none
 *
 * @output: cloned object
 *
 *--*/
twitCurl *twitCurl::clone() {
    twitCurl *cloneObj = new twitCurl();

    /* cURL proxy data */
    cloneObj->setProxyServerIp(m_proxyServerIp);
    cloneObj->setProxyServerPort(m_proxyServerPort);
    cloneObj->setProxyUserName(m_proxyUserName);
    cloneObj->setProxyPassword(m_proxyPassword);

    /* Twitter data */
    cloneObj->setTwitterUsername(m_twitterUsername);
    cloneObj->setTwitterPassword(m_twitterPassword);

    /* Twitter API type */
    cloneObj->setTwitterApiType(m_eApiFormatType);

    /* OAuth data */
    cloneObj->m_oAuth = m_oAuth.clone();

    return cloneObj;
}

/*++
 * @method: twitCurl::setTwitterApiType
 *
 * @description: method to set API type
 *
 * @input: none
 *
 * @output: none
 *
 *--*/
void twitCurl::setTwitterApiType(twitCurlTypes::eTwitCurlApiFormatType eType) {
    m_eApiFormatType = (eType < twitCurlTypes::eTwitCurlApiFormatMax) ?
                       eType : twitCurlTypes::eTwitCurlApiFormatXml;
}

/*++
 * @method: twitCurl::setTwitterProcotolType
 *
 * @description: method to set protocol
 *
 * @input: none
 *
 * @output: none
 *
 *--*/
void twitCurl::setTwitterProcotolType(twitCurlTypes::eTwitCurlProtocolType eType) {
    m_eProtocolType = (eType < twitCurlTypes::eTwitCurlProtocolMax) ?
                      eType : twitCurlTypes::eTwitCurlProtocolHttp;
}

/*++
 * @method: twitCurl::isCurlInit
 *
 * @description: method to check if cURL is initialized properly
 *
 * @input: none
 *
 * @output: true if cURL is intialized, otherwise false
 *
 *--*/
bool twitCurl::isCurlInit() {
    return (NULL != m_curlHandle) ? true : false;
}

/*++
 * @method: twitCurl::getTwitterUsername
 *
 * @description: method to get stored Twitter username
 *
 * @input: none
 *
 * @output: twitter username
 *
 *--*/
std::string& twitCurl::getTwitterUsername() {
    return m_twitterUsername;
}

/*++
 * @method: twitCurl::getTwitterPassword
 *
 * @description: method to get stored Twitter password
 *
 * @input: none
 *
 * @output: twitter password
 *
 *--*/
std::string& twitCurl::getTwitterPassword() {
    return m_twitterPassword;
}

/*++
 * @method: twitCurl::setTwitterUsername
 *
 * @description: method to set username
 *
 * @input: userName
 *
 * @output: none
 *
 *--*/
void twitCurl::setTwitterUsername(std::string& userName) {
    if (userName.length()) {
        m_twitterUsername    = userName;
        m_curlLoginParamsSet = false;
    }
}

/*++
 * @method: twitCurl::setTwitterPassword
 *
 * @description: method to set password
 *
 * @input: passWord
 *
 * @output: none
 *
 *--*/
void twitCurl::setTwitterPassword(std::string& passWord) {
    if (passWord.length()) {
        m_twitterPassword    = passWord;
        m_curlLoginParamsSet = false;
    }
}

/*++
 * @method: twitCurl::getProxyServerIp
 *
 * @description: method to get proxy server IP address
 *
 * @input: none
 *
 * @output: proxy server IP address
 *
 *--*/
std::string& twitCurl::getProxyServerIp() {
    return m_proxyServerIp;
}

/*++
 * @method: twitCurl::getProxyServerPort
 *
 * @description: method to get proxy server port
 *
 * @input: none
 *
 * @output: proxy server port
 *
 *--*/
std::string& twitCurl::getProxyServerPort() {
    return m_proxyServerPort;
}

/*++
 * @method: twitCurl::getProxyUserName
 *
 * @description: method to get proxy user name
 *
 * @input: none
 *
 * @output: proxy server user name
 *
 *--*/
std::string& twitCurl::getProxyUserName() {
    return m_proxyUserName;
}

/*++
 * @method: twitCurl::getProxyPassword
 *
 * @description: method to get proxy server password
 *
 * @input: none
 *
 * @output: proxy server password
 *
 *--*/
std::string& twitCurl::getProxyPassword() {
    return m_proxyPassword;
}

/*++
 * @method: twitCurl::setProxyServerIp
 *
 * @description: method to set proxy server IP address
 *
 * @input: proxyServerIp
 *
 * @output: none
 *
 *--*/
void twitCurl::setProxyServerIp(std::string& proxyServerIp) {
    if (proxyServerIp.length()) {
        m_proxyServerIp = proxyServerIp;

        /*
         * Reset the flag so that next cURL http request
         * would set proxy details again into cURL.
         */
        m_curlProxyParamsSet = false;
    }
}

/*++
 * @method: twitCurl::setProxyServerPort
 *
 * @description: method to set proxy server port
 *
 * @input: proxyServerPort
 *
 * @output: none
 *
 *--*/
void twitCurl::setProxyServerPort(std::string& proxyServerPort) {
    if (proxyServerPort.length()) {
        m_proxyServerPort = proxyServerPort;

        /*
         * Reset the flag so that next cURL http request
         * would set proxy details again into cURL.
         */
        m_curlProxyParamsSet = false;
    }
}

/*++
 * @method: twitCurl::setProxyUserName
 *
 * @description: method to set proxy server username
 *
 * @input: proxyUserName
 *
 * @output: none
 *
 *--*/
void twitCurl::setProxyUserName(std::string& proxyUserName) {
    if (proxyUserName.length()) {
        m_proxyUserName = proxyUserName;

        /*
         * Reset the flag so that next cURL http request
         * would set proxy details again into cURL.
         */
        m_curlProxyParamsSet = false;
    }
}

/*++
 * @method: twitCurl::setProxyPassword
 *
 * @description: method to set proxy server password
 *
 * @input: proxyPassword
 *
 * @output: none
 *
 *--*/
void twitCurl::setProxyPassword(std::string& proxyPassword) {
    if (proxyPassword.length()) {
        m_proxyPassword = proxyPassword;

        /*
         * Reset the flag so that next cURL http request
         * would set proxy details again into cURL.
         */
        m_curlProxyParamsSet = false;
    }
}

/*++
 * @method: twitCurl::search
 *
 * @description: method to return tweets that match a specified query.
 *
 * @input: searchQuery - search query in string format
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 * @note: Only ATOM and JSON format supported.
 *
 *--*/
bool twitCurl::search(std::string& searchQuery) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_SEARCH_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[twitCurlTypes::eTwitCurlApiFormatJson] +
                           twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SEARCHQUERYSTRING +
                           searchQuery;

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::statusUpdate
 *
 * @description: method to update new status message in twitter profile
 *
 * @input: newStatus
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::statusUpdate(std::string& newStatus) {
    bool retVal = false;

    if (newStatus.length()) {
        /* Prepare new status message */
        std::string newStatusMsg = twitCurlDefaults::TWITCURL_STATUSSTRING + urlencode(newStatus);

        /* Perform POST */
        retVal = performPost(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                             twitterDefaults::TWITCURL_STATUSUPDATE_URL +
                             twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                             newStatusMsg);
    }
    return retVal;
}

/*++
 * @method: twitCurl::statusShowById
 *
 * @description: method to get a status message by its id
 *
 * @input: statusId - a number in std::string format
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::statusShowById(std::string& statusId) {
    bool retVal = false;

    if (statusId.length()) {
        /* Prepare URL */
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

        /* Perform GET */
        retVal = performGet(buildUrl);
    }
    return retVal;
}

/*++
 * @method: twitCurl::statusDestroyById
 *
 * @description: method to delete a status message by its id
 *
 * @input: statusId - a number in std::string format
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::statusDestroyById(std::string& statusId) {
    bool retVal = false;

    if (statusId.length()) {
        /* Prepare URL */
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               twitterDefaults::TWITCURL_STATUDESTROY_URL + statusId +
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

        /* Perform DELETE */
        retVal = performDelete(buildUrl);
    }
    return retVal;
}

/*++
 * @method: twitCurl::retweetById
 *
 * @description: method to RETWEET a status message by its id
 *
 * @input: statusId - a number in std::string format
 *
 * @output: true if RETWEET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::retweetById(std::string& statusId) {
    bool retVal = false;

    if (statusId.length()) {
        /* Prepare URL */
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               twitterDefaults::TWITCURL_RETWEET_URL + statusId +
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

        /* Send some dummy data in POST */
        std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
                                urlencode(std::string("dummy"));

        /* Perform Retweet */
        retVal = performPost(buildUrl, dummyData);
    }
    return retVal;
}

/*++
 * @method: twitCurl::timelineHomeGet
 *
 * @description: method to get home timeline
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::timelineHomeGet(std::string sinceId) {
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    if (sinceId.length()) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
    }
    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::timelinePublicGet
 *
 * @description: method to get public timeline
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::timelinePublicGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_PUBLIC_TIMELINE_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::featuredUsersGet
 *
 * @description: method to get featured users
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::featuredUsersGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_FEATURED_USERS_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::timelineFriendsGet
 *
 * @description: method to get friends timeline
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::timelineFriendsGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_FRIENDS_TIMELINE_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::mentionsGet
 *
 * @description: method to get mentions
 *
 * @input: sinceId - String specifying since id parameter
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::mentionsGet(std::string sinceId) {
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_MENTIONS_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    if (sinceId.length()) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
    }
    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::timelineUserGet
 *
 * @description: method to get mentions
 *
 * @input: trimUser - Trim user name if true
 *         tweetCount - Number of tweets to get. Max 200.
 *         userInfo - screen name or user id in string format,
 *         isUserId - true if userInfo contains an id
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::timelineUserGet(bool trimUser, bool includeRetweets, unsigned int tweetCount,
                               std::string userInfo, bool isUserId) {
    /* Prepare URL */
    std::string buildUrl;

    utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       twitterDefaults::TWITCURL_USERTIMELINE_URL +
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                       userInfo, isUserId);

    if (!userInfo.length()) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
    }

    if (tweetCount) {
        if (tweetCount > twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT) {
            tweetCount = twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT;
        }
        std::stringstream tmpStrm;
        tmpStrm << twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_COUNT << tweetCount;
        buildUrl += tmpStrm.str();
        tmpStrm.str().clear();
    }

    if (includeRetweets) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_INCRETWEETS;
    }

    if (trimUser) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_TRIMUSER;
    }

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::userLookup
 *
 * @description: method to get a number of user's profiles
 *
 * @input: userInfo - vector of screen names or user ids
 *         isUserId - true if userInfo contains an id
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::userLookup(std::vector<std::string>& userInfo, bool isUserId) {
    bool retVal = false;

    if (userInfo.size()) {
        std::string userIds = "";
        std::string sep     = "";
        for (unsigned int i = 0; i < std::min((size_t)100, userInfo.size()); i++, sep = ",") {
            userIds += sep + userInfo[i];
        }

        userIds = (isUserId ? twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME) +
                  urlencode(userIds);

        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               twitterDefaults::TWITCURL_LOOKUPUSERS_URL +
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

        /* Perform POST */
        retVal = performPost(buildUrl, userIds);
    }

    return retVal;
}

/*++
 * @method: twitCurl::userGet
 *
 * @description: method to get a user's profile
 *
 * @input: userInfo - screen name or user id in string format,
 *         isUserId - true if userInfo contains an id
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::userGet(std::string& userInfo, bool isUserId) {
    bool retVal = false;

    if (userInfo.length()) {
        /* Set URL */
        std::string buildUrl;
        utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_SHOWUSERS_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                           userInfo, isUserId);

        /* Perform GET */
        retVal = performGet(buildUrl);
    }
    return retVal;
}

/*++
 * @method: twitCurl::friendsGet
 *
 * @description: method to get a user's friends
 *
 * @input: userInfo - screen name or user id in string format,
 *         isUserId - true if userInfo contains an id
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::friendsGet(std::string userInfo, bool isUserId) {
    /* Set URL */
    std::string buildUrl;

    utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       twitterDefaults::TWITCURL_SHOWFRIENDS_URL +
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                       userInfo, isUserId);

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::followersGet
 *
 * @description: method to get a user's followers
 *
 * @input: userInfo - screen name or user id in string format,
 *         isUserId - true if userInfo contains an id
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::followersGet(std::string userInfo, bool isUserId) {
    /* Prepare URL */
    std::string buildUrl;

    utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       twitterDefaults::TWITCURL_SHOWFOLLOWERS_URL +
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                       userInfo, isUserId);

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::directMessageGet
 *
 * @description: method to get direct messages
 *
 * @input: since id
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::directMessageGet(std::string sinceId) {
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_DIRECTMESSAGES_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    if (sinceId.length()) {
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
    }

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::directMessageSend
 *
 * @description: method to send direct message to a user
 *
 * @input: userInfo - screen name or user id of a user to whom message needs to be sent,
 *         dMsg - message
 *         isUserId - true if userInfo contains target user's id
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::directMessageSend(std::string& userInfo, std::string& dMsg, bool isUserId) {
    bool retVal = false;

    if (userInfo.length() && dMsg.length()) {
        /* Prepare new direct message */
        std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode(dMsg);

        /* Prepare URL */
        std::string buildUrl;
        utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_DIRECTMESSAGENEW_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                           userInfo, isUserId);

        /* Perform POST */
        retVal = performPost(buildUrl, newDm);
    }
    return retVal;
}

/*++
 * @method: twitCurl::directMessageGetSent
 *
 * @description: method to get sent direct messages
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::directMessageGetSent() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_DIRECTMESSAGESSENT_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::directMessageDestroyById
 *
 * @description: method to delete direct messages by its id
 *
 * @input: dMsgId - id of direct message in string format
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::directMessageDestroyById(std::string& dMsgId) {
    bool retVal = false;

    if (dMsgId.length()) {
        /* Prepare URL */
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               twitterDefaults::TWITCURL_DIRECTMESSAGEDESTROY_URL + dMsgId +
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

        /* Perform DELETE */
        retVal = performDelete(buildUrl);
    }
    return retVal;
}

/*++
 * @method: twitCurl::friendshipCreate
 *
 * @description: method to add a twitter user as friend (follow a user)
 *
 * @input: userInfo - user id or screen name of a user
 *         isUserId - true if userInfo contains a user id instead of screen name
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::friendshipCreate(std::string& userInfo, bool isUserId) {
    bool retVal = false;

    if (userInfo.length()) {
        /* Prepare URL */
        std::string buildUrl;
        utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                           userInfo, isUserId);

        /* Send some dummy data in POST */
        std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
                                urlencode(std::string("dummy"));

        /* Perform POST */
        retVal = performPost(buildUrl, dummyData);
    }
    return retVal;
}

/*++
 * @method: twitCurl::friendshipDestroy
 *
 * @description: method to delete a twitter user from friend list (unfollow a user)
 *
 * @input: userInfo - user id or screen name of a user
 *         isUserId - true if userInfo contains a user id instead of screen name
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::friendshipDestroy(std::string& userInfo, bool isUserId) {
    bool retVal = false;

    if (userInfo.length()) {
        /* Prepare URL */
        std::string buildUrl;
        utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_FRIENDSHIPSDESTROY_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                           userInfo, isUserId);

        /* Perform DELETE */
        retVal = performDelete(buildUrl);
    }
    return retVal;
}

/*++
 * @method: twitCurl::friendshipShow
 *
 * @description: method to show all friends
 *
 * @input: userInfo - user id or screen name of a user of whom friends need to be shown
 *         isUserId - true if userInfo contains a user id instead of screen name
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::friendshipShow(std::string& userInfo, bool isUserId) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_FRIENDSHIPSSHOW_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    if (userInfo.length()) {
        /* Append username to the URL */
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
        if (isUserId) {
            buildUrl += twitCurlDefaults::TWITCURL_TARGETUSERID;
        } else {
            buildUrl += twitCurlDefaults::TWITCURL_TARGETSCREENNAME;
        }
        buildUrl += userInfo;
    }

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::friendsIdsGet
 *
 * @description: method to show IDs of all friends of a twitter user
 *
 * @input: userInfo - user id or screen name of a user
 *         isUserId - true if userInfo contains a user id instead of screen name
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::friendsIdsGet(std::string& userInfo, bool isUserId) {
    /* Prepare URL */
    std::string buildUrl;

    utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       twitterDefaults::TWITCURL_FRIENDSIDS_URL +
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                       userInfo, isUserId);

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::followersIdsGet
 *
 * @description: method to show IDs of all followers of a twitter user
 *
 * @input: userInfo - user id or screen name of a user
 *         isUserId - true if userInfo contains a user id instead of screen name
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::followersIdsGet(std::string& userInfo, bool isUserId) {
    /* Prepare URL */
    std::string buildUrl;

    utilMakeUrlForUser(buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       twitterDefaults::TWITCURL_FOLLOWERSIDS_URL +
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
                       userInfo, isUserId);

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::accountRateLimitGet
 *
 * @description: method to get API rate limit of current user
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::accountRateLimitGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_ACCOUNTRATELIMIT_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::accountVerifyCredGet
 *
 * @description: method to get information on user identified by given credentials
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::accountVerifyCredGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_ACCOUNTVERIFYCRED_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::favoriteGet
 *
 * @description: method to get favorite users' statuses
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::favoriteGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_FAVORITESGET_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::favoriteCreate
 *
 * @description: method to favorite a status message
 *
 * @input: statusId - id in string format of the status to be favorited
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::favoriteCreate(std::string& statusId) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_FAVORITECREATE_URL + statusId +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Send some dummy data in POST */
    std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
                            urlencode(std::string("dummy"));

    /* Perform POST */
    return performPost(buildUrl, dummyData);
}

/*++
 * @method: twitCurl::favoriteDestroy
 *
 * @description: method to delete a favorited the status
 *
 * @input: statusId - id in string format of the favorite status to be deleted
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::favoriteDestroy(std::string& statusId) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_FAVORITEDESTROY_URL + statusId +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Perform DELETE */
    return performDelete(buildUrl);
}

/*++
 * @method: twitCurl::blockCreate
 *
 * @description: method to block a user
 *
 * @input: userInfo - user id or screen name
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::blockCreate(std::string& userInfo) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_BLOCKSCREATE_URL + userInfo +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Send some dummy data in POST */
    std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
                            urlencode(std::string("dummy"));

    /* Perform POST */
    return performPost(buildUrl, dummyData);
}

/*++
 * @method: twitCurl::blockDestroy
 *
 * @description: method to unblock a user
 *
 * @input: userInfo - user id or screen name
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::blockDestroy(std::string& userInfo) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_BLOCKSDESTROY_URL + userInfo +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Perform DELETE */
    return performDelete(buildUrl);
}

/*++
 * @method: twitCurl::savedSearchGet
 *
 * @description: gets authenticated user's saved search queries.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::savedSearchGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_SAVEDSEARCHGET_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::savedSearchShow
 *
 * @description: method to retrieve the data for a saved search owned by the authenticating user
 *               specified by the given id.
 *
 * @input: searchId - id in string format of the search to be displayed
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::savedSearchShow(std::string& searchId) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_SAVEDSEARCHSHOW_URL + searchId +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Perform GET */
    return performGet(buildUrl);
}

/*++
 * @method: twitCurl::savedSearchCreate
 *
 * @description: creates a saved search for the authenticated user
 *
 * @input: query - the query of the search the user would like to save
 *
 * @output: true if POST is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::savedSearchCreate(std::string& query) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_SAVEDSEARCHCREATE_URL +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Send some dummy data in POST */
    std::string queryStr = twitCurlDefaults::TWITCURL_QUERYSTRING + urlencode(query);

    /* Perform POST */
    return performPost(buildUrl, queryStr);
}

/*++
 * @method: twitCurl::savedSearchDestroy
 *
 * @description: method to destroy a saved search for the authenticated user. The search specified
 *               by id must be owned by the authenticating user.
 *
 * @input: searchId - search id of item to be deleted
 *
 * @output: true if DELETE is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::savedSearchDestroy(std::string& searchId) {
    /* Prepare URL */
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                           twitterDefaults::TWITCURL_SAVEDSEARCHDESTROY_URL + searchId +
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];

    /* Perform DELETE */
    return performDelete(buildUrl);
}

/*++
 * @method: twitCurl::trendsGet()
 *
 * @description: gets trends.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::trendsGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_TRENDS_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::trendsDailyGet()
 *
 * @description: gets daily trends.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::trendsDailyGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_TRENDSDAILY_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::trendsWeeklyGet()
 *
 * @description: gets weekly trends.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::trendsWeeklyGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_TRENDSWEEKLY_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::trendsCurrentGet()
 *
 * @description: gets current trends.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::trendsCurrentGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_TRENDSCURRENT_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::trendsAvailableGet()
 *
 * @description: gets available trends.
 *
 * @input: none
 *
 * @output: true if GET is success, otherwise false. This does not check http
 *          response by twitter. Use getLastWebResponse() for that.
 *
 *--*/
bool twitCurl::trendsAvailableGet() {
    /* Perform GET */
    return performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                      twitterDefaults::TWITCURL_TRENDSAVAILABLE_URL +
                      twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType]);
}

/*++
 * @method: twitCurl::getLastWebResponse
 *
 * @description: method to get http response for the most recent request sent.
 *               twitcurl users need to call this method and parse the XML
 *               data returned by twitter to see what has happened.
 *
 * @input: outWebResp - string in which twitter's response is supplied back to caller
 *
 * @output: none
 *
 *--*/
void twitCurl::getLastWebResponse(std::string& outWebResp) {
    outWebResp = "";
    if (m_callbackData.length()) {
        outWebResp = m_callbackData;
    }
}

/*++
 * @method: twitCurl::getLastCurlError
 *
 * @description: method to get cURL error response for most recent http request.
 *               twitcurl users can call this method if any of the APIs return
 *               false.
 *
 * @input: none
 *
 * @output: none
 *
 *--*/
void twitCurl::getLastCurlError(std::string& outErrResp) {
    m_errorBuffer[twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE - 1] = twitCurlDefaults::TWITCURL_EOS;
    outErrResp.assign(m_errorBuffer);
}

/*++
 * @method: twitCurl::curlCallback
 *
 * @description: static method to get http response back from cURL.
 *               this is an internal method, users of twitcurl need not
 *               use this.
 *
 * @input: as per cURL convention.
 *
 * @output: size of data stored in our buffer
 *
 * @remarks: internal method
 *
 *--*/
int twitCurl::curlCallback(char *data, size_t size, size_t nmemb, twitCurl *pTwitCurlObj) {
    int writtenSize = 0;

    if ((NULL != pTwitCurlObj) && (NULL != data)) {
        /* Save http response in twitcurl object's buffer */
        writtenSize = pTwitCurlObj->saveLastWebResponse(data, (size * nmemb));
    }
    return writtenSize;
}

/*++
 * @method: twitCurl::saveLastWebResponse
 *
 * @description: method to save http responses. this is an internal method
 *               and twitcurl users need not use this.
 *
 * @input: data - character buffer from cURL,
 *         size - size of character buffer
 *
 * @output: size of data stored in our buffer
 *
 * @remarks: internal method
 *
 *--*/
int twitCurl::saveLastWebResponse(char *& data, size_t size) {
    int bytesWritten = 0;

    if (data && size) {
        /* Append data in our internal buffer */
        m_callbackData.append(data, size);
        bytesWritten = (int)size;
    }
    return bytesWritten;
}

/*++
 * @method: twitCurl::clearCurlCallbackBuffers
 *
 * @description: method to clear callback buffers used by cURL. this is an
 *               internal method and twitcurl users need not use this.
 *
 * @input: none
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
void twitCurl::clearCurlCallbackBuffers() {
    m_callbackData = "";
    memset(m_errorBuffer, 0, twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE);
}

/*++
 * @method: twitCurl::prepareCurlProxy
 *
 * @description: method to set proxy details into cURL. this is an internal method.
 *               twitcurl users should not use this method, instead use setProxyXxx
 *               methods to set proxy server information.
 *
 * @input: none
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
void twitCurl::prepareCurlProxy() {
    if (!m_curlProxyParamsSet) {
        /* Reset existing proxy details in cURL */
        curl_easy_setopt(m_curlHandle, CURLOPT_PROXY, NULL);
        curl_easy_setopt(m_curlHandle, CURLOPT_PROXYUSERPWD, NULL);
        curl_easy_setopt(m_curlHandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);

        /* Set proxy details in cURL */
        std::string proxyIpPort("");
        if (getProxyServerIp().size()) {
            utilMakeCurlParams(proxyIpPort, getProxyServerIp(), getProxyServerPort());
        }
        curl_easy_setopt(m_curlHandle, CURLOPT_PROXY, proxyIpPort.c_str());

        /* Prepare username and password for proxy server */
        if (m_proxyUserName.length() && m_proxyPassword.length()) {
            std::string proxyUserPass;
            utilMakeCurlParams(proxyUserPass, getProxyUserName(), getProxyPassword());
            curl_easy_setopt(m_curlHandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str());
        }

        /* Set the flag to true indicating that proxy info is set in cURL */
        m_curlProxyParamsSet = true;
    }
}

/*++
 * @method: twitCurl::prepareCurlCallback
 *
 * @description: method to set callback details into cURL. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: none
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
void twitCurl::prepareCurlCallback() {
    if (!m_curlCallbackParamsSet) {
        /* Set buffer to get error */
        curl_easy_setopt(m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer);

        /* Set callback function to get response */
        curl_easy_setopt(m_curlHandle, CURLOPT_WRITEFUNCTION, curlCallback);
        curl_easy_setopt(m_curlHandle, CURLOPT_WRITEDATA, this);

        /* Set the flag to true indicating that callback info is set in cURL */
        m_curlCallbackParamsSet = true;
    }
}

/*++
 * @method: twitCurl::prepareCurlUserPass
 *
 * @description: method to set twitter credentials into cURL. this is an internal method.
 *               twitcurl users should not use this method, instead use setTwitterXxx
 *               methods to set twitter username and password.
 *
 * @input: none
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
void twitCurl::prepareCurlUserPass() {
    if (!m_curlLoginParamsSet) {
        /* Reset existing username and password stored in cURL */
        curl_easy_setopt(m_curlHandle, CURLOPT_USERPWD, "");

        if (getTwitterUsername().size()) {
            /* Prepare username:password */
            std::string userNamePassword;
            utilMakeCurlParams(userNamePassword, getTwitterUsername(), getTwitterPassword());

            /* Set username and password */
            curl_easy_setopt(m_curlHandle, CURLOPT_USERPWD, userNamePassword.c_str());
        }

        /* Set the flag to true indicating that twitter credentials are set in cURL */
        m_curlLoginParamsSet = true;
    }
}

/*++
 * @method: twitCurl::prepareStandardParams
 *
 * @description: method to set standard params into cURL. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: none
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
void twitCurl::prepareStandardParams() {
    /* Restore any custom request we may have */
    curl_easy_setopt(m_curlHandle, CURLOPT_CUSTOMREQUEST, NULL);

    /* All supported encodings */
    curl_easy_setopt(m_curlHandle, CURLOPT_ENCODING, "");

    /* Clear callback and error buffers */
    clearCurlCallbackBuffers();

    /* Prepare proxy */
    prepareCurlProxy();

    /* Prepare cURL callback data and error buffer */
    prepareCurlCallback();

    /* Prepare username and password for twitter */
    prepareCurlUserPass();
}

/*++
 * @method: twitCurl::performGet
 *
 * @description: method to send http GET request. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: getUrl - url
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
bool twitCurl::performGet(const std::string& getUrl) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    std::string       dataStrDummy;
    std::string       oAuthHttpHeader;
    struct curl_slist *pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* Set OAuth header */
    m_oAuth.getOAuthHeader(eOAuthHttpGet, getUrl, dataStrDummy, oAuthHttpHeader);
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Set http request and url */
    curl_easy_setopt(m_curlHandle, CURLOPT_HTTPGET, 1);
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, getUrl.c_str());

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_slist_free_all(pOAuthHeaderList);
        }
        return true;
    }
    if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
    }
    return false;
}

/*++
 * @method: twitCurl::performGet
 *
 * @description: method to send http GET request. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: const std::string& getUrl, const std::string& oAuthHttpHeader
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
bool twitCurl::performGet(const std::string& getUrl, const std::string& oAuthHttpHeader) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    struct curl_slist *pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* Set http request and url */
    curl_easy_setopt(m_curlHandle, CURLOPT_HTTPGET, 1);
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, getUrl.c_str());

    /* Set header */
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_slist_free_all(pOAuthHeaderList);
        }
        return true;
    }
    if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
    }
    return false;
}

/*++
 * @method: twitCurl::performDelete
 *
 * @description: method to send http DELETE request. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: deleteUrl - url
 *
 * @output: none
 *
 * @remarks: internal method
 *
 *--*/
bool twitCurl::performDelete(const std::string& deleteUrl) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    std::string       dataStrDummy;
    std::string       oAuthHttpHeader;
    struct curl_slist *pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* Set OAuth header */
    m_oAuth.getOAuthHeader(eOAuthHttpDelete, deleteUrl, dataStrDummy, oAuthHttpHeader);
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Set http request and url */
    curl_easy_setopt(m_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, deleteUrl.c_str());
    curl_easy_setopt(m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStrDummy.c_str());

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_slist_free_all(pOAuthHeaderList);
        }
        return true;
    }
    if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
    }
    return false;
}

/*++
 * @method: twitCurl::performPost
 *
 * @description: method to send http POST request. this is an internal method.
 *               twitcurl users should not use this method.
 *
 * @input: postUrl - url,
 *         dataStr - url encoded data to be posted
 *
 * @output: none
 *
 * @remarks: internal method
 *           data value in dataStr must already be url encoded.
 *           ex: dataStr = "key=urlencode(value)"
 *
 *--*/
bool twitCurl::performPost(const std::string& postUrl, std::string dataStr) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    std::string       oAuthHttpHeader;
    struct curl_slist *pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* Set OAuth header */
    m_oAuth.getOAuthHeader(eOAuthHttpPost, postUrl, dataStr, oAuthHttpHeader);
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Set http request, url and data */
    curl_easy_setopt(m_curlHandle, CURLOPT_POST, 1);
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, postUrl.c_str());
    if (dataStr.length()) {
        curl_easy_setopt(m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str());
    }

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_slist_free_all(pOAuthHeaderList);
        }
        return true;
    }
    if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
    }
    return false;
}

/*++
 * @method: utilMakeCurlParams
 *
 * @description: utility function to build parameter strings in the format
 *               required by cURL ("param1:param2"). twitcurl users should
 *               not use this function.
 *
 * @input: inParam1 - first parameter,
 *         inParam2 - second parameter
 *
 * @output: outStr - built parameter
 *
 * @remarks: internal method
 *
 *--*/
void utilMakeCurlParams(std::string& outStr, std::string& inParam1, std::string& inParam2) {
    outStr  = inParam1;
    outStr += twitCurlDefaults::TWITCURL_COLON + inParam2;
}

/*++
 * @method: utilMakeUrlForUser
 *
 * @description: utility function to build url compatible to twitter. twitcurl
 *               users should not use this function.
 *
 * @input: baseUrl - base twitter url,
 *         userInfo - user name,
 *         isUserId - indicates if userInfo contains a user id or scree name
 *
 * @output: outUrl - built url
 *
 * @remarks: internal method
 *
 *--*/
void utilMakeUrlForUser(std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId) {
    /* Copy base URL */
    outUrl = baseUrl;

    if (userInfo.length()) {
        /* Append username to the URL */
        outUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
        if (isUserId) {
            outUrl += twitCurlDefaults::TWITCURL_USERID;
        } else {
            outUrl += twitCurlDefaults::TWITCURL_SCREENNAME;
        }
        outUrl += userInfo;
    }
}

/*++
 * @method: twitCurl::getOAuth
 *
 * @description: method to get a reference to oAuth object.
 *
 * @input: none
 *
 * @output: reference to oAuth object
 *
 *--*/
oAuth& twitCurl::getOAuth() {
    return m_oAuth;
}

/*++
 * @method: twitCurl::oAuthRequestToken
 *
 * @description: method to get a request token key and secret. this token
 *               will be used to get authorize user and get PIN from twitter
 *
 * @input: authorizeUrl is an output parameter. this method will set the url
 *         in this string. user should visit this link and get PIN from that page.
 *
 * @output: true if everything went sucessfully, otherwise false
 *
 *--*/
bool twitCurl::oAuthRequestToken(std::string& authorizeUrl /* out */) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    /* Get OAuth header for request token */
    bool        retVal = false;
    std::string oAuthHeader;
    authorizeUrl = "";
    if (m_oAuth.getOAuthHeader(eOAuthHttpGet,
                               twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
                               std::string(""),
                               oAuthHeader)) {
        if (performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL, oAuthHeader)) {
            /* Tell OAuth object to save access token and secret from web response */
            std::string twitterResp;
            getLastWebResponse(twitterResp);
            m_oAuth.extractOAuthTokenKeySecret(twitterResp);

            /* Get access token and secret from OAuth object */
            std::string oAuthTokenKey;
            m_oAuth.getOAuthTokenKey(oAuthTokenKey);

            /* Build authorize url so that user can visit in browser and get PIN */
            authorizeUrl.assign(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_AUTHORIZE_URL);
            authorizeUrl.append(oAuthTokenKey.c_str());

            retVal = true;
        }
    }
    return retVal;
}

/*++
 * @method: twitCurl::oAuthAccessToken
 *
 * @description: method to exchange request token with access token
 *
 * @input: none
 *
 * @output: true if everything went sucessfully, otherwise false
 *
 *--*/
bool twitCurl::oAuthAccessToken() {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }
    /* Get OAuth header for access token */
    bool        retVal = false;
    std::string oAuthHeader;
    if (m_oAuth.getOAuthHeader(eOAuthHttpGet,
                               twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                               oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
                               std::string(""),
                               oAuthHeader, true)) {
        if (performGet(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
                       oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL, oAuthHeader)) {
            /* Tell OAuth object to save access token and secret from web response */
            std::string twitterResp;
            getLastWebResponse(twitterResp);
            m_oAuth.extractOAuthTokenKeySecret(twitterResp);

            retVal = true;
        }
    }
    return retVal;
}

/*++
 * ADDED BY ANTIROOT
 *
 * @method: twitCurl::oAuthHandlePIN
 *
 * @description: method to handle user's PIN code from the authentiation URLs
 *
 * @input: none
 *
 * @output: true if everything went sucessfully, otherwise false
 *
 *--*/
bool twitCurl::oAuthHandlePIN(const std::string& authorizeUrl /* in */) {
    /* Return if cURL is not initialized */
    if (!isCurlInit()) {
        return false;
    }

    std::string       dataStr;
    std::string       oAuthHttpHeader;
    std::string       authenticityTokenVal;
    std::string       oauthTokenVal;
    std::string       pinCodeVal;
    unsigned long     httpStatusCode = 0;
    size_t            nPosStart, nPosEnd;
    struct curl_slist *pOAuthHeaderList = NULL;

    /* Prepare standard params */
    prepareStandardParams();

    /* Set OAuth header */
    m_oAuth.getOAuthHeader(eOAuthHttpGet, authorizeUrl, dataStr, oAuthHttpHeader);
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Set http request and url */
    curl_easy_setopt(m_curlHandle, CURLOPT_HTTPGET, 1);
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, authorizeUrl.c_str());

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_easy_getinfo(m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode);
            curl_slist_free_all(pOAuthHeaderList);

            // Now, let's find the authenticity token and oauth token
            nPosStart = m_callbackData.find(oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY);
            if (std::string::npos == nPosStart) {
                return false;
            }
            nPosStart += oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY.length();
            nPosEnd    = m_callbackData.substr(nPosStart).find(oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP);
            if (std::string::npos == nPosEnd) {
                return false;
            }
            authenticityTokenVal = m_callbackData.substr(nPosStart, nPosEnd);

            nPosStart = m_callbackData.find(oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY);
            if (std::string::npos == nPosStart) {
                return false;
            }
            nPosStart += oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY.length();
            nPosEnd    = m_callbackData.substr(nPosStart).find(oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP);
            if (std::string::npos == nPosEnd) {
                return false;
            }
            oauthTokenVal = m_callbackData.substr(nPosStart, nPosEnd);
        }
    } else if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
        return false;
    }

    // Second phase for the authorization
    pOAuthHeaderList = NULL;
    oAuthHttpHeader.clear();

    /* Prepare standard params */
    prepareStandardParams();

    /*
       Now, we need to make a data string for POST operation
       which includes oauth token, authenticity token, username, password.
     */
    dataStr = oAuthLibDefaults::OAUTHLIB_TOKEN_KEY + "=" + oauthTokenVal + "&" +                     \
              oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_KEY + "=" + authenticityTokenVal + "&" + \
              oAuthLibDefaults::OAUTHLIB_SESSIONUSERNAME_KEY + "=" + getTwitterUsername() + "&" +    \
              oAuthLibDefaults::OAUTHLIB_SESSIONPASSWORD_KEY + "=" + getTwitterPassword();

    /* Set OAuth header */
    m_oAuth.getOAuthHeader(eOAuthHttpPost, authorizeUrl, dataStr, oAuthHttpHeader);
    if (oAuthHttpHeader.length()) {
        pOAuthHeaderList = curl_slist_append(pOAuthHeaderList, oAuthHttpHeader.c_str());
        if (pOAuthHeaderList) {
            curl_easy_setopt(m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList);
        }
    }

    /* Set http request and url */
    curl_easy_setopt(m_curlHandle, CURLOPT_POST, 1);
    curl_easy_setopt(m_curlHandle, CURLOPT_URL, authorizeUrl.c_str());
    curl_easy_setopt(m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str());

    /* Send http request */
    if (CURLE_OK == curl_easy_perform(m_curlHandle)) {
        if (pOAuthHeaderList) {
            curl_easy_getinfo(m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode);
            curl_slist_free_all(pOAuthHeaderList);

            // Now, let's find the PIN CODE
            nPosStart = m_callbackData.find(oAuthLibDefaults::OAUTHLIB_PIN_TWITTER_RESP_KEY);
            if (std::string::npos == nPosStart) {
                return false;
            }
            nPosStart += oAuthLibDefaults::OAUTHLIB_PIN_TWITTER_RESP_KEY.length();
            nPosEnd    = m_callbackData.substr(nPosStart).find(oAuthLibDefaults::OAUTHLIB_PIN_END_TAG_TWITTER_RESP);
            if (std::string::npos == nPosEnd) {
                return false;
            }
            pinCodeVal = m_callbackData.substr(nPosStart, nPosEnd);
            getOAuth().setOAuthPin(pinCodeVal);
            return true;
        }
    } else if (pOAuthHeaderList) {
        curl_slist_free_all(pOAuthHeaderList);
    }
    return false;
}


text:
Reports calls to Arrays.asList() with at most one argument.

  Such calls could be replaced
  with Collections.singletonList(), Collections.emptyList(),
  or List.of() on JDK 9 and later, which will save some memory.

In particular, Collections.emptyList() and List.of() with no arguments
  always return a shared instance,
  while Arrays.asList() with no arguments creates a new object every time it's called.

Note: the lists returned by Collections.singletonList() and List.of() are immutable,
while the list returned Arrays.asList() allows calling the set() method.
This may break the code in rare cases.

Example:

  List<String> empty = Arrays.asList();
  List<String> one = Arrays.asList("one");

After the quick-fix is applied:

  List<String> empty = Collections.emptyList();
  List<String> one = Collections.singletonList("one");


text:
@interface CMJHChartShowController : UIViewController

@property (assign , nonatomic) NSInteger  index ;

@end


text:
/*
 *  fs/partitions/ultrix.c
 *
 *  Code extracted from drivers/block/genhd.c
 *
 *  Re-organised Jul 1999 Russell King
 */

#include "check.h"
#include "ultrix.h"

int ultrix_partition(struct parsed_partitions *state)
{
	int i;
	Sector sect;
	unsigned char *data;
	struct ultrix_disklabel {
		s32	pt_magic;	/* magic no. indicating part. info exits */
		s32	pt_valid;	/* set by driver if pt is current */
		struct  pt_info {
			s32		pi_nblocks; /* no. of sectors */
			u32		pi_blkoff;  /* block offset for start */
		} pt_part[8];
	} *label;

#define PT_MAGIC	0x032957	/* Partition magic number */
#define PT_VALID	1		/* Indicates if struct is valid */

	data = read_part_sector(state, (16384 - sizeof(*label))/512, &sect);
	if (!data)
		return -1;

	label = (struct ultrix_disklabel *)(data + 512 - sizeof(*label));

	if (label->pt_magic == PT_MAGIC && label->pt_valid == PT_VALID) {
		for (i=0; i<8; i++)
			if (label->pt_part[i].pi_nblocks)
				put_partition(state, i+1,
					      label->pt_part[i].pi_blkoff,
					      label->pt_part[i].pi_nblocks);
		put_dev_sector(sect);
		strlcat(state->pp_buf, "\n", PAGE_SIZE);
		return 1;
	} else {
		put_dev_sector(sect);
		return 0;
	}
}


text:
package com.elmakers.mine.bukkit.utility.platform.legacy;

import com.elmakers.mine.bukkit.utility.platform.Platform;
import com.elmakers.mine.bukkit.utility.platform.base.EntityUtilsBase;

public class EntityUtils extends EntityUtilsBase  {
    public EntityUtils(final Platform platform) {
        super(platform);
    }
}


text:
void
unsetenv (const char *name CK_ATTRIBUTE_UNUSED)
{
  assert (0);
}


text:
<!doctype html>

    <meta charset=utf8>

        <link rel=stylesheet href="https://prosemirror.net/css/editor.css">

        <button onclick="saveState()">SAVE TEST</button>
        <button onclick="openState()">OPEN TEST</button>
        <button onclick="showSelection()">SHOW SELECTION</button>

Hello ProseMirror

This is editable text. You can focus it and start typing.

To apply styling, you can select a piece of text and manipulate
          its styling from the menu. The basic schema
          supports emphasis, strong
          text, links, code
          font, and  images.

Block-level structure can be manipulated with key bindings (try
          ctrl-shift-2 to create a level 2 heading, or enter in an empty
          textblock to exit the parent block), or through the menu.

Try using the "list" item in the menu to wrap this paragraph in
          a numbered list.


text:
<?php

namespace Github\Api\CurrentUser;

use Github\Api\AbstractApi;

/**
 * @link   http://developer.github.com/v3/activity/notifications/
 * @author Joseph Bielawski <stloyd@gmail.com>
 */
class Notifications extends AbstractApi
{
    /**
     * List all notifications for the authenticated user.
     *
     * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications
     *
     * @param array $params
     *
     * @return array
     */
    public function all(array $params = array())
    {
        return $this->get('/notifications', $params);
    }

    /**
     * List all notifications for the authenticated user in selected repository.
     *
     * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
     *
     * @param string $username   the user who owns the repo
     * @param string $repository the name of the repo
     * @param array  $params
     *
     * @return array
     */
    public function allInRepository($username, $repository, array $params = array())
    {
        return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params);
    }

    /**
     * Mark all notifications as read.
     *
     * @link http://developer.github.com/v3/activity/notifications/#mark-as-read
     *
     * @param array $params
     *
     * @return array
     */
    public function markAsReadAll(array $params = array())
    {
        return $this->put('/notifications', $params);
    }

    /**
     * Mark all notifications for a repository as read.
     *
     * @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
     *
     * @param string $username   the user who owns the repo
     * @param string $repository the name of the repo
     * @param array  $params
     *
     * @return array
     */
    public function markAsReadInRepository($username, $repository, array $params = array())
    {
        return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params);
    }

    /**
     * Mark a notification as read.
     *
     * @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
     *
     * @param string $id     the notification number
     * @param array  $params
     *
     * @return array
     */
    public function markAsRead($id, array $params)
    {
        return $this->patch('/notifications/threads/'.rawurlencode($id), $params);
    }

    /**
     * Show a notification.
     *
     * @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread
     *
     * @param string $id the notification number
     *
     * @return array
     */
    public function show($id)
    {
        return $this->get('/notifications/threads/'.rawurlencode($id));
    }

    /**
     * Show a subscription.
     *
     * @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
     *
     * @param string $id the notification number
     *
     * @return array
     */
    public function showSubscription($id)
    {
        return $this->get('/notifications/threads/'.rawurlencode($id).'/subscription');
    }

    /**
     * Create a subscription.
     *
     * @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
     *
     * @param string $id     the notification number
     * @param array  $params
     *
     * @return array
     */
    public function createSubscription($id, array $params)
    {
        return $this->put('/notifications/threads/'.rawurlencode($id).'/subscription', $params);
    }

    /**
     * Delete a subscription.
     *
     * @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
     *
     * @param string $id the notification number
     *
     * @return array
     */
    public function removeSubscription($id)
    {
        return $this->delete('/notifications/threads/'.rawurlencode($id).'/subscription');
    }
}


text:
<!DOCTYPE html><html><head><meta charset="utf-8" />
<meta http-equiv="refresh" content="0;url=/place/central-african-republic/spending/" />
</head></html>


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">CalendarView</string>

</resources>


text:
#include <ucp/core/ucp_mm.h>

#include <ucp/core/ucp_ep.h>
#include <ucp/core/ucp_worker.h>
#include <ucp/core/ucp_context.h>
#include <ucp/dt/dt_contig.h>
#include <ucs/debug/profile.h>

#include <ucp/core/ucp_request.inl>
#include <ucs/datastruct/mpool.inl>
#include <ucp/core/ucp_ep.inl>

#define UCP_RMA_CHECK_PARAMS(_buffer, _length) \
    if ((_length) == 0) { \
        return UCS_OK; \
    } \
    if (ENABLE_PARAMS_CHECK && ((_buffer) == NULL)) { \
        return UCS_ERR_INVALID_PARAM; \
    }

/* request can be released if
 *  - all fragments were sent (length == 0) (bcopy & zcopy mix)
 *  - all zcopy fragments are done (uct_comp.count == 0)
 *  - and request was allocated from the mpool
 *    (checked in ucp_request_complete_send)
 *
 * Request can be released either immediately or in the completion callback.
 * We must check req length in the completion callback to avoid the following
 * scenario:
 *  partial_send;no_resos;progress;
 *  send_completed;cb called;req free(ooops);
 *  next_partial_send; (oops req already freed)
 */
static UCS_F_ALWAYS_INLINE ucs_status_t
ucp_rma_request_advance(ucp_request_t *req, ssize_t frag_length,
                        ucs_status_t status)
{
    if (ucs_likely((status == UCS_OK) || (status == UCS_INPROGRESS))) {
        req->send.length -= frag_length;
        if (req->send.length == 0) {
            /* bcopy is the fast path */
            if (ucs_likely(req->send.uct_comp.count == 0)) {
                if (ucs_unlikely(req->send.state.dt.contig.memh !=
                                 UCT_MEM_HANDLE_NULL)) {
                    ucp_request_send_buffer_dereg(req, req->send.lane);
                }
                ucp_request_complete_send(req, UCS_OK);
            }
            return UCS_OK;
        }
        req->send.buffer          += frag_length;
        req->send.rma.remote_addr += frag_length;
        return UCS_INPROGRESS;
    } else {
        return status;
    }
}

static void ucp_rma_request_bcopy_completion(uct_completion_t *self,
                                             ucs_status_t status)
{
    ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct_comp);

    if (ucs_likely(req->send.length == 0)) {
        ucp_request_complete_send(req, UCS_OK);
    }
}

static void ucp_rma_request_zcopy_completion(uct_completion_t *self,
                                             ucs_status_t status)
{
    ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct_comp);

    if (ucs_likely(req->send.length == 0)) {
        ucp_request_send_buffer_dereg(req, req->send.lane);
        ucp_request_complete_send(req, UCS_OK);
    }
}

static UCS_F_ALWAYS_INLINE ucs_status_t
ucp_rma_request_init(ucp_request_t *req, ucp_ep_h ep, const void *buffer,
                     size_t length, uint64_t remote_addr, ucp_rkey_h rkey,
                     uct_pending_callback_t cb, size_t zcopy_thresh, int flags)
{
    req->flags                = flags; /* Implicit release */
    req->send.ep              = ep;
    req->send.buffer          = buffer;
    req->send.datatype        = ucp_dt_make_contig(1);
    req->send.length          = length;
    req->send.rma.remote_addr = remote_addr;
    req->send.rma.rkey        = rkey;
    req->send.uct.func        = cb;
    req->send.lane            = rkey->cache.rma_lane;
    req->send.uct_comp.count  = 0;
#if ENABLE_ASSERT
    req->send.cb              = NULL;
#endif
    if (length < zcopy_thresh) {
        req->send.uct_comp.func        = ucp_rma_request_bcopy_completion;
        req->send.state.dt.contig.memh = UCT_MEM_HANDLE_NULL;
        return UCS_OK;
    } else {
        req->send.uct_comp.func        = ucp_rma_request_zcopy_completion;
        return ucp_request_send_buffer_reg(req, req->send.lane);
    }
}

static ucs_status_t ucp_progress_put(uct_pending_req_t *self)
{
    ucp_request_t *req              = ucs_container_of(self, ucp_request_t, send.uct);
    ucp_ep_t *ep                    = req->send.ep;
    ucp_rkey_h rkey                 = req->send.rma.rkey;
    ucp_lane_index_t lane           = req->send.lane;
    ucp_ep_rma_config_t *rma_config = &ucp_ep_config(ep)->rma[lane];
    ucs_status_t status;
    ssize_t packed_len;

    ucs_assert(rkey->cache.ep_cfg_index == ep->cfg_index);
    ucs_assert(rkey->cache.rma_lane == lane);

    if (req->send.length <= ucp_ep_config(ep)->bcopy_thresh) {
        packed_len = ucs_min(req->send.length, rma_config->max_put_short);
        status = UCS_PROFILE_CALL(uct_ep_put_short,
                                  ep->uct_eps[lane],
                                  req->send.buffer,
                                  packed_len,
                                  req->send.rma.remote_addr,
                                  rkey->cache.rma_rkey);
    } else if (ucs_likely(req->send.length < rma_config->put_zcopy_thresh)) {
        ucp_memcpy_pack_context_t pack_ctx;
        pack_ctx.src    = req->send.buffer;
        pack_ctx.length = ucs_min(req->send.length, rma_config->max_put_bcopy);
        packed_len = UCS_PROFILE_CALL(uct_ep_put_bcopy,
                                      ep->uct_eps[lane],
                                      ucp_memcpy_pack,
                                      &pack_ctx,
                                      req->send.rma.remote_addr,
                                      rkey->cache.rma_rkey);
        status = (packed_len > 0) ? UCS_OK : (ucs_status_t)packed_len;
    } else {
        uct_iov_t iov;

        /* TODO: leave last fragment for bcopy */
        packed_len = ucs_min(req->send.length, rma_config->max_put_zcopy);
        iov.buffer = (void *)req->send.buffer;
        iov.length = packed_len;
        iov.count  = 1;
        iov.memh   = req->send.state.dt.contig.memh;
        ++req->send.uct_comp.count;

        status = UCS_PROFILE_CALL(uct_ep_put_zcopy,
                                  ep->uct_eps[lane],
                                  &iov, 1,
                                  req->send.rma.remote_addr,
                                  rkey->cache.rma_rkey,
                                  &req->send.uct_comp);
        if (status <= 0) {
            --req->send.uct_comp.count;
        }
    }

    return ucp_rma_request_advance(req, packed_len, status);
}

static ucs_status_t ucp_progress_get(uct_pending_req_t *self)
{
    ucp_request_t *req              = ucs_container_of(self, ucp_request_t, send.uct);
    ucp_ep_t *ep                    = req->send.ep;
    ucp_rkey_h rkey                 = req->send.rma.rkey;
    ucp_lane_index_t lane           = req->send.lane;
    ucp_ep_rma_config_t *rma_config = &ucp_ep_config(ep)->rma[lane];
    ucs_status_t status;
    size_t frag_length;

    ucs_assert(rkey->cache.ep_cfg_index == ep->cfg_index);
    ucs_assert(rkey->cache.rma_lane == lane);

    ++req->send.uct_comp.count;
    if (ucs_likely(req->send.length < rma_config->get_zcopy_thresh)) {
        frag_length = ucs_min(rma_config->max_get_bcopy, req->send.length);
        status = UCS_PROFILE_CALL(uct_ep_get_bcopy,
                                  ep->uct_eps[lane],
                                  (uct_unpack_callback_t)memcpy,
                                  (void*)req->send.buffer,
                                  frag_length,
                                  req->send.rma.remote_addr,
                                  rkey->cache.rma_rkey,
                                  &req->send.uct_comp);
    } else {
        uct_iov_t iov;
        frag_length = ucs_min(req->send.length, rma_config->max_get_zcopy);
        iov.buffer  = (void *)req->send.buffer;
        iov.length  = frag_length;
        iov.count   = 1;
        iov.memh    = req->send.state.dt.contig.memh;

        status = UCS_PROFILE_CALL(uct_ep_get_zcopy,
                                  ep->uct_eps[lane],
                                  &iov, 1,
                                  req->send.rma.remote_addr,
                                  rkey->cache.rma_rkey,
                                  &req->send.uct_comp);
    }
    if (status <= 0) {
        --req->send.uct_comp.count;
    }

    return ucp_rma_request_advance(req, frag_length, status);
}

static UCS_F_ALWAYS_INLINE ucs_status_t
ucp_rma_blocking(ucp_ep_h ep, const void *buffer, size_t length,
                 uint64_t remote_addr, ucp_rkey_h rkey,
                 uct_pending_callback_t progress_cb, size_t zcopy_thresh)
{
    ucs_status_t status;
    ucp_request_t req;

    status = ucp_rma_request_init(&req, ep, buffer, length, remote_addr, rkey,
                                  NULL, zcopy_thresh, 0);
    if (ucs_unlikely(status != UCS_OK)) {
        return status;
    }

    /* Loop until all message has been sent.
     * We re-check the configuration on every iteration except for zcopy,
     * because it can be * changed by transport switch.
     */
    for (;;) {
        /* coverity[callee_ptr_arith] */
        status = progress_cb(&req.send.uct);
        if (ucs_likely(status == UCS_OK)) {
            break;
        } else if (status == UCS_INPROGRESS) {
            continue;
        } else if (status != UCS_ERR_NO_RESOURCE) {
            break;
        } else {
            ucp_worker_progress(ep->worker);
        }
    }

    ucp_request_wait_uct_comp(&req);
    return status;
}

static UCS_F_ALWAYS_INLINE ucs_status_t
ucp_rma_nonblocking(ucp_ep_h ep, const void *buffer, size_t length,
                    uint64_t remote_addr, ucp_rkey_h rkey,
                    uct_pending_callback_t progress_cb, size_t zcopy_thresh)
{
    ucs_status_t status;
    ucp_request_t *req;

    req = ucp_request_get(ep->worker);
    if (req == NULL) {
        return UCS_ERR_NO_MEMORY;
    }

    status = ucp_rma_request_init(req, ep, buffer, length, remote_addr, rkey,
                                  progress_cb, zcopy_thresh,
                                  UCP_REQUEST_FLAG_RELEASED);
    if (ucs_unlikely(status != UCS_OK)) {
        return status;
    }

    return ucp_request_start_send(req);
}

UCS_PROFILE_FUNC(ucs_status_t, ucp_put, (ep, buffer, length, remote_addr, rkey),
                 ucp_ep_h ep, const void *buffer, size_t length,
                 uint64_t remote_addr, ucp_rkey_h rkey)
{
    ucp_ep_rma_config_t *rma_config;
    ucs_status_t status;

    UCP_RMA_CHECK_PARAMS(buffer, length);
    UCP_THREAD_CS_ENTER_CONDITIONAL(&ep->worker->mt_lock);

    status = UCP_RKEY_RESOLVE(rkey, ep, rma);
    if (status != UCS_OK) {
        goto out_unlock;
    }

    if (ucs_likely(length <= rkey->cache.max_put_short)) {
        do {
            /* testing shows that for put message rate it is better to finish
             * put_short here instead of doing it once, getting NO_RESOURCE
             * and continuing to ucp_rma_blocking()
             */
            status = UCS_PROFILE_CALL(uct_ep_put_short, ep->uct_eps[rkey->cache.rma_lane],
                                      buffer, length, remote_addr, rkey->cache.rma_rkey);
            if (ucs_likely(status != UCS_ERR_NO_RESOURCE)) {
                goto out_unlock;
            }

            ucp_worker_progress(ep->worker);

            status = UCP_RKEY_RESOLVE(rkey, ep, rma);
            if (status != UCS_OK) {
                goto out_unlock;
            }
        } while (1);
    }

    rma_config = &ucp_ep_config(ep)->rma[rkey->cache.rma_lane];
    status = ucp_rma_blocking(ep, buffer, length, remote_addr, rkey,
                              ucp_progress_put, rma_config->put_zcopy_thresh);
out_unlock:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&ep->worker->mt_lock);
    return status;
}

UCS_PROFILE_FUNC(ucs_status_t, ucp_get, (ep, buffer, length, remote_addr, rkey),
                 ucp_ep_h ep, void *buffer, size_t length,
                 uint64_t remote_addr, ucp_rkey_h rkey)
{
    ucp_ep_rma_config_t *rma_config;
    ucs_status_t status;

    UCP_RMA_CHECK_PARAMS(buffer, length);
    UCP_THREAD_CS_ENTER_CONDITIONAL(&ep->worker->mt_lock);

    status = UCP_RKEY_RESOLVE(rkey, ep, rma);
    if (status != UCS_OK) {
        goto out_unlock;
    }

    rma_config = &ucp_ep_config(ep)->rma[rkey->cache.rma_lane];
    status = ucp_rma_blocking(ep, buffer, length, remote_addr, rkey,
                              ucp_progress_get, rma_config->get_zcopy_thresh);
out_unlock:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&ep->worker->mt_lock);
    return status;
}

ucs_status_t ucp_put_nbi(ucp_ep_h ep, const void *buffer, size_t length,
                         uint64_t remote_addr, ucp_rkey_h rkey)
{
    ucp_ep_rma_config_t *rma_config;
    ucs_status_t status;

    UCP_RMA_CHECK_PARAMS(buffer, length);
    UCP_THREAD_CS_ENTER_CONDITIONAL(&ep->worker->mt_lock);

    status = UCP_RKEY_RESOLVE(rkey, ep, rma);
    if (status != UCS_OK) {
        goto out_unlock;
    }

    /* Fast path for a single short message */
    if (ucs_likely(length <= rkey->cache.max_put_short)) {
        status = UCS_PROFILE_CALL(uct_ep_put_short, ep->uct_eps[rkey->cache.rma_lane],
                                  buffer, length, remote_addr, rkey->cache.rma_rkey);
        if (ucs_likely(status != UCS_ERR_NO_RESOURCE)) {
            goto out_unlock;
        }
    }

    rma_config = &ucp_ep_config(ep)->rma[rkey->cache.rma_lane];
    status = ucp_rma_nonblocking(ep, buffer, length, remote_addr, rkey,
                                 ucp_progress_put, rma_config->put_zcopy_thresh);
out_unlock:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&ep->worker->mt_lock);
    return status;
}

ucs_status_t ucp_get_nbi(ucp_ep_h ep, void *buffer, size_t length,
                         uint64_t remote_addr, ucp_rkey_h rkey)
{
    ucp_ep_rma_config_t *rma_config;
    ucs_status_t status;

    UCP_RMA_CHECK_PARAMS(buffer, length);
    UCP_THREAD_CS_ENTER_CONDITIONAL(&ep->worker->mt_lock);

    status = UCP_RKEY_RESOLVE(rkey, ep, rma);
    if (status != UCS_OK) {
        goto out_unlock;
    }

    rma_config = &ucp_ep_config(ep)->rma[rkey->cache.rma_lane];
    status = ucp_rma_nonblocking(ep, buffer, length, remote_addr, rkey,
                         ucp_progress_get, rma_config->get_zcopy_thresh);
out_unlock:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&ep->worker->mt_lock);
    return status;
}

UCS_PROFILE_FUNC(ucs_status_t, ucp_worker_fence, (worker), ucp_worker_h worker)
{
    unsigned rsc_index;
    ucs_status_t status;

    UCP_THREAD_CS_ENTER_CONDITIONAL(&worker->mt_lock);

    for (rsc_index = 0; rsc_index < worker->context->num_tls; ++rsc_index) {
        if (worker->ifaces[rsc_index] == NULL) {
            continue;
        }

        status = uct_iface_fence(worker->ifaces[rsc_index], 0);
        if (status != UCS_OK) {
            goto out;
        }
    }
    status = UCS_OK;

out:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&worker->mt_lock);
    return status;
}

UCS_PROFILE_FUNC(ucs_status_t, ucp_worker_flush, (worker), ucp_worker_h worker)
{
    unsigned rsc_index;

    UCP_THREAD_CS_ENTER_CONDITIONAL(&worker->mt_lock);

    while (worker->stub_pend_count > 0) {
        ucp_worker_progress(worker);
    }

    /* TODO flush in parallel */
    for (rsc_index = 0; rsc_index < worker->context->num_tls; ++rsc_index) {
        if (worker->ifaces[rsc_index] == NULL) {
            continue;
        }

        while (uct_iface_flush(worker->ifaces[rsc_index], 0, NULL) != UCS_OK) {
            ucp_worker_progress(worker);
        }
    }

    UCP_THREAD_CS_EXIT_CONDITIONAL(&worker->mt_lock);

    return UCS_OK;
}

UCS_PROFILE_FUNC(ucs_status_t, ucp_ep_flush, (ep), ucp_ep_h ep)
{
    ucp_lane_index_t lane;
    ucs_status_t status;

    UCP_THREAD_CS_ENTER_CONDITIONAL(&ep->worker->mt_lock);

    for (lane = 0; lane < ucp_ep_num_lanes(ep); ++lane) {
        for (;;) {
            status = uct_ep_flush(ep->uct_eps[lane], 0, NULL);
            if (status == UCS_OK) {
                break;
            } else if ((status != UCS_INPROGRESS) && (status != UCS_ERR_NO_RESOURCE)) {
                goto out;
            }
            ucp_worker_progress(ep->worker);
        }
    }

    status = UCS_OK;
out:
    UCP_THREAD_CS_EXIT_CONDITIONAL(&ep->worker->mt_lock);
    return status;
}