~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to dttools/src/catalog_query.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#include "catalog_query.h"
 
9
#include "catalog_server.h"
 
10
 
 
11
#include "http_query.h"
 
12
#include "nvpair.h"
 
13
#include "xmalloc.h"
 
14
#include "stringtools.h"
 
15
 
 
16
#define QUERY "GET HTTP/1.0 /query.text\n\n"
 
17
 
 
18
struct catalog_query {
 
19
        struct link *link;
 
20
};
 
21
 
 
22
struct catalog_query * catalog_query_create( const char *host, int port, time_t stoptime )
 
23
{
 
24
        struct catalog_query *q = xxmalloc(sizeof(*q));
 
25
        char url[1024];
 
26
 
 
27
        if(!host) host = CATALOG_HOST;
 
28
        if(!port) port = CATALOG_PORT;
 
29
 
 
30
        sprintf(url,"http://%s:%d/query.text",host,port);
 
31
 
 
32
        q->link = http_query(url,"GET",stoptime);
 
33
        if(!q->link) {
 
34
                free(q);
 
35
                return 0;
 
36
        }
 
37
 
 
38
        return q;
 
39
}
 
40
 
 
41
struct nvpair * catalog_query_read( struct catalog_query *q, time_t stoptime )
 
42
{
 
43
        struct nvpair *nv = nvpair_create();
 
44
        char line[65536];
 
45
        int lines = 0;
 
46
 
 
47
        while(link_readline(q->link,line,sizeof(line),stoptime)) {
 
48
                string_chomp(line);
 
49
                if(!line[0]) break;
 
50
                nvpair_parse(nv,line);
 
51
                lines++;
 
52
        }
 
53
 
 
54
        if(lines) {
 
55
                return nv;
 
56
        } else {
 
57
                nvpair_delete(nv);
 
58
                return 0;
 
59
        }
 
60
}
 
61
 
 
62
void catalog_query_delete( struct catalog_query *q )
 
63
{
 
64
        link_close(q->link);
 
65
        free(q);
 
66
}
 
67