"Fossies" - the Fresh Open Source Software Archive

Member "links-1.03/finger.c" (16 Oct 2011, 2095 Bytes) of archive /linux/www/links-1.03.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "finger.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8_vs_1.03.

    1 /* finger.c
    2  * finger:// processing
    3  * (c) 2002 Mikulas Patocka
    4  * This file is a part of the Links program, released under GPL.
    5  */
    6 
    7 #include "links.h"
    8 
    9 static void finger_send_request(struct connection *);
   10 static void finger_sent_request(struct connection *);
   11 static void finger_get_response(struct connection *, struct read_buffer *);
   12 static void finger_end_request(struct connection *);
   13 
   14 void finger_func(struct connection *c)
   15 {
   16     int p;
   17     if ((p = get_port(c->url)) == -1) {
   18         setcstate(c, S_INTERNAL);
   19         abort_connection(c);
   20         return;
   21     }
   22     c->from = 0;
   23     make_connection(c, p, &c->sock1, finger_send_request);
   24 }
   25 
   26 static void finger_send_request(struct connection *c)
   27 {
   28     unsigned char *req = init_str();
   29     int rl = 0;
   30     unsigned char *user;
   31     add_to_str(&req, &rl, "/W");
   32     if ((user = get_user_name(c->url))) {
   33         add_to_str(&req, &rl, " ");
   34         add_to_str(&req, &rl, user);
   35         mem_free(user);
   36     }
   37     add_to_str(&req, &rl, "\r\n");
   38     write_to_socket(c, c->sock1, req, rl, finger_sent_request);
   39     mem_free(req);
   40     setcstate(c, S_SENT);
   41 }
   42 
   43 static void finger_sent_request(struct connection *c)
   44 {
   45     struct read_buffer *rb;
   46     set_timeout(c);
   47     if (!(rb = alloc_read_buffer(c))) return;
   48     rb->close = 1;
   49     read_from_socket(c, c->sock1, rb, finger_get_response);
   50 }
   51 
   52 static void finger_get_response(struct connection *c, struct read_buffer *rb)
   53 {
   54     int l;
   55     set_timeout(c);
   56     if (get_cache_entry(c->url, &c->cache)) {
   57         setcstate(c, S_OUT_OF_MEM);
   58         abort_connection(c);
   59         return;
   60     }
   61     c->cache->refcount--;
   62     if (rb->close == 2) {
   63         setcstate(c, S_OK);
   64         finger_end_request(c);
   65         return;
   66     }
   67     l = rb->len;
   68     if ((off_t)(0UL + c->from + l) < 0) {
   69         setcstate(c, S_LARGE_FILE);
   70         abort_connection(c);
   71         return;
   72     }
   73     c->received += l;
   74     if (add_fragment(c->cache, c->from, rb->data, l) == 1) c->tries = 0;
   75     c->from += l;
   76     kill_buffer_data(rb, l);
   77     read_from_socket(c, c->sock1, rb, finger_get_response);
   78     setcstate(c, S_TRANS);
   79 }
   80 
   81 static void finger_end_request(struct connection *c)
   82 {
   83     if (c->state == S_OK) {
   84         if (c->cache) {
   85             truncate_entry(c->cache, c->from, 1);
   86             c->cache->incomplete = 0;
   87         }
   88     }
   89     abort_connection(c);
   90 }