Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (88 sloc) 2.992 kb
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
1 #pragma once
2
9f0cff1 Initial commit.
Sound and Fury authored
3 /*
3fcb080 Enable many warnings & fix them
ec429 authored
4 quIRC - simple terminal-based IRC client
4e3364b @ec429 Nudge copyright year to 2013
authored
5 Copyright (C) 2010-13 Edward Cree
3fcb080 Enable many warnings & fix them
ec429 authored
6
9f0cff1 Initial commit.
Sound and Fury authored
7 See quirc.c for license information
8 irc: networking functions
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdbool.h>
14 #include <string.h>
15 #include <unistd.h>
8844d52 Fix various compile errors in prev. commit
Sound and Fury authored
16 #include <fcntl.h>
556a521 Functions for irc-style casemapping
Sound and Fury authored
17 #include <ctype.h>
9f0cff1 Initial commit.
Sound and Fury authored
18 #include <sys/socket.h>
19 #include <sys/utsname.h>
9a76983 New cmd /ping, sends a CTCP ping. Also, handling of responses
ec429 authored
20 #include <sys/time.h>
9f0cff1 Initial commit.
Sound and Fury authored
21 #include <netdb.h>
22 #include <arpa/inet.h>
23 #include <netinet/in.h>
5bd9397 Asynchronous connect(), fixes, and liveness (unfinished)
Sound and Fury authored
24 #include <errno.h>
417d27e Handle SIGPIPE
Sound and Fury authored
25 #include <signal.h>
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
26
bdca1e0 More correct casemapping handling (doesn't yet detect from RPL_ISUPPORT)
Sound and Fury authored
27 typedef enum
28 {
29 RFC1459,
30 STRICT_RFC1459,
31 ASCII
32 }
33 cmap;
34
61b2658 irc_breakdown() function, parses :prefix cmd args...
Sound and Fury authored
35 typedef struct
36 {
37 char *prefix;
38 char *cmd;
39 int nargs;
40 char *args[15]; // RFC specifies maximum of 15 args
41 }
42 message;
43
29252b6 More refactoring; chopping up quirc.c. '#pragma once'-ing headers
Sound and Fury authored
44 #include "colour.h"
bdca1e0 More correct casemapping handling (doesn't yet detect from RPL_ISUPPORT)
Sound and Fury authored
45 #include "names.h"
b7319a8 Asynch name lookups
ec429 authored
46 #include "osconf.h"
9f0cff1 Initial commit.
Sound and Fury authored
47
bfdcd84 Handle Low-Level Quoting
Sound and Fury authored
48 #define MQUOTE '\020'
49
b7319a8 Asynch name lookups
ec429 authored
50 volatile sig_atomic_t sigpipe, sigwinch, sigusr1;
417d27e Handle SIGPIPE
Sound and Fury authored
51
b7319a8 Asynch name lookups
ec429 authored
52 void handle_signals(int); // handles sigpipe, sigwinch and sigusr1
417d27e Handle SIGPIPE
Sound and Fury authored
53
b7319a8 Asynch name lookups
ec429 authored
54 #if ASYNCH_NL
ecc567b Further reworking of asynch NL
ec429 authored
55 typedef struct _nl_list
56 {
57 struct gaicb *nl_details;
58 int reconn_b;
59 servlist *autoent; // filled out by autoconnect
60 struct _nl_list *prev, *next;
61 }
62 nl_list;
63 nl_list *nl_active;
64 nl_list *irc_connect(char *server, const char *portno); // non-blocking NL
65 int irc_conn_found(nl_list **list, fd_set *master, int *fdmax); // non-blocking; call this when the getaddrinfo_a() has finished
66 #else
67 int irc_connect(char *server, const char *portno, fd_set *master, int *fdmax); // non-blocking
b7319a8 Asynch name lookups
ec429 authored
68 #endif
b5829d6 PASS (--pass) and related stuff, also call termsize() at startup
ec429 authored
69 int irc_conn_rest(int b, char *nick, char *username, char *passwd, char *fullname); // call this when the non-blocking connect() has finished
e515989 Allow multiple automatic connects and joins in .quirc
Sound and Fury authored
70 int autoconnect(fd_set *master, int *fdmax, servlist *serv);
9f0cff1 Initial commit.
Sound and Fury authored
71 int irc_tx(int fd, char * packet);
9c521e2 Fix irc_rx() infinite recv() loop
ec429 authored
72 int irc_rx(int fd, char ** data, fd_set *master);
61b2658 irc_breakdown() function, parses :prefix cmd args...
Sound and Fury authored
73
74 message irc_breakdown(char *packet);
7c3fe55 More work on parsing and protocol correctness etc.
Sound and Fury authored
75 void message_free(message pkt);
9add456 Improve PREFIX handling (RPL_ISUPPORT) and :prefix handling
Sound and Fury authored
76 void prefix_split(char * prefix, char **src, char **user, char **host);
77
bfdcd84 Handle Low-Level Quoting
Sound and Fury authored
78 void low_quote(char *from, char to[512]);
79 char * low_dequote(char *buf);
e928ecf Refactor PING, MODE and KILL handling
Sound and Fury authored
80
bdca1e0 More correct casemapping handling (doesn't yet detect from RPL_ISUPPORT)
Sound and Fury authored
81 char irc_to_upper(char c, cmap casemapping);
82 char irc_to_lower(char c, cmap casemapping);
f048496 Some const-correctness
ec429 authored
83 int irc_strcasecmp(const char *c1, const char *c2, cmap casemapping);
84 int irc_strncasecmp(const char *c1, const char *c2, int n, cmap casemapping);
556a521 Functions for irc-style casemapping
Sound and Fury authored
85
d88f242 //text sends message /text (then /// sends //, etc.)
ec429 authored
86 // Send an IRC PRIVMSG (ie. ordinary talking)
87 int talk(char *iinput);
88
6fee724 Some work on the new RX parsing
Sound and Fury authored
89 // Received-IRC message handlers
90 int irc_numeric(message pkt, int b);
8acd80f More work on the new parsing code
Sound and Fury authored
91 int rx_ping(message pkt, int b);
cdd4d11 Implemented MODEs, except that nick-prefixes are never displayed
ec429 authored
92 int rx_mode(message pkt, int b); // the first MODE triggers auto-join
8acd80f More work on the new parsing code
Sound and Fury authored
93 int rx_kill(message pkt, int b, fd_set *master);
94 int rx_kick(message pkt, int b);
95 int rx_error(message pkt, int b, fd_set *master);
bf8886f Much more parsing work
Sound and Fury authored
96 int rx_privmsg(message pkt, int b, bool notice);
8acd80f More work on the new parsing code
Sound and Fury authored
97 int rx_topic(message pkt, int b);
98 int rx_join(message pkt, int b);
99 int rx_part(message pkt, int b);
100 int rx_quit(message pkt, int b);
101 int rx_nick(message pkt, int b);
097f13b Refactoring (CTCP handling from rx_privmsg() to ctcp())
Sound and Fury authored
102
207fa65 Proper CTCP handling
ec429 authored
103 int ctcp_strip(char *msg, const char *src, int b2, bool ha, bool notice, bool priv, bool tx); // Strip the CTCPs out of a privmsg and handle them
104 int ctcp(const char *msg, const char *src, int b2, bool ha, bool notice, bool priv, bool tx); // Handle CTCP (Client-To-Client Protocol) messages
Something went wrong with that request. Please try again.