예제 #1
0
/* Debug function to print the entire hosttable.  */
gpg_error_t
ks_hkp_print_hosttable (ctrl_t ctrl)
{
  gpg_error_t err;
  int idx, idx2;
  hostinfo_t hi;
  membuf_t mb;
  time_t curtime;
  char *p, *died;
  const char *diedstr;

  err = ks_print_help (ctrl, "hosttable (idx, ipv6, ipv4, dead, name, time):");
  if (err)
    return err;

  /* FIXME: We need a lock for the hosttable.  */
  curtime = gnupg_get_time ();
  for (idx=0; idx < hosttable_size; idx++)
    if ((hi=hosttable[idx]))
      {
        if (hi->dead && hi->died_at)
          {
            died = elapsed_time_string (hi->died_at, curtime);
            diedstr = died? died : "error";
          }
        else
          diedstr = died = NULL;

        if (!hi->iporname_valid)
          {
            char *canon = NULL;

            xfree (hi->iporname);
            hi->iporname = NULL;

            /* Do a lookup just for the display purpose.  */
            if (hi->onion || hi->pool)
              ;
            else if (is_ip_address (hi->name))
              {
                dns_addrinfo_t aibuf, ai;

                /* Turn the numerical IP address string into an AI and
                 * then do a DNS PTR lookup.  */
                if (!resolve_dns_name (hi->name, 0, 0,
                                       SOCK_STREAM,
                                       &aibuf, &canon))
                  {
                    if (canon && is_ip_address (canon))
                      {
                        xfree (canon);
                        canon = NULL;
                      }
                    for (ai = aibuf; !canon && ai; ai = ai->next)
                      {
                        resolve_dns_addr (ai->addr, ai->addrlen,
                                          DNS_WITHBRACKET, &canon);
                        if (canon && is_ip_address (canon))
                          {
                            /* We already have the numeric IP - no need to
                             * display it a second time.  */
                            xfree (canon);
                            canon = NULL;
                          }
                      }
                  }
                free_dns_addrinfo (aibuf);
              }
            else
              {
                dns_addrinfo_t aibuf, ai;

                /* Get the IP address as a string from a name.  Note
                 * that resolve_dns_addr allocates CANON on success
                 * and thus terminates the loop. */
                if (!resolve_dns_name (hi->name, 0,
                                       hi->v6? AF_INET6 : AF_INET,
                                       SOCK_STREAM,
                                       &aibuf, NULL))
                  {
                    for (ai = aibuf; !canon && ai; ai = ai->next)
                      {
                        resolve_dns_addr (ai->addr, ai->addrlen,
                                          DNS_NUMERICHOST|DNS_WITHBRACKET,
                                          &canon);
                      }
                  }
                free_dns_addrinfo (aibuf);
              }

            hi->iporname = canon;
            hi->iporname_valid = 1;
          }

        err = ks_printf_help (ctrl, "%3d %s %s %s %s%s%s%s%s%s%s\n",
                              idx,
                              hi->onion? "O" : hi->v6? "6":" ",
                              hi->v4? "4":" ",
                              hi->dead? "d":" ",
                              hi->name,
                              hi->iporname? " (":"",
                              hi->iporname? hi->iporname : "",
                              hi->iporname? ")":"",
                              diedstr? "  (":"",
                              diedstr? diedstr:"",
                              diedstr? ")":""   );
        xfree (died);
        if (err)
          return err;

        if (hi->cname)
          err = ks_printf_help (ctrl, "  .       %s", hi->cname);
        if (err)
          return err;

        if (hi->pool)
          {
            init_membuf (&mb, 256);
            put_membuf_printf (&mb, "  .   -->");
            for (idx2 = 0; idx2 < hi->pool_len && hi->pool[idx2] != -1; idx2++)
              {
                put_membuf_printf (&mb, " %d", hi->pool[idx2]);
                if (hi->poolidx == hi->pool[idx2])
                  put_membuf_printf (&mb, "*");
              }
            put_membuf( &mb, "", 1);
            p = get_membuf (&mb, NULL);
            if (!p)
              return gpg_error_from_syserror ();
            err = ks_print_help (ctrl, p);
            xfree (p);
            if (err)
              return err;
          }
      }
  return 0;
}
예제 #2
0
/* Debug function to print the entire hosttable.  */
gpg_error_t
ks_hkp_print_hosttable (ctrl_t ctrl)
{
  gpg_error_t err;
  int idx, idx2;
  hostinfo_t hi;
  membuf_t mb;
  time_t curtime;
  char *p, *died;
  const char *diedstr;

  err = ks_print_help (ctrl, "hosttable (idx, ipv6, ipv4, dead, name, time):");
  if (err)
    return err;

  curtime = gnupg_get_time ();
  for (idx=0; idx < hosttable_size; idx++)
    if ((hi=hosttable[idx]))
      {
        if (hi->dead && hi->died_at)
          {
            died = elapsed_time_string (hi->died_at, curtime);
            diedstr = died? died : "error";
          }
        else
          diedstr = died = NULL;
        err = ks_printf_help (ctrl, "%3d %s %s %s %s%s%s%s%s%s%s%s\n",
                              idx, hi->v6? "6":" ", hi->v4? "4":" ",
                              hi->dead? "d":" ",
                              hi->name,
                              hi->v6addr? " v6=":"",
                              hi->v6addr? hi->v6addr:"",
                              hi->v4addr? " v4=":"",
                              hi->v4addr? hi->v4addr:"",
                              diedstr? "  (":"",
                              diedstr? diedstr:"",
                              diedstr? ")":""   );
        xfree (died);
        if (err)
          return err;

        if (hi->cname)
          err = ks_printf_help (ctrl, "  .       %s", hi->cname);
        if (err)
          return err;

        if (hi->pool)
          {
            init_membuf (&mb, 256);
            put_membuf_printf (&mb, "  .   -->");
            for (idx2=0; hi->pool[idx2] != -1; idx2++)
              {
                put_membuf_printf (&mb, " %d", hi->pool[idx2]);
                if (hi->poolidx == hi->pool[idx2])
                  put_membuf_printf (&mb, "*");
              }
            put_membuf( &mb, "", 1);
            p = get_membuf (&mb, NULL);
            if (!p)
              return gpg_error_from_syserror ();
            err = ks_print_help (ctrl, p);
            xfree (p);
            if (err)
              return err;
          }
      }
  return 0;
}
예제 #3
0
파일: pdump.c 프로젝트: anylonen/omega
short dump_basic( FILE *dumpfile )
{
  int curcol;
  long total_balance;
  char *cp;
  bank_account *account;
	
  /* reset "checksum" */
  dumpcheck = 0;

  strcpy( dump_buf, "[*] " );
  strcat( dump_buf, VERSIONSTRING );
  strcat( dump_buf, " character dump [*]\n\n" );
  if ( !dump( dumpfile, dump_buf, FALSE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Name      : %s\n", Player.name );
  if ( gamestatusp( CHEATED ) )
    {
      if ( 72 > strlen( dump_buf ) )
        cp = strrchr( dump_buf, '\n' );
      else
        cp = &(dump_buf[ 70 ]);
      strcpy( cp, " (WIZARD)\n" );
    }
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  sprintf( dump_buf, "Level     : %s [%d]\n", levelname( Player.level ), Player.level );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  sprintf( dump_buf, "Alignment : %s\n\n", alignment_string( Player.alignment ) );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
	
  /*
    sprintf( dump_buf, "Str : %5d [%d]%n%*sHP       : %5d [%d]%n%*sHit     : %d\n",
    Player.str, Player.maxstr, &curcol, 26 - curcol, spaces,
    Player.hp,  Player.maxhp,  &curcol, 57 - curcol, spaces,
    Player.hit );
    if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
  */
		
  curcol = sprintf( dump_buf, "Str : %5d [%d]", Player.str, Player.maxstr );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 26; curcol++ )
    *cp++ = ' ';
  curcol += sprintf( cp, "HP       : %5d [%d]", Player.hp,  Player.maxhp );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 57; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Hit     : %d\n", Player.hit );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Con : %5d [%d]", Player.con, Player.maxcon );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 26; curcol++ )
    *cp++ = ' ';
  curcol += sprintf( cp, "Mana     : %5ld [%ld]", Player.mana,  Player.maxmana );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 57; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Damage  : %d\n", Player.dmg );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Dex : %5d [%d]", Player.dex, Player.maxdex );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 57; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Defense : %d\n", Player.defense );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Agi : %5d [%d]", Player.agi, Player.maxagi );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 26; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Exp      : %-10ld          Armor   : %d\n", Player.xp,  Player.absorption );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Int : %5d [%d]", Player.iq, Player.maxiq );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 26; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Carry    : %-10d          Speed   : %d.%d\n",
           Player.itemweight, 5 / Player.speed, 500 / Player.speed % 100 );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  curcol = sprintf( dump_buf, "Pow : %5d [%d]", Player.pow, Player.maxpow );
  cp = strrchr( dump_buf, '\0' );
  for ( ; curcol < 26; curcol++ )
    *cp++ = ' ';
  sprintf( cp, "Capacity : %d\n\n", Player.maxweight );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  total_balance = 0;
  for( account = bank; account; account = account->next_account )
    {
      if ( account->player )
        total_balance += account->balance;
    }
		
  sprintf( dump_buf, "Cash (carried/bank) : %ld / %ld\n", Player.cash, total_balance );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  sprintf( dump_buf, "Current Point Total : %ld\n", calc_points() );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  sprintf( dump_buf, "Elapsed Game Time   : %s\n\n", elapsed_time_string( Time ) );
  if ( !dump( dumpfile, dump_buf, TRUE ) )
    return FALSE;
		
  sprintf( dump_buf, "[Verification: %8.8lx]\n\n", dumpcheck );
  if ( !dump( dumpfile, dump_buf, FALSE ) )
    return FALSE;
		
  return TRUE;
}