hexchat/src/common/servlist.c at master · hexchat/hexchat
GTK+ IRC client. Contribute to hexchat/hexchat development by creating an account on GitHub.
https://github.com/fluidicon.png
GitHub
Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Name

Query

To see all available qualifiers, see our documentation.

Sign up

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert

This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

hexchat / hexchat Public archive

Notifications You must be signed in to change notification settings

Fork 535

Latest commit

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

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

/* X-Chat

* Copyright (C) 1998 Peter Zelezny.

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 2 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA

*/

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <sys/types.h>

#include <sys/stat.h>

#ifndef WIN32

#include <unistd.h>

#endif

#include "hexchat.h"

#include "cfgfiles.h"

#include "fe.h"

#include "server.h"

#include "text.h"

#include "util.h" /* token_foreach */

#include "hexchatc.h"

#include "servlist.h"

struct defaultserver

{

char *network;

char *host;

char *channel;

char *charset;

int loginmode; /* default authentication type */

char *connectcmd; /* default connect command - should only be used for rare login types, paired with LOGIN_CUSTOM */

gboolean ssl;

};

static const struct defaultserver def[] =

{

{"2600net", 0},

/* Invalid hostname in cert */

{0, "irc.2600.net"},

{"AfterNET", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.afternet.org"},

{"Aitvaras", 0},

#ifdef USE_OPENSSL

{0, "irc.data.lt/+6668"},

{0, "irc.omicron.lt/+6668"},

{0, "irc.vub.lt/+6668"},

#endif

{0, "irc.data.lt"},

{0, "irc.omicron.lt"},

{0, "irc.vub.lt"},

{"Anthrochat", 0, 0, 0, 0, 0, TRUE},

{0, "irc.anthrochat.net"},

{"ARCNet", 0},

{0, "arcnet-irc.org"},

{"AustNet", 0},

{0, "irc.austnet.org"},

{"AzzurraNet", 0},

{0, "irc.azzurra.org"},

{"Canternet", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.canternet.org"},

{"Chat4all", 0, 0, 0, 0, 0, TRUE},

{0, "irc.chat4all.org"},

{"ChatJunkies", 0},

{0, "irc.chatjunkies.org"},

{"chatpat", 0, 0, "CP1251", LOGIN_CUSTOM, "MSG NS IDENTIFY %p"},

{0, "irc.unibg.net"},

{0, "irc.chatpat.bg"},

{"ChatSpike", 0, 0, 0, LOGIN_SASL},

{0, "irc.chatspike.net"},

{"DaIRC", 0},

{0, "irc.dairc.net"},

{"DALnet", 0, 0, 0, LOGIN_NICKSERV},

/* Self signed */

{0, "us.dal.net"},

{"DarkMyst", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.darkmyst.org"},

#ifdef USE_OPENSSL

{"darkscience", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.darkscience.net"},

{0, "irc.drk.sc"},

{0, "irc.darkscience.ws"},

#endif

{"Dark-Tou-Net", 0},

{0, "irc.d-t-net.de"},

{"DigitalIRC", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.digitalirc.org"},

#ifdef USE_OPENSSL

{"DosersNET", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.dosers.net/+6697"},

#endif

{"EFnet", 0},

{0, "irc.choopa.net"},

{0, "efnet.port80.se"},

{0, "irc.underworld.no"},

{0, "efnet.deic.eu"},

{"EnterTheGame", 0},

{0, "irc.enterthegame.com"},

{"EntropyNet", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.entropynet.net"},

{"EsperNet", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.esper.net"},

{"EUIrc", 0},

{0, "irc.euirc.net"},

{"EuropNet", 0},

/* Self signed */

{0, "irc.europnet.org"},

{"FDFNet", 0},

/* Self signed */

{0, "irc.fdfnet.net"},

{"GameSurge", 0},

{0, "irc.gamesurge.net"},

{"GeekShed", 0, 0, 0, 0, 0, TRUE},

{0, "irc.geekshed.net"},

{"German-Elite", 0, 0, "CP1252"},

{0, "irc.german-elite.net"},

{"GIMPNet", 0},

/* Invalid hostname in cert */

{0, "irc.gimp.org"},

{0, "irc.gnome.org"},

{"GlobalGamers", 0},

#ifdef USE_OPENSSL

{0, "irc.globalgamers.net/+6660"},

#endif

{0, "irc.globalgamers.net"},

#ifdef USE_OPENSSL

{"hackint", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.hackint.org"},

{0, "irc.eu.hackint.org"},

#endif

{"Hashmark", 0},

{0, "irc.hashmark.net"},

{"ICQ-Chat", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.icq-chat.com"},

{"Interlinked", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.interlinked.me"},

{"Irc-Nerds", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.irc-nerds.net"},

{"IRC4Fun", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.irc4fun.net"},

{"IRCNet", 0},

{0, "open.ircnet.net"},

{"IRCtoo", 0},

{0, "irc.irctoo.net"},

{"Keyboard-Failure", 0},

/* SSL is self-signed */

{0, "irc.kbfail.net"},

{"Libera.Chat", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.libera.chat"},

#ifdef USE_OPENSSL

{"LibertaCasa", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.liberta.casa"},

#endif

{"LibraIRC", 0},

/* Self signed */

{0, "irc.librairc.net"},

#ifdef USE_OPENSSL

{"LinkNet", 0},

{0, "irc.link-net.org/+7000"},

#endif

{"MindForge", 0, 0, 0, LOGIN_SASL},

{0, "irc.mindforge.org"},

{"MIXXnet", 0},

{0, "irc.mixxnet.net"},

{"Oceanius", 0, 0, 0, LOGIN_SASL},

/* Self signed */

{0, "irc.oceanius.com"},

{"OFTC", 0, 0, 0, 0, 0, TRUE},

{0, "irc.oftc.net"},

{"OtherNet", 0},

{0, "irc.othernet.org"},

{"OzOrg", 0},

{0, "irc.oz.org"},

{"PIK", 0},

{0, "irc.krstarica.com"},

{"pirc.pl", 0, 0, 0, 0, 0, TRUE},

{0, "irc.pirc.pl"},

{"PTNet", 0},

{0, "irc.ptnet.org"},

{0, "uevora.ptnet.org"},

{0, "claranet.ptnet.org"},

{0, "sonaquela.ptnet.org"},

{0, "uc.ptnet.org"},

{0, "ipg.ptnet.org"},

{"QuakeNet", 0, 0, 0, LOGIN_CHALLENGEAUTH},

{0, "irc.quakenet.org"},

{"Rizon", 0, 0, 0, 0, 0, TRUE},

{0, "irc.rizon.net"},

{"RusNet", 0, 0, "KOI8-R (Cyrillic)"},

/* Self signed */

{0, "irc.tomsk.net"},

{0, "irc.run.net"},

{0, "irc.ru"},

{0, "irc.lucky.net"},

{"Serenity-IRC", 0},

{0, "irc.serenity-irc.net"},

{"SimosNap", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.simosnap.com"},

{"SlashNET", 0},

/* Self signed */

{0, "irc.slashnet.org"},

{"Snoonet", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.snoonet.org"},

{"Sohbet.Net", 0, 0, "CP1254"},

{0, "irc.sohbet.net"},

{"SorceryNet", 0, 0, 0, LOGIN_SASL},

/* Self signed */

{0, "irc.sorcery.net"},

{"SpotChat", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.spotchat.org"},

{"Station51", 0},

/* Self signed */

{0, "irc.station51.net"},

{"StormBit", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.stormbit.net"},

{"SwiftIRC", 0},

/* Expired cert */

{0, "irc.swiftirc.net"},

{"synIRC", 0},

/* Self signed */

{0, "irc.synirc.net"},

{"Techtronix", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.techtronix.net"},

{"TechNet", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.technet.chat"},

{"tilde.chat", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.tilde.chat"},

{"TURLINet", 0, 0, 0, 0, 0, TRUE},

/* all servers use UTF-8 and valid certs */

{0, "irc.servx.org"},

{0, "i.valware.uk"},

#ifdef USE_OPENSSL

{"TripSit", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.tripsit.me"},

{0, "newirc.tripsit.me"},

{0, "coconut.tripsit.me"},

{0, "innsbruck.tripsit.me"},

#endif

{"UnderNet", 0, 0, 0, LOGIN_CUSTOM, "MSG x@channels.undernet.org login %u %p"},

{0, "irc.undernet.org"},

{"Xertion", 0, 0, 0, LOGIN_SASL, 0, TRUE},

{0, "irc.xertion.org"},

{0,0}

};

GSList *network_list = 0;

favchannel *

servlist_favchan_copy (favchannel *fav)

{

favchannel *newfav;

newfav = g_new (favchannel, 1);

newfav->name = g_strdup (fav->name);

newfav->key = g_strdup (fav->key); /* g_strdup() can handle NULLs so no need to check it */

return newfav;

}

void

servlist_connect (session *sess, ircnet *net, gboolean join)

{

ircserver *ircserv;

GSList *list;

char *port;

server *serv;

if (!sess)

sess = new_ircwindow (NULL, NULL, SESS_SERVER, TRUE);

serv = sess->server;

/* connect to the currently selected Server-row */

list = g_slist_nth (net->servlist, net->selected);

if (!list)

list = net->servlist;

if (!list)

return;

ircserv = list->data;

/* in case a protocol switch is added to the servlist gui */

server_fill_her_up (sess->server);

if (join)

{

sess->willjoinchannel[0] = 0;

if (net->favchanlist)

{

if (serv->favlist)

{

g_slist_free_full (serv->favlist, (GDestroyNotify) servlist_favchan_free);

}

serv->favlist = g_slist_copy_deep (net->favchanlist, (GCopyFunc) servlist_favchan_copy, NULL);

}

}

if (net->logintype)

{

serv->loginmethod = net->logintype;

}

else

{

serv->loginmethod = LOGIN_DEFAULT_REAL;

}

serv->password[0] = 0;

if (net->pass)

{

safe_strcpy (serv->password, net->pass, sizeof (serv->password));

}

if (net->flags & FLAG_USE_GLOBAL)

{

strcpy (serv->nick, prefs.hex_irc_nick1);

}

else

{

if (net->nick)

strcpy (serv->nick, net->nick);

}

serv->dont_use_proxy = (net->flags & FLAG_USE_PROXY) ? FALSE : TRUE;

#ifdef USE_OPENSSL

serv->use_ssl = (net->flags & FLAG_USE_SSL) ? TRUE : FALSE;

serv->accept_invalid_cert =

(net->flags & FLAG_ALLOW_INVALID) ? TRUE : FALSE;

#endif

serv->network = net;

port = strrchr (ircserv->hostname, '/');

if (port)

{

*port = 0;

/* support "+port" to indicate SSL (like mIRC does) */

if (port[1] == '+')

{

#ifdef USE_OPENSSL

serv->use_ssl = TRUE;

#endif

serv->connect (serv, ircserv->hostname, atoi (port + 2), FALSE);

} else

{

serv->connect (serv, ircserv->hostname, atoi (port + 1), FALSE);

}

*port = '/';

} else

serv->connect (serv, ircserv->hostname, -1, FALSE);

server_set_encoding (serv, net->encoding);

}

int

servlist_connect_by_netname (session *sess, char *network, gboolean join)

{

ircnet *net;

GSList *list = network_list;

while (list)

{

net = list->data;

if (g_ascii_strcasecmp (net->name, network) == 0)

{

servlist_connect (sess, net, join);

return 1;

}

list = list->next;

}

return 0;

}

int

servlist_have_auto (void)

{

GSList *list = network_list;

ircnet *net;

while (list)

{

net = list->data;

if (net->flags & FLAG_AUTO_CONNECT)

return 1;

list = list->next;

}

return 0;

}

int

servlist_auto_connect (session *sess)

{

GSList *list = network_list;

ircnet *net;

int ret = 0;

while (list)

{

net = list->data;

if (net->flags & FLAG_AUTO_CONNECT)

{

servlist_connect (sess, net, TRUE);

ret = 1;

}

list = list->next;

}

return ret;

}

static gint

servlist_cycle_cb (server *serv)

{

if (serv->network)

{

PrintTextf (serv->server_session,

_("Cycling to next server in %s...\n"), ((ircnet *)serv->network)->name);

servlist_connect (serv->server_session, serv->network, TRUE);

}

return 0;

}

int

servlist_cycle (server *serv)

{

ircnet *net;

int max, del;

net = serv->network;

if (net)

{

max = g_slist_length (net->servlist);

if (max > 0)

{

/* try the next server, if that option is on */

if (net->flags & FLAG_CYCLE)

{

net->selected++;

if (net->selected >= max)

net->selected = 0;

}

del = prefs.hex_net_reconnect_delay * 1000;

if (del < 1000)

del = 500; /* so it doesn't block the gui */

if (del)

serv->recondelay_tag = fe_timeout_add (del, servlist_cycle_cb, serv);

else

servlist_connect (serv->server_session, net, TRUE);

return TRUE;

}

}

return FALSE;

}

ircserver *

servlist_server_find (ircnet *net, char *name, int *pos)

{

GSList *list = net->servlist;

ircserver *serv;

int i = 0;

while (list)

{

serv = list->data;

if (strcmp (serv->hostname, name) == 0)

{

if (pos)

{

*pos = i;

}

return serv;

}

i++;

list = list->next;

}

return NULL;

}

favchannel *

servlist_favchan_find (ircnet *net, char *channel, int *pos)

{

GSList *list;

favchannel *favchan;

int i = 0;

if (net == NULL)

return NULL;

list = net->favchanlist;

while (list)

{

favchan = list->data;

if (g_ascii_strcasecmp (favchan->name, channel) == 0)

{

if (pos)

{

*pos = i;

}

return favchan;

}

i++;

list = list->next;

}

return NULL;

}

commandentry *

servlist_command_find (ircnet *net, char *cmd, int *pos)

{

GSList *list = net->commandlist;

commandentry *entry;

int i = 0;

while (list)

{

entry = list->data;

if (strcmp (entry->command, cmd) == 0)

{

if (pos)

{

*pos = i;

}

return entry;

}

i++;

list = list->next;

}

return NULL;

}

/* find a network (e.g. (ircnet *) to "FreeNode") from a hostname

(e.g. "irc.eu.freenode.net") */

ircnet *

servlist_net_find_from_server (char *server_name)

{

GSList *list = network_list;

GSList *slist;

ircnet *net;

ircserver *serv;

while (list)

{

net = list->data;

slist = net->servlist;

while (slist)

{

gsize hostname_len;

const char *hostname, *p;

serv = slist->data;

hostname = serv->hostname;

/* Ignore port when comparing */

if ((p = strchr (hostname, '/')))

hostname_len = p - hostname;

else

hostname_len = strlen (hostname);

if (g_ascii_strncasecmp (hostname, server_name, hostname_len) == 0)

return net;

slist = slist->next;

}

list = list->next;

}

return NULL;

}

ircnet *

servlist_net_find (char *name, int *pos, int (*cmpfunc) (const char *, const char *))

{

GSList *list = network_list;

ircnet *net;

int i = 0;

while (list)

{

net = list->data;

if (cmpfunc (net->name, name) == 0)

{

if (pos)

*pos = i;

return net;

}

i++;

list = list->next;

}

return NULL;

}

ircserver *

servlist_server_add (ircnet *net, char *name)

{

ircserver *serv;

serv = g_new (ircserver, 1);

serv->hostname = g_strdup (name);

net->servlist = g_slist_append (net->servlist, serv);

return serv;

}

commandentry *

servlist_command_add (ircnet *net, char *cmd)

{

commandentry *entry;

entry = g_new (commandentry, 1);

entry->command = g_strdup (cmd);

net->commandlist = g_slist_append (net->commandlist, entry);

return entry;

}

GSList *

servlist_favchan_listadd (GSList *chanlist, char *channel, char *key)

{

favchannel *chan;

chan = g_new (favchannel, 1);

chan->name = g_strdup (channel);

chan->key = g_strdup (key);

chanlist = g_slist_append (chanlist, chan);

return chanlist;

}

void

servlist_favchan_add (ircnet *net, char *channel)

{

int pos;

char *name;

char *key;

if (strchr (channel, ',') != NULL)

{

pos = (int) (strchr (channel, ',') - channel);

name = g_strndup (channel, pos);

key = g_strdup (channel + pos + 1);

}

else

{

name = g_strdup (channel);

key = NULL;

}

net->favchanlist = servlist_favchan_listadd (net->favchanlist, name, key);

g_free (name);

g_free (key);

}

void

servlist_server_remove (ircnet *net, ircserver *serv)

{

g_free (serv->hostname);

g_free (serv);

net->servlist = g_slist_remove (net->servlist, serv);

}

static void

servlist_server_remove_all (ircnet *net)

{

ircserver *serv;

while (net->servlist)

{

serv = net->servlist->data;

servlist_server_remove (net, serv);

}

}

void

servlist_command_free (commandentry *entry)

{

g_free (entry->command);

g_free (entry);

}

void

servlist_command_remove (ircnet *net, commandentry *entry)

{

servlist_command_free (entry);

net->commandlist = g_slist_remove (net->commandlist, entry);

}

void

servlist_favchan_free (favchannel *channel)

{

g_free (channel->name);

g_free (channel->key);

g_free (channel);

}

void

servlist_favchan_remove (ircnet *net, favchannel *channel)

{

servlist_favchan_free (channel);

net->favchanlist = g_slist_remove (net->favchanlist, channel);

}

static void

free_and_clear (char *str)

{

if (str)

{

char *orig = str;

while (*str)

*str++ = 0;

g_free (orig);

}

}

/* executed on exit: Clear any password strings */

void

servlist_cleanup (void)

{

GSList *list;

ircnet *net;

for (list = network_list; list; list = list->next)

{

net = list->data;

free_and_clear (net->pass);

}

}

void

servlist_net_remove (ircnet *net)

{

GSList *list;

server *serv;

servlist_server_remove_all (net);

network_list = g_slist_remove (network_list, net);

g_free (net->nick);

g_free (net->nick2);

g_free (net->user);

g_free (net->real);

free_and_clear (net->pass);

if (net->favchanlist)

g_slist_free_full (net->favchanlist, (GDestroyNotify) servlist_favchan_free);

if (net->commandlist)

g_slist_free_full (net->commandlist, (GDestroyNotify) servlist_command_free);

g_free (net->encoding);

g_free (net->name);

g_free (net);

/* for safety */

list = serv_list;

while (list)

{

serv = list->data;

if (serv->network == net)

{

serv->network = NULL;

}

list = list->next;

}

}

ircnet *

servlist_net_add (char *name, char *comment, int prepend)

{

ircnet *net;

net = g_new0 (ircnet, 1);

net->name = g_strdup (name);

net->flags = FLAG_CYCLE | FLAG_USE_GLOBAL | FLAG_USE_PROXY;

#ifdef USE_OPENSSL

net->flags |= FLAG_USE_SSL;

#endif

if (prepend)

network_list = g_slist_prepend (network_list, net);

else

network_list = g_slist_append (network_list, net);

return net;

}

static void

servlist_load_defaults (void)

{

int i = 0, j = 0;

ircnet *net = NULL;

guint def_hash = g_str_hash ("Libera.Chat");

while (1)

{

if (def[i].network)

{

net = servlist_net_add (def[i].network, def[i].host, FALSE);

if (def[i].channel)

{

servlist_favchan_add (net, def[i].channel);

}

if (def[i].charset)

{

net->encoding = g_strdup (def[i].charset);

}

else

{

net->encoding = g_strdup (IRC_DEFAULT_CHARSET);

}

if (def[i].loginmode)

{

net->logintype = def[i].loginmode;

}

if (def[i].connectcmd)

{

servlist_command_add (net, def[i].connectcmd);

}

if (def[i].ssl)

{

net->flags |= FLAG_USE_SSL;

}

if (g_str_hash (def[i].network) == def_hash)

{

prefs.hex_gui_slist_select = j;

}

j++;

}

else

{

servlist_server_add (net, def[i].host);

if (!def[i+1].host && !def[i+1].network)

{

break;

}

}

i++;

}

}

static int

servlist_load (void)

{

FILE *fp;

char buf[2048];

int len;

ircnet *net = NULL;

/* simple migration we will keep for a short while */

char *oldfile = g_build_filename (get_xdir (), "servlist_.conf", NULL);

char *newfile = g_build_filename (get_xdir (), "servlist.conf", NULL);

if (g_file_test (oldfile, G_FILE_TEST_EXISTS) && !g_file_test (newfile, G_FILE_TEST_EXISTS))

{

g_rename (oldfile, newfile);

}

g_free (oldfile);

g_free (newfile);

fp = hexchat_fopen_file ("servlist.conf", "r", 0);

if (!fp)

return FALSE;

while (fgets (buf, sizeof (buf) - 2, fp))

{

len = strlen (buf);

if (!len)

continue;

buf[len] = 0;

buf[len-1] = 0; /* remove the trailing \n */

if (net)

{

switch (buf[0])

{

case 'I':

net->nick = g_strdup (buf + 2);

break;

case 'i':

net->nick2 = g_strdup (buf + 2);

break;

case 'U':

net->user = g_strdup (buf + 2);

break;

You can’t perform that action at this time.