Skip to content
Permalink
Browse files

meek-client-wrapper: only support one --helper behaviour for each pla…

…tform
  • Loading branch information...
infinity0 committed Oct 6, 2015
1 parent 43a35d3 commit 6b21c416a54d382c61918308a4b868eb1b2141c5
@@ -0,0 +1,55 @@
// +build windows

package main

import (
"errors"
"bufio"
"log"
"os"
"strings"
)

const browserHelperToCmdLineHelp = "path to descriptor file for browser helper executable"

// Convert the helper filename into a command line string slice
func browserHelperToCmdLine(browserHelperPath string) (command []string, err error) {
var file *os.File
file, err = os.Open(browserHelperPath)
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
settingEnv := true
for scanner.Scan() {
line := scanner.Text()
if line == "" || strings.HasPrefix(line, "#") {
continue
} else if settingEnv && strings.Contains(line, "=") {
envpair := strings.SplitN(line, "=", 2)
if envpair[1] == "" {
log.Printf("unset envvar %s", envpair[0])
err = os.Unsetenv(envpair[0])
} else {
log.Printf("set envvar %s=%s", envpair[0], envpair[1])
err = os.Setenv(envpair[0], envpair[1])
}
if err != nil {
return
}
} else {
settingEnv = false
command = append(command, line)
}
}
err = scanner.Err()
if err != nil {
return
}
if (len(command) == 0) {
err = errors.New("no commands in meek-browser-helper file: " + browserHelperPath)
return
}
return
}
@@ -7,10 +7,9 @@
// a meek-client command line.
//
// This program, meek-client-wrapper, starts a browser-helper program specified
// by the --helper option. This is executed with no arguments; use a shell
// script if you need something more complex. Alternatively, you may point to a
// file with the ".meek-browser-helper" suffix, which is a basic custom format
// for specifying what to execute. An example of its format:
// by the --helper option. On non-Windows platforms, this is executed with no
// arguments; use a shell script if you need something more complex. On Windows,
// this file instead *describes* what to execute. An example of its format:
//
// -- begin example file --
// # comments and empty lines are ignored
@@ -38,7 +37,6 @@ package main

import (
"bufio"
"errors"
"flag"
"fmt"
"io"
@@ -48,7 +46,6 @@ import (
"os/exec"
"os/signal"
"regexp"
"strings"
"syscall"
)

@@ -80,52 +77,6 @@ func logSignal(p *os.Process, sig os.Signal) error {
return err
}

// Convert the helper filename into a command line string slice
func browserHelperToCmdLine(browserHelperPath string) (command []string, err error) {
if (strings.HasSuffix(browserHelperPath, ".meek-browser-helper")) {
var file *os.File
file, err = os.Open(browserHelperPath)
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
settingEnv := true
for scanner.Scan() {
line := scanner.Text()
if line == "" || strings.HasPrefix(line, "#") {
continue
} else if settingEnv && strings.Contains(line, "=") {
envpair := strings.SplitN(line, "=", 2)
if envpair[1] == "" {
log.Printf("unset envvar %s", envpair[0])
err = os.Unsetenv(envpair[0])
} else {
log.Printf("set envvar %s=%s", envpair[0], envpair[1])
err = os.Setenv(envpair[0], envpair[1])
}
if err != nil {
return
}
} else {
settingEnv = false
command = append(command, line)
}
}
err = scanner.Err()
if err != nil {
return
}
if (len(command) == 0) {
err = errors.New("no commands in meek-browser-helper file: " + browserHelperPath)
return
}
} else {
command = []string{browserHelperPath}
}
return
}

// Run browser helper and return its exec.Cmd and stdout pipe.
func runBrowserHelper(browserHelperPath string) (cmd *exec.Cmd, stdout io.Reader, err error) {
var command []string
@@ -197,7 +148,7 @@ func main() {

flag.Usage = usage
flag.StringVar(&logFilename, "log", "", "name of log file")
flag.StringVar(&browserHelperPath, "helper", "", "path to browser helper executable")
flag.StringVar(&browserHelperPath, "helper", "", browserHelperToCmdLineHelp)
flag.Parse()

if logFilename != "" {
@@ -0,0 +1,11 @@
// +build !windows

package main

const browserHelperToCmdLineHelp = "path to browser helper executable"

// Convert the helper filename into a command line string slice
func browserHelperToCmdLine(browserHelperPath string) (command []string, err error) {
command = []string{browserHelperPath}
return
}

0 comments on commit 6b21c41

Please sign in to comment.
You can’t perform that action at this time.