Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
meek-client-wrapper: only support one --helper behaviour for each pla…
…tform
- Loading branch information
Showing
with
70 additions
and 53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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 | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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 | ||
| } |