Allow overriding the /open utility
parent
362d779b61
commit
2db17e83a9
|
@ -9,6 +9,7 @@
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl ev
|
.Op Fl ev
|
||||||
|
.Op Fl O Ar open
|
||||||
.Op Fl a Ar auth
|
.Op Fl a Ar auth
|
||||||
.Op Fl c Ar cert
|
.Op Fl c Ar cert
|
||||||
.Op Fl h Ar host
|
.Op Fl h Ar host
|
||||||
|
@ -46,6 +47,13 @@ following their corresponding flags.
|
||||||
.Pp
|
.Pp
|
||||||
The arguments are as follows:
|
The arguments are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
|
.It Fl O Ar util , Cm open = Ar util
|
||||||
|
Set the command used by
|
||||||
|
.Ic /open .
|
||||||
|
The default is the first available of
|
||||||
|
.Xr open 1 ,
|
||||||
|
.Xr xdg-open 1 .
|
||||||
|
.
|
||||||
.It Fl a Ar user Ns : Ns Ar pass , Cm sasl-plain = Ar user Ns : Ns Ar pass
|
.It Fl a Ar user Ns : Ns Ar pass , Cm sasl-plain = Ar user Ns : Ns Ar pass
|
||||||
Authenticate as
|
Authenticate as
|
||||||
.Ar user
|
.Ar user
|
||||||
|
|
4
chat.c
4
chat.c
|
@ -81,9 +81,10 @@ int main(int argc, char *argv[]) {
|
||||||
const char *user = NULL;
|
const char *user = NULL;
|
||||||
const char *real = NULL;
|
const char *real = NULL;
|
||||||
|
|
||||||
const char *Opts = "!a:c:eh:j:k:n:p:r:u:vw:";
|
const char *Opts = "!O:a:c:eh:j:k:n:p:r:u:vw:";
|
||||||
const struct option LongOpts[] = {
|
const struct option LongOpts[] = {
|
||||||
{ "insecure", no_argument, NULL, '!' },
|
{ "insecure", no_argument, NULL, '!' },
|
||||||
|
{ "open", required_argument, NULL, 'O' },
|
||||||
{ "sasl-plain", required_argument, NULL, 'a' },
|
{ "sasl-plain", required_argument, NULL, 'a' },
|
||||||
{ "cert", required_argument, NULL, 'c' },
|
{ "cert", required_argument, NULL, 'c' },
|
||||||
{ "sasl-external", no_argument, NULL, 'e' },
|
{ "sasl-external", no_argument, NULL, 'e' },
|
||||||
|
@ -103,6 +104,7 @@ int main(int argc, char *argv[]) {
|
||||||
while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
|
while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
break; case '!': insecure = true;
|
break; case '!': insecure = true;
|
||||||
|
break; case 'O': urlOpenUtil = optarg;
|
||||||
break; case 'a': sasl = true; self.plain = optarg;
|
break; case 'a': sasl = true; self.plain = optarg;
|
||||||
break; case 'c': cert = optarg;
|
break; case 'c': cert = optarg;
|
||||||
break; case 'e': sasl = true;
|
break; case 'e': sasl = true;
|
||||||
|
|
1
chat.h
1
chat.h
|
@ -169,6 +169,7 @@ void completeClear(size_t id);
|
||||||
size_t completeID(const char *str);
|
size_t completeID(const char *str);
|
||||||
enum Color completeColor(size_t id, const char *str);
|
enum Color completeColor(size_t id, const char *str);
|
||||||
|
|
||||||
|
extern const char *urlOpenUtil;
|
||||||
void urlScan(size_t id, const char *nick, const char *mesg);
|
void urlScan(size_t id, const char *nick, const char *mesg);
|
||||||
void urlOpenCount(size_t id, size_t count);
|
void urlOpenCount(size_t id, size_t count);
|
||||||
void urlOpenMatch(size_t id, const char *str);
|
void urlOpenMatch(size_t id, const char *str);
|
||||||
|
|
14
url.c
14
url.c
|
@ -95,7 +95,8 @@ void urlScan(size_t id, const char *nick, const char *mesg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *OpenBins[] = { "open", "xdg-open" };
|
const char *urlOpenUtil;
|
||||||
|
static const char *OpenUtils[] = { "open", "xdg-open" };
|
||||||
|
|
||||||
static void urlOpen(const char *url) {
|
static void urlOpen(const char *url) {
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
@ -105,10 +106,15 @@ static void urlOpen(const char *url) {
|
||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
dup2(procPipe[1], STDOUT_FILENO);
|
dup2(procPipe[1], STDOUT_FILENO);
|
||||||
dup2(procPipe[1], STDERR_FILENO);
|
dup2(procPipe[1], STDERR_FILENO);
|
||||||
for (size_t i = 0; i < ARRAY_LEN(OpenBins); ++i) {
|
if (urlOpenUtil) {
|
||||||
execlp(OpenBins[i], OpenBins[i], url, NULL);
|
execlp(urlOpenUtil, urlOpenUtil, url, NULL);
|
||||||
|
warn("%s", urlOpenUtil);
|
||||||
|
_exit(EX_CONFIG);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < ARRAY_LEN(OpenUtils); ++i) {
|
||||||
|
execlp(OpenUtils[i], OpenUtils[i], url, NULL);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
warn("%s", OpenBins[i]);
|
warn("%s", OpenUtils[i]);
|
||||||
_exit(EX_CONFIG);
|
_exit(EX_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue