Ejemplo n.º 1
0
static void
ask_password_cb (GMountOperation *op,
                 const char      *message,
                 const char      *default_user,
                 const char      *default_domain,
                 GAskPasswordFlags flags)
{
  char *s;
  g_print ("%s\n", message);

  if (flags & G_ASK_PASSWORD_NEED_USERNAME)
    {
      s = prompt_for ("User", default_user, TRUE);
      g_mount_operation_set_username (op, s);
      g_free (s);
    }

  if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
    {
      s = prompt_for ("Domain", default_domain, TRUE);
      g_mount_operation_set_domain (op, s);
      g_free (s);
    }

  if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
    {
      s = prompt_for ("Password", NULL, FALSE);
      g_mount_operation_set_password (op, s);
      g_free (s);
    }

  g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
}
Ejemplo n.º 2
0
void
prompt_for_block_item_topic(std::string *pblock, 
                            std::string *pitem, 
                            std::string *ptopic,
                            CommandCtx *ctx)
{
    prompt_for("block", pblock, ctx);
    prompt_for("item", pitem, ctx);    
    prompt_for("topic", ptopic, ctx);
}
Ejemplo n.º 3
0
bool 
prompt_for_cpp(CommandCtx *ctx, int recurse) /*recurse=2*/
{
    std::string cpp_y_or_n;

    language l = get_default_language();

    if(l == language::c) 
        return false;
        
    if(l == language::cpp)
        return true;            

    prompt_for("use C++ version? (y/n)", &cpp_y_or_n, ctx);

    if(cpp_y_or_n == "y")
        return true;
    else if(cpp_y_or_n == "n")
        return false;
    else if(recurse > 0){
        std::cout<< "INVALID - enter 'y' or 'n'" << std::endl;
        return prompt_for_cpp(ctx, recurse-1);
    }else{
        std::cout<< "INVALID - defaulting to C version" << std::endl;
        return false;
    }
}
Ejemplo n.º 4
0
size_type 
get_cstr_entries(std::string label, char ***pstrs, CommandCtx *ctx)
{  
    std::string nentry;
    std::string item;

    prompt_for("# " + label + "s", &nentry, ctx);    

    unsigned long n = 0;
    try{
        n = std::stoul(nentry);
    }catch(...){
        std::cerr<< std::endl << "INVALID INPUT" << std::endl << std::endl;
        *pstrs = nullptr;
        return 0;
    }

    try{
        *pstrs = NewStrings(n, TOSDB_MAX_STR_SZ);

        for(size_type i = 0; i < n; ++i){
            prompt_b<< ctx->name;
            prompt<< label << "(" << (i+1) << ") " >> item;        
            strcpy_s((*pstrs)[i], item.length() + 1, item.c_str());
        }
    }catch(...){
        DeleteStrings(*pstrs, n);
        *pstrs = nullptr;
        return 0;
    }

    return n;
}
Ejemplo n.º 5
0
void
prompt_for_block_item_topic_index(std::string *pblock, 
                                  std::string *pitem, 
                                  std::string *ptopic, 
                                  std::string *pindex, 
                                  CommandCtx *ctx)
{
    prompt_for_block_item_topic(pblock, pitem, ptopic, ctx);
    prompt_for("index", pindex, ctx); 
}
Ejemplo n.º 6
0
bool 
prompt_for_datetime(std::string block, CommandCtx *ctx)
{
    std::string dts_y_or_n;
  
    if( !TOSDB_IsUsingDateTime(block) )
        return false;          
   
    prompt_for("get datetime stamp? (y/n)", &dts_y_or_n, ctx);
                    
    if(dts_y_or_n == "y")
        return true;
    else if(dts_y_or_n != "n")              
        std::cout<< "INVALID - default to NO datetime" << std::endl;

    return false;    
}
Ejemplo n.º 7
0
static void
ask_question_cb (GMountOperation *op,
                 char *message,
                 char **choices,
                 gpointer user_data)
{
  char **ptr = choices;
  char *s;
  int i, choice;

  g_print ("%s\n", message);

  i = 1;
  while (*ptr)
    {
      g_print ("[%d] %s\n", i, *ptr++);
      i++;
    }

  s = prompt_for ("Choice", NULL, TRUE);
  if (!s)
    goto error;

  choice = atoi (s);
  if (choice > 0 && choice < i)
    {
      g_mount_operation_set_choice (op, choice - 1);
      g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
    }
  g_free (s);

  return;

error:
  g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
}
Ejemplo n.º 8
0
static void
ask_password_cb (GMountOperation *op,
                 const char      *message,
                 const char      *default_user,
                 const char      *default_domain,
                 GAskPasswordFlags flags)
{
  if ((flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) && anonymous)
    {
      g_mount_operation_set_anonymous (op, TRUE);
    }
  else
    {
      char *s;
      g_print ("%s\n", message);

      if (flags & G_ASK_PASSWORD_NEED_USERNAME)
        {
          s = prompt_for ("User", default_user, TRUE);
          if (!s)
            goto error;
          g_mount_operation_set_username (op, s);
          g_free (s);
        }

      if (flags & G_ASK_PASSWORD_NEED_DOMAIN)
        {
          s = prompt_for ("Domain", default_domain, TRUE);
          if (!s)
            goto error;
          g_mount_operation_set_domain (op, s);
          g_free (s);
        }

      if (flags & G_ASK_PASSWORD_NEED_PASSWORD)
        {
          s = prompt_for ("Password", NULL, FALSE);
          if (!s)
            goto error;
          g_mount_operation_set_password (op, s);
          g_free (s);
        }
    }

  /* Only try anonymous access once. */
  if (anonymous &&
      GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ASKED)
    {
      g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ABORTED));
      g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
    }
  else
    {
      g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ASKED));
      g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
    }

  return;

error:
  g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
}