// PostFindHandle implements the handle for the find document (POST). func PostFindHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) { var userData map[string]string userData = rawhttp.GetFieldsFromPost(httpPayload) var replyBuffer []byte if _, posted := userData["user"]; !posted { replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true) } else { var result string result = preprocessor.ExpandData(roomName, rooms.GetFindResultsHeadTemplate(roomName)) listing := rooms.GetFindResultsBodyTemplate(roomName) availRooms := rooms.GetRooms() user := strings.ToUpper(userData["user"]) if len(user) > 0 { for _, r := range availRooms { users := rooms.GetRoomUsers(r) preprocessor.SetDataValue("{{.find-result-users-total}}", rooms.GetUsersTotal(r)) preprocessor.SetDataValue("{{.find-result-room-name}}", r) for _, u := range users { if strings.HasPrefix(strings.ToUpper(u), user) { preprocessor.SetDataValue("{{.find-result-user}}", u) result += preprocessor.ExpandData(roomName, listing) } } } } result += preprocessor.ExpandData(roomName, rooms.GetFindResultsTailTemplate(roomName)) replyBuffer = rawhttp.MakeReplyBuffer(result, 200, true) } newConn.Write(replyBuffer) newConn.Close() }
func openRooms(configPath string) { var cherryRooms *config.CherryRooms var err *parser.CherryFileError cherryRooms, err = parser.ParseCherryFile(configPath) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { rooms := cherryRooms.GetRooms() for _, r := range rooms { go messageplexer.RoomMessagePlexer(r, cherryRooms) go peer(r, cherryRooms) } } sigintWatchdog := make(chan os.Signal, 1) signal.Notify(sigintWatchdog, os.Interrupt) signal.Notify(sigintWatchdog, syscall.SIGINT|syscall.SIGTERM) <-sigintWatchdog cleanup() }