Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

void DNSTest::Main (  ) [virtual]

User override function for the main execution routine of the thread. A descendent class must provide the code that will be executed in the thread within this function.

Note that the correct way for a thread to terminate is to return from this function.

Implements PThread.

Definition at line 107 of file main.cxx.

References PProcess::GetArguments(), PArgList::GetCount(), PIPSocket::GetHostAddress(), PURL::GetHostName(), PArgList::GetOptionString(), PURL::GetPort(), PURL::GetScheme(), PURL::GetUserName(), PArgList::HasOption(), and PArgList::Parse().

{
  PArgList & args = GetArguments();

  args.Parse("t:u.");

  if (args.GetCount() < 1) {
    Usage();
    return;
  }

  if (args.HasOption('u')) {
    if (args.GetCount() < 0) {
      Usage();
      return;
    }

    PURL url(args[0]);
    if (url.GetScheme() *= "h323") {
      PString user   = url.GetUserName();
      PString domain = url.GetHostName();
      WORD    port   = url.GetPort();
      cout << "user = " << user << ", domain = " << domain << ", port = " << port << endl;

      std::vector<LookupRecord> found;

      BOOL hasGK = FindSRVRecords(found, domain, "LRQ",         "_h323ls._udp.");
      hasGK = hasGK || FindSRVRecords(found, domain, "LRQ",         "_h323rs._udp.");
      FindSRVRecords(found, domain, "Call direct", "_h323cs._tcp.");

      // if no entries so far, see if the domain is actually a host
      if (found.size() == 0) {
        PIPSocket::Address addr;
        if (PIPSocket::GetHostAddress(domain, addr)) {
          LookupRecord rec;
          rec.addr = addr;
          rec.port = 1720;
          rec.type = "Call direct";
          rec.source = "DNS";
          found.push_back(rec);
        }
      }

      if (!hasGK) {
        PDNS::MXRecordList mxRecords;
        if (PDNS::GetRecords(domain, mxRecords)) {
          PDNS::MXRecord * recPtr = mxRecords.GetFirst();
          while (recPtr != NULL) {
            LookupRecord rec;
            rec.addr = recPtr->hostAddress;
            rec.port = 1719;
            rec.type = "LRQ";
            rec.source = "MX";
            found.push_back(rec);
            recPtr = mxRecords.GetNext();
          }
        } 
      }

      if (found.size() == 0) {
        PError << "Cannot find match" << endl;
      }
      else
      {
        std::vector<LookupRecord>::const_iterator r;
        cout << "Found\n";
        for (r = found.begin(); r != found.end(); ++r) {
          cout << *r << endl;
        }
      }
    }
    else {
      PError << "error: unsupported scheme " << url.GetScheme() << endl;
    }
  }

  else if (args.HasOption('t')) {
    PString type = args.GetOptionString('t');
    if (type *= "SRV") 
      GetAndDisplayRecords<PDNS::SRVRecordList>(args[0]);

    else if (type *= "MX")
      GetAndDisplayRecords<PDNS::MXRecordList>(args[0]);

    else if (type *= "NAPTR") {
      if (args.GetCount() == 1)
        GetAndDisplayRecords<PDNS::NAPTRRecordList>(args[0]);
      else {
        PDNS::NAPTRRecordList records;
        if (!PDNS::GetRecords(args[0], records))
          PError << "Lookup for " << args[0] << " failed" << endl;
        else {
          cout << "Returned " << endl;
          PDNS::NAPTRRecord * rec = records.GetFirst(args[1]);
          while (rec != NULL) {
            cout << *rec;
            rec = records.GetNext(args[1]);
          }
        }
      }
    }

    else if (type *= "enum") {
      if (args.GetCount() < 2)
        Usage();
      else {
        PString e164    = args[0];
        PString service = args[1];
        PString str;
        if (!PDNS::ENUMLookup(e164, service, str))
          cout << "Could not resolve E164 number " << e164 << " with service " << service << endl;
        else
          cout << "E164 number " << e164 << " with service " << service << " resolved to " << str << endl;
      }
    }
  }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index