-
Notifications
You must be signed in to change notification settings - Fork 2
/
qrcode.c
70 lines (53 loc) · 1.84 KB
/
qrcode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "qrcode.h"
#include "settings.h"
static void QREncode(const char *Msg, const char *Path, const char *Args)
{
char *Tempstr=NULL;
STREAM *S, *StdOut;
Tempstr=MCopyStr(Tempstr, "cmd:qrencode ", Args, NULL);
if (StrValid(Path)) Tempstr=MCatStr(Tempstr, " -o ", Path, NULL);
S=STREAMOpen(Tempstr, "");
if (S)
{
STREAMWriteLine(Msg, S);
STREAMCommit(S);
StdOut=STREAMOpen("stdout:", "");
Tempstr=STREAMReadLine(Tempstr, S);
while (Tempstr)
{
STREAMWriteLine(Tempstr, StdOut);
Tempstr=STREAMReadLine(Tempstr, S);
}
STREAMClose(S);
}
Destroy(Tempstr);
}
void DisplayQRCode(TNet *Net)
{
char *SecureType=NULL, *Tempstr=NULL, *Msg=NULL, *Path=NULL;
STREAM *S;
if (Net->Flags & (NET_WPA1 | NET_WPA2 | NET_RSN)) SecureType=CopyStr(SecureType, "WPA");
else if (Net->Flags & NET_WEP) SecureType=CopyStr(SecureType, "WEP");
else if (StrValid(Net->Key)) SecureType=CopyStr(SecureType, "WPA");
else SecureType=CopyStr(SecureType, "");
Msg=MCopyStr(Msg, "WIFI:S:", Net->ESSID, ";T:", SecureType, ";P:", Net->Key, ";;", NULL);
printf("QRCODE URL: %s\n", Msg);
Path=CopyStr(Path, "/tmp/wifi.png");
if (StrValid(Settings.OutputPath)) Path=CopyStr(Path, Settings.OutputPath);
QREncode(Msg, Path, "");
if (! StrValid(Settings.OutputPath))
{
Tempstr=FindCommandFromList(Tempstr, Settings.ImageViewer);
if (StrValid(Tempstr))
{
if (strcmp(GetBasename(Tempstr), "convert")==0) Tempstr=MCatStr(Tempstr, " ", Path, " sixel:-", NULL);
else Tempstr=MCatStr(Tempstr, " ", Path, NULL);
system(Tempstr);
}
else QREncode(Msg, "", "-t ANSI256");
}
Destroy(SecureType);
Destroy(Tempstr);
Destroy(Path);
Destroy(Msg);
}