- Timestamp:
- Apr 30, 2020, 2:10:39 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/upstream.go
r281 r282 15 15 "gopkg.in/irc.v3" 16 16 ) 17 18 // permanentUpstreamCaps is the static list of upstream capabilities always 19 // requested when supported. 20 var permanentUpstreamCaps = map[string]bool{ 21 "away-notify": true, 22 "batch": true, 23 "labeled-response": true, 24 "message-tags": true, 25 "server-time": true, 26 } 17 27 18 28 type upstreamChannel struct { … … 1210 1220 func (uc *upstreamConn) requestCaps() { 1211 1221 var requestCaps []string 1212 for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time", "away-notify"}{1222 for c := range permanentUpstreamCaps { 1213 1223 if _, ok := uc.supportedCaps[c]; ok && !uc.caps[c] { 1214 1224 requestCaps = append(requestCaps, c) … … 1220 1230 } 1221 1231 1222 if len(requestCaps) > 0 { 1232 if len(requestCaps) == 0 { 1233 return 1234 } 1235 1236 uc.SendMessage(&irc.Message{ 1237 Command: "CAP", 1238 Params: []string{"REQ", strings.Join(requestCaps, " ")}, 1239 }) 1240 } 1241 1242 func (uc *upstreamConn) requestSASL() bool { 1243 if uc.network.SASL.Mechanism == "" { 1244 return false 1245 } 1246 1247 v, ok := uc.supportedCaps["sasl"] 1248 if !ok { 1249 return false 1250 } 1251 if v != "" { 1252 mechanisms := strings.Split(v, ",") 1253 found := false 1254 for _, mech := range mechanisms { 1255 if strings.EqualFold(mech, uc.network.SASL.Mechanism) { 1256 found = true 1257 break 1258 } 1259 } 1260 if !found { 1261 return false 1262 } 1263 } 1264 1265 return true 1266 } 1267 1268 func (uc *upstreamConn) handleCapAck(name string, ok bool) error { 1269 uc.caps[name] = ok 1270 1271 switch name { 1272 case "sasl": 1273 if !ok { 1274 uc.logger.Printf("server refused to acknowledge the SASL capability") 1275 return nil 1276 } 1277 1278 auth := &uc.network.SASL 1279 switch auth.Mechanism { 1280 case "PLAIN": 1281 uc.logger.Printf("starting SASL PLAIN authentication with username %q", auth.Plain.Username) 1282 uc.saslClient = sasl.NewPlainClient("", auth.Plain.Username, auth.Plain.Password) 1283 default: 1284 return fmt.Errorf("unsupported SASL mechanism %q", name) 1285 } 1286 1223 1287 uc.SendMessage(&irc.Message{ 1224 Command: "CAP", 1225 Params: []string{"REQ", strings.Join(requestCaps, " ")}, 1226 }) 1227 } 1288 Command: "AUTHENTICATE", 1289 Params: []string{auth.Mechanism}, 1290 }) 1291 default: 1292 if permanentUpstreamCaps[name] { 1293 break 1294 } 1295 uc.logger.Printf("received CAP ACK/NAK for a cap we don't support: %v", name) 1296 } 1297 return nil 1228 1298 } 1229 1299 … … 1291 1361 } 1292 1362 1293 func (uc *upstreamConn) requestSASL() bool {1294 if uc.network.SASL.Mechanism == "" {1295 return false1296 }1297 1298 v, ok := uc.supportedCaps["sasl"]1299 if !ok {1300 return false1301 }1302 if v != "" {1303 mechanisms := strings.Split(v, ",")1304 found := false1305 for _, mech := range mechanisms {1306 if strings.EqualFold(mech, uc.network.SASL.Mechanism) {1307 found = true1308 break1309 }1310 }1311 if !found {1312 return false1313 }1314 }1315 1316 return true1317 }1318 1319 func (uc *upstreamConn) handleCapAck(name string, ok bool) error {1320 uc.caps[name] = ok1321 1322 switch name {1323 case "sasl":1324 if !ok {1325 uc.logger.Printf("server refused to acknowledge the SASL capability")1326 return nil1327 }1328 1329 auth := &uc.network.SASL1330 switch auth.Mechanism {1331 case "PLAIN":1332 uc.logger.Printf("starting SASL PLAIN authentication with username %q", auth.Plain.Username)1333 uc.saslClient = sasl.NewPlainClient("", auth.Plain.Username, auth.Plain.Password)1334 default:1335 return fmt.Errorf("unsupported SASL mechanism %q", name)1336 }1337 1338 uc.SendMessage(&irc.Message{1339 Command: "AUTHENTICATE",1340 Params: []string{auth.Mechanism},1341 })1342 case "message-tags", "labeled-response", "away-notify", "batch", "server-time":1343 // Nothing to do1344 default:1345 uc.logger.Printf("received CAP ACK/NAK for a cap we don't support: %v", name)1346 }1347 return nil1348 }1349 1350 1363 func (uc *upstreamConn) readMessages(ch chan<- event) error { 1351 1364 for {
Note:
See TracChangeset
for help on using the changeset viewer.