/**
 * We could have put the \p content into a TraciMessage and call the other
 * send_command but that would require another copy operation, so, we avoid
 * that.
 */
void TraCIClient::send_command( CommandId command,
                                const traci::TraciType & content,
                                TraciMessage & answer ) const
throw( tcpip::SocketException )
{
    Storage out;
    writeCommandHead(command, content.getLength(), out);

    // write content
    content.write(out);

    do_send_command(command, out, answer);
}
/**
 *  see http://sourceforge.net/apps/mediawiki/sumo/index.php?title=TraCI/Protocol
 *
 *  For historical reasons subfunctions might call \c abort() in case of problems
 *  after sending a message to \c stderr instead of throwing an exception.
 *
 *  \param[in]  command         TraCI command ID to send
 *  \param[in]  content         part of TraCI command after the command ID
 *  \param[out] answer          TraciMessage for command answer, position will
 *                              be set behind status response at first answer command
 */
void TraCIClient::send_command( CommandId command,
                                TraciMessage & content,
                                TraciMessage & answer ) const
throw(SocketException)
{
    Storage out;
    writeCommandHead(command, content.size(), out);

    // write content
    out.writeStorage(content);

    do_send_command(command, out, answer);
}
int do_psync_account_stopshare(psync_shareid_t usershareids[], int nusershareid, psync_shareid_t teamshareids[], int nteamshareid, char **err) {
 psync_socket *api;
  binresult *bres;
  uint64_t result,userresult,teamresult;
  char *ids1 = NULL;
  char *ids2 = NULL;
  char *idsp = 0;
  int i,pind = 1, numparam = 1,k;
  binparam *t;
  const binresult *userres, *teamres, *statres;
  *err  = 0;
  
  numparam +=  !!nusershareid + !!nteamshareid;
  if (unlikely(numparam == 1))
    return -3;
    
  t = (binparam *) psync_malloc(numparam*sizeof(binparam));
  
  init_param_str(t, "auth", psync_my_auth);
  
  if (nusershareid) {
    ids1 = (char *) psync_malloc(nusershareid*FOLDERID_ENTRY_SIZE);
    idsp = ids1;
    for (i = 0; i < nusershareid; ++i) {
      k = sprintf(idsp, "%lld",(long long) usershareids[i]);
      if (unlikely(k <= 0 )) break;
      idsp[k] = ',';
      idsp = idsp + k + 1;
    }
    if (i > 0)
      *(idsp - 1) = '\0';
    //debug(D_NOTICE, "usershareids %s",ids1);
    init_param_str(t + pind++, "usershareids", ids1);
  }
  
  if (nteamshareid) {
    ids2 = (char *) psync_malloc(nteamshareid*FOLDERID_ENTRY_SIZE);
    idsp = ids2;
    for (i = 0; i < nteamshareid; ++i) {
      k = sprintf(idsp, "%lld", (long long) teamshareids[i]);
      if (unlikely(k <= 0 )) break;
      idsp[k] = ',';
      idsp = idsp + k + 1;
    }
    if (i > 0)
      *(idsp - 1) = '\0';
    //debug(D_NOTICE, "teamshareids %s",ids2);
    init_param_str(t + pind++, "teamshareids", ids2);
  }
  
  api=psync_apipool_get();
  if (unlikely(!api)) {
    debug(D_WARNING, "Can't gat api from the pool. No pool ?\n");
    return -2;
  }
  
  bres =  do_send_command(api, "account_stopshare", sizeof("account_stopshare") - 1, t, pind, -1, 1);
  
  if (likely(bres))
    psync_apipool_release(api);
  else {
    psync_apipool_release_bad(api);
    debug(D_WARNING, "Send command returned in valid result.\n");
    return -2;
  }
  
  result=psync_find_result(bres, "result", PARAM_NUM)->num;
  if (unlikely(result))
    return handle_result(bres, result, err);
 
  statres = psync_find_result(bres, "status", PARAM_HASH);
  teamres = psync_find_result(statres, "team", PARAM_ARRAY)->array[0];
  teamresult = psync_find_result(teamres, "result", PARAM_NUM)->num;
  userres = psync_find_result(statres, "user", PARAM_ARRAY)->array[0];
  userresult = psync_find_result(userres, "result", PARAM_NUM)->num;
  if (!userresult || !teamresult)
    result = 0;
  else {
    if(userresult == INVALID_SHAREDID_RESULT && teamresult == INVALID_SHAREDID_RESULT)
      result = handle_result(userres, userresult, err); 
    else if (userresult)
      result = handle_result(userres, userresult, err); 
    else 
      result = handle_result(teamres, teamresult, err); 
  }
  
  if (ids1)
    psync_free(ids1);
  if (ids2)
    psync_free(ids2);
  
  psync_free(bres);
  psync_free(t);
  
  return result;
  
}