~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to tools/gsoap/gsoap-linux-2.7/samples/googleapi/.svn/text-base/googleapi.c.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      Google Web API
2
 
        Compile and run from the command line:
3
 
        googleapi <key> search|cached|spell <arg>
4
 
        where <key> is the Google API license key (see http://www.google.com/apis)
5
 
        Example:
6
 
        googleapi XXXXXXXX search gSOAP
7
 
 
8
 
Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9
 
either express or implied.
10
 
 
11
 
Copyright (C) 2002, Robert A. van Engelen, Florida State University.
12
 
 
13
 
*/
14
 
 
15
 
#include "soapH.h"
16
 
#include "googleapi.nsmap"
17
 
 
18
 
int main(int argc, char **argv)
19
 
{ char *key, *dir, *arg;
20
 
  struct soap soap;
21
 
  soap_init2(&soap, SOAP_IO_DEFAULT, SOAP_XML_TREE);
22
 
  if (argc <= 3)
23
 
  { fprintf(stderr, "Usage: googleapi <key> search|cached|spell <arg>\n");
24
 
    return 0;
25
 
  }
26
 
  key = argv[1];
27
 
  dir = argv[2];
28
 
  arg = argv[3];
29
 
  if (!strcmp(dir, "search"))
30
 
  { struct api__doGoogleSearchResponse r;
31
 
    if (soap_call_api__doGoogleSearch(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, 0, 10, true_, "", false_, "", "latin1", "latin1", &r))
32
 
    { soap_print_fault(&soap, stderr);
33
 
      exit(1);
34
 
    }
35
 
    else
36
 
    { int i;
37
 
      printf("documentFiltering          = %d\n", (int)r._return.documentFiltering);
38
 
      printf("searchQuery                = %s\n", r._return.searchQuery?r._return.searchQuery:"<NONE>");
39
 
      printf("searchComments             = %s\n", r._return.searchComments?r._return.searchComments:"<NONE>");
40
 
      printf("searchTips                 = %s\n", r._return.searchTips);
41
 
      printf("searchTime                 = %f\n", r._return.searchTime);
42
 
      printf("estimatedTotalResultsCount = %d\n", r._return.estimatedTotalResultsCount);
43
 
      printf("estimateIsExact            = %d\n", (int)r._return.estimateIsExact);
44
 
      printf("startIndex                 = %d\n", r._return.startIndex);
45
 
      printf("endIndex                   = %d\n", r._return.endIndex);
46
 
      printf("resultElements             = \n");
47
 
      for (i = 0; i < r._return.resultElements.__size; i++)
48
 
      { const char *s1 = r._return.resultElements.__ptr[i].summary;
49
 
        const char *s2 = r._return.resultElements.__ptr[i].URL;
50
 
        const char *s3 = r._return.resultElements.__ptr[i].snippet;
51
 
        const char *s4 = r._return.resultElements.__ptr[i].title;
52
 
        const char *s5 = r._return.resultElements.__ptr[i].cachedSize;
53
 
        const char *s6 = r._return.resultElements.__ptr[i].directoryTitle;
54
 
        /* skipped printing of directoryCategory field */
55
 
        printf("[%3d]\tSummary        = %s\n", i+1, s1?s1:"<NONE>");
56
 
        printf("\ttitle          = %s\n", s4?s4:"<NONE>");
57
 
        printf("\tURL            = %s\n", s2?s2:"<NONE>");
58
 
        printf("\tsnippet        = %s\n", s3?s3:"<NONE>");
59
 
        printf("\tcachedSize     = %s\n", s5?s5:"<NONE>");
60
 
        printf("\trelatedInfo    = %d\n", (int)r._return.resultElements.__ptr[i].relatedInformationPresent);
61
 
        printf("\tdirectoryTitle = %s\n", s6?s6:"<NONE>");
62
 
      }
63
 
      printf("directoryCategories      = \n");
64
 
      for (i = 0; i < r._return.directoryCategories.__size; i++)
65
 
      { const char *s1 = r._return.directoryCategories.__ptr[i].fullViewableName;
66
 
        const char *s2 = r._return.directoryCategories.__ptr[i].specialEncoding;
67
 
        printf("\t%s\t%s\n", s1?s1:"<NONE>", s2?s2:"<NONE>");
68
 
      }
69
 
    }
70
 
  }
71
 
  else if (!strcmp(dir, "cached"))
72
 
  { struct xsd__base64Binary r;
73
 
    if (soap_call_api__doGetCachedPage(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, &r))
74
 
    { soap_print_fault(&soap, stderr);
75
 
      exit(1);
76
 
    }
77
 
    else
78
 
    { int i;
79
 
      for (i = 0; i < r.__size; i++)
80
 
        putchar(r.__ptr[i]);
81
 
      putchar('\n');
82
 
    }
83
 
  }
84
 
  else if (!strcmp(dir, "spell"))
85
 
  { char *r;
86
 
    if (soap_call_api__doSpellingSuggestion(&soap, "http://api.google.com/search/beta2", "urn:GoogleSearchAction", key, arg, &r))
87
 
    { soap_print_fault(&soap, stderr);
88
 
      exit(1);
89
 
    }
90
 
    else
91
 
      printf("Suggested spelling: %s\n", r?r:"<NONE>");
92
 
  }
93
 
  else
94
 
    fprintf(stderr, "Unknown directive\n");
95
 
  soap_end(&soap); /* remove all temporary and deserialized data */
96
 
  soap_done(&soap);
97
 
  return 0;
98
 
}