{"action":"created","comment":{"url":"https://api.github.com/repos/alexbrainman/printer/pulls/comments/223196761","pull_request_review_id":161908958,"id":223196761,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyMzE5Njc2MQ==","diff_hunk":"@@ -136,6 +173,120 @@ type DriverInfo struct {\n \tAttributes  uint32\n }\n \n+// PrintJobInfo stores information about a print job.\n+type PrintJobInfo struct {\n+\tJobID           uint32\n+\tUserMachineName string\n+\tUserName        string\n+\tDocumentName    string\n+\tDataType        string\n+\tStatus          string\n+\tStatusCode      uint32\n+\tPriority        uint32\n+\tPosition        uint32\n+\tTotalPages      uint32\n+\tPagesPrinted    uint32\n+\tSubmitted       time.Time\n+}\n+\n+// Jobs returns information about all print jobs on this printer\n+func (p *Printer) Jobs() ([]PrintJobInfo, error) {\n+\tvar bytesNeeded, jobsReturned uint32\n+\tbuf := make([]byte, 1)\n+\tfor {\n+\t\terr := EnumJobs(p.h, 0, 255, 1, &buf[0], uint32(len(buf)), &bytesNeeded, &jobsReturned)\n+\t\tif err == nil {\n+\t\t\tbreak\n+\t\t}\n+\t\tif err != syscall.ERROR_INSUFFICIENT_BUFFER {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tif bytesNeeded <= uint32(len(buf)) {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tbuf = make([]byte, bytesNeeded)\n+\t}\n+\tif jobsReturned <= 0 {\n+\t\treturn nil, nil\n+\t}\n+\tpj := make([]PrintJobInfo, 0, jobsReturned)\n+\tji := (*[2048]JOB_INFO_1)(unsafe.Pointer(&buf[0]))[:jobsReturned]\n+\tfor idx, j := range ji {\n+\t\tpj = append(pj, PrintJobInfo{\n+\t\t\tJobID:        j.JobID,\n+\t\t\tStatusCode:   j.StatusCode,\n+\t\t\tPriority:     j.Priority,\n+\t\t\tPosition:     j.Position,\n+\t\t\tTotalPages:   j.TotalPages,\n+\t\t\tPagesPrinted: j.PagesPrinted,\n+\t\t})\n+\t\t// get strings, checking for nil\n+\t\tif j.MachineName != nil {\n+\t\t\tpj[idx].UserMachineName = syscall.UTF16ToString((*[2048]uint16)(unsafe.Pointer(j.MachineName))[:])\n+\t\t}\n+\t\tif j.UserName != nil {\n+\t\t\tpj[idx].UserName = syscall.UTF16ToString((*[2048]uint16)(unsafe.Pointer(j.UserName))[:])\n+\t\t}\n+\t\tif j.Document != nil {\n+\t\t\tpj[idx].DocumentName = syscall.UTF16ToString((*[2048]uint16)(unsafe.Pointer(j.Document))[:])\n+\t\t}\n+\t\tif j.DataType != nil {\n+\t\t\tpj[idx].DataType = syscall.UTF16ToString((*[2048]uint16)(unsafe.Pointer(j.DataType))[:])\n+\t\t}\n+\t\tif j.Status != nil {\n+\t\t\tpj[idx].Status = syscall.UTF16ToString((*[2048]uint16)(unsafe.Pointer(j.Status))[:])\n+\t\t}\n+\t\tif strings.TrimSpace(pj[idx].Status) == \"\" {\n+\t\t\tswitch j.StatusCode {","path":"printer.go","position":136,"original_position":136,"commit_id":"16a1d9b371590e177e5a59fc487f4f55e691d3ca","original_commit_id":"16a1d9b371590e177e5a59fc487f4f55e691d3ca","user":{"login":"alexbrainman","id":9796621,"node_id":"MDQ6VXNlcjk3OTY2MjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9796621?v=4","gravatar_id":"","url":"https://api.github.com/users/alexbrainman","html_url":"https://github.com/alexbrainman","followers_url":"https://api.github.com/users/alexbrainman/followers","following_url":"https://api.github.com/users/alexbrainman/following{/other_user}","gists_url":"https://api.github.com/users/alexbrainman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbrainman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbrainman/subscriptions","organizations_url":"https://api.github.com/users/alexbrainman/orgs","repos_url":"https://api.github.com/users/alexbrainman/repos","events_url":"https://api.github.com/users/alexbrainman/events{/privacy}","received_events_url":"https://api.github.com/users/alexbrainman/received_events","type":"User","site_admin":false},"body":"This code does not look right. I run your new test here, and see this:\r\n```\r\n    printer_test.go:100: {\r\n           \"JobID\": 3,\r\n           \"UserMachineName\": \"\\\\\\\\UUUU\",\r\n           \"UserName\": \"Alex\",\r\n           \"DocumentName\": \"my document\",\r\n           \"DataType\": \"RAW\",\r\n           \"Status\": \"Unknown\",\r\n           \"StatusCode\": 8210,\r\n           \"Priority\": 1,\r\n           \"Position\": 1,\r\n           \"TotalPages\": 1,\r\n           \"PagesPrinted\": 0,\r\n           \"Submitted\": \"2018-10-06T13:34:01.000021392Z\"\r\n        }\r\n    printer_test.go:100: {\r\n           \"JobID\": 4,\r\n           \"UserMachineName\": \"\\\\\\\\UUUU\",\r\n           \"UserName\": \"Alex\",\r\n           \"DocumentName\": \"my document\",\r\n           \"DataType\": \"RAW\",\r\n           \"Status\": \"Unknown\",\r\n           \"StatusCode\": 0,\r\n           \"Priority\": 1,\r\n           \"Position\": 2,\r\n           \"TotalPages\": 1,\r\n           \"PagesPrinted\": 0,\r\n           \"Submitted\": \"2018-10-06T13:34:21.000020568Z\"\r\n        }\r\n```\r\nand I wondered why Status says 'Unknown'? I think you are misinterpreting the JOB_INFO_1 doco, which says:\r\n```\r\nThe job status. The value of this member can be zero or a combination of one or more of the following values. A value of zero indicates that the print queue was paused after the document finished spooling.\r\n```\r\n- you are not handling Status field being 0;\r\n- you are not treating Status value as \"combination of one or more of the following values.\".","created_at":"2018-10-06T23:47:42Z","updated_at":"2018-10-06T23:54:21Z","html_url":"https://github.com/alexbrainman/printer/pull/7#discussion_r223196761","pull_request_url":"https://api.github.com/repos/alexbrainman/printer/pulls/7","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/comments/223196761"},"html":{"href":"https://github.com/alexbrainman/printer/pull/7#discussion_r223196761"},"pull_request":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/alexbrainman/printer/pulls/7","id":219875694,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE5ODc1Njk0","html_url":"https://github.com/alexbrainman/printer/pull/7","diff_url":"https://github.com/alexbrainman/printer/pull/7.diff","patch_url":"https://github.com/alexbrainman/printer/pull/7.patch","issue_url":"https://api.github.com/repos/alexbrainman/printer/issues/7","number":7,"state":"open","locked":false,"title":"Add PrintJobs function","user":{"login":"kylevanek","id":4075944,"node_id":"MDQ6VXNlcjQwNzU5NDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4075944?v=4","gravatar_id":"","url":"https://api.github.com/users/kylevanek","html_url":"https://github.com/kylevanek","followers_url":"https://api.github.com/users/kylevanek/followers","following_url":"https://api.github.com/users/kylevanek/following{/other_user}","gists_url":"https://api.github.com/users/kylevanek/gists{/gist_id}","starred_url":"https://api.github.com/users/kylevanek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylevanek/subscriptions","organizations_url":"https://api.github.com/users/kylevanek/orgs","repos_url":"https://api.github.com/users/kylevanek/repos","events_url":"https://api.github.com/users/kylevanek/events{/privacy}","received_events_url":"https://api.github.com/users/kylevanek/received_events","type":"User","site_admin":false},"body":"Add PrintJobs function that returns information about all print jobs on a printer","created_at":"2018-10-02T23:32:15Z","updated_at":"2018-10-06T23:54:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"450b55cfdc9aa2eaf3a2bf0f42f41237f29f4346","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/alexbrainman/printer/pulls/7/commits","review_comments_url":"https://api.github.com/repos/alexbrainman/printer/pulls/7/comments","review_comment_url":"https://api.github.com/repos/alexbrainman/printer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alexbrainman/printer/issues/7/comments","statuses_url":"https://api.github.com/repos/alexbrainman/printer/statuses/16a1d9b371590e177e5a59fc487f4f55e691d3ca","head":{"label":"kylevanek:master","ref":"master","sha":"16a1d9b371590e177e5a59fc487f4f55e691d3ca","user":{"login":"kylevanek","id":4075944,"node_id":"MDQ6VXNlcjQwNzU5NDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4075944?v=4","gravatar_id":"","url":"https://api.github.com/users/kylevanek","html_url":"https://github.com/kylevanek","followers_url":"https://api.github.com/users/kylevanek/followers","following_url":"https://api.github.com/users/kylevanek/following{/other_user}","gists_url":"https://api.github.com/users/kylevanek/gists{/gist_id}","starred_url":"https://api.github.com/users/kylevanek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylevanek/subscriptions","organizations_url":"https://api.github.com/users/kylevanek/orgs","repos_url":"https://api.github.com/users/kylevanek/repos","events_url":"https://api.github.com/users/kylevanek/events{/privacy}","received_events_url":"https://api.github.com/users/kylevanek/received_events","type":"User","site_admin":false},"repo":{"id":151195210,"node_id":"MDEwOlJlcG9zaXRvcnkxNTExOTUyMTA=","name":"printer","full_name":"kylevanek/printer","private":false,"owner":{"login":"kylevanek","id":4075944,"node_id":"MDQ6VXNlcjQwNzU5NDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4075944?v=4","gravatar_id":"","url":"https://api.github.com/users/kylevanek","html_url":"https://github.com/kylevanek","followers_url":"https://api.github.com/users/kylevanek/followers","following_url":"https://api.github.com/users/kylevanek/following{/other_user}","gists_url":"https://api.github.com/users/kylevanek/gists{/gist_id}","starred_url":"https://api.github.com/users/kylevanek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylevanek/subscriptions","organizations_url":"https://api.github.com/users/kylevanek/orgs","repos_url":"https://api.github.com/users/kylevanek/repos","events_url":"https://api.github.com/users/kylevanek/events{/privacy}","received_events_url":"https://api.github.com/users/kylevanek/received_events","type":"User","site_admin":false},"html_url":"https://github.com/kylevanek/printer","description":"Windows printing","fork":true,"url":"https://api.github.com/repos/kylevanek/printer","forks_url":"https://api.github.com/repos/kylevanek/printer/forks","keys_url":"https://api.github.com/repos/kylevanek/printer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kylevanek/printer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kylevanek/printer/teams","hooks_url":"https://api.github.com/repos/kylevanek/printer/hooks","issue_events_url":"https://api.github.com/repos/kylevanek/printer/issues/events{/number}","events_url":"https://api.github.com/repos/kylevanek/printer/events","assignees_url":"https://api.github.com/repos/kylevanek/printer/assignees{/user}","branches_url":"https://api.github.com/repos/kylevanek/printer/branches{/branch}","tags_url":"https://api.github.com/repos/kylevanek/printer/tags","blobs_url":"https://api.github.com/repos/kylevanek/printer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kylevanek/printer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kylevanek/printer/git/refs{/sha}","trees_url":"https://api.github.com/repos/kylevanek/printer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kylevanek/printer/statuses/{sha}","languages_url":"https://api.github.com/repos/kylevanek/printer/languages","stargazers_url":"https://api.github.com/repos/kylevanek/printer/stargazers","contributors_url":"https://api.github.com/repos/kylevanek/printer/contributors","subscribers_url":"https://api.github.com/repos/kylevanek/printer/subscribers","subscription_url":"https://api.github.com/repos/kylevanek/printer/subscription","commits_url":"https://api.github.com/repos/kylevanek/printer/commits{/sha}","git_commits_url":"https://api.github.com/repos/kylevanek/printer/git/commits{/sha}","comments_url":"https://api.github.com/repos/kylevanek/printer/comments{/number}","issue_comment_url":"https://api.github.com/repos/kylevanek/printer/issues/comments{/number}","contents_url":"https://api.github.com/repos/kylevanek/printer/contents/{+path}","compare_url":"https://api.github.com/repos/kylevanek/printer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kylevanek/printer/merges","archive_url":"https://api.github.com/repos/kylevanek/printer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kylevanek/printer/downloads","issues_url":"https://api.github.com/repos/kylevanek/printer/issues{/number}","pulls_url":"https://api.github.com/repos/kylevanek/printer/pulls{/number}","milestones_url":"https://api.github.com/repos/kylevanek/printer/milestones{/number}","notifications_url":"https://api.github.com/repos/kylevanek/printer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kylevanek/printer/labels{/name}","releases_url":"https://api.github.com/repos/kylevanek/printer/releases{/id}","deployments_url":"https://api.github.com/repos/kylevanek/printer/deployments","created_at":"2018-10-02T03:27:38Z","updated_at":"2018-10-04T17:51:08Z","pushed_at":"2018-10-04T17:51:06Z","git_url":"git://github.com/kylevanek/printer.git","ssh_url":"git@github.com:kylevanek/printer.git","clone_url":"https://github.com/kylevanek/printer.git","svn_url":"https://github.com/kylevanek/printer","homepage":"","size":17,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"alexbrainman:master","ref":"master","sha":"4e978612df3eec9e647e095d1a1a5768b4bea1f9","user":{"login":"alexbrainman","id":9796621,"node_id":"MDQ6VXNlcjk3OTY2MjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9796621?v=4","gravatar_id":"","url":"https://api.github.com/users/alexbrainman","html_url":"https://github.com/alexbrainman","followers_url":"https://api.github.com/users/alexbrainman/followers","following_url":"https://api.github.com/users/alexbrainman/following{/other_user}","gists_url":"https://api.github.com/users/alexbrainman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbrainman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbrainman/subscriptions","organizations_url":"https://api.github.com/users/alexbrainman/orgs","repos_url":"https://api.github.com/users/alexbrainman/repos","events_url":"https://api.github.com/users/alexbrainman/events{/privacy}","received_events_url":"https://api.github.com/users/alexbrainman/received_events","type":"User","site_admin":false},"repo":{"id":32447564,"node_id":"MDEwOlJlcG9zaXRvcnkzMjQ0NzU2NA==","name":"printer","full_name":"alexbrainman/printer","private":false,"owner":{"login":"alexbrainman","id":9796621,"node_id":"MDQ6VXNlcjk3OTY2MjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9796621?v=4","gravatar_id":"","url":"https://api.github.com/users/alexbrainman","html_url":"https://github.com/alexbrainman","followers_url":"https://api.github.com/users/alexbrainman/followers","following_url":"https://api.github.com/users/alexbrainman/following{/other_user}","gists_url":"https://api.github.com/users/alexbrainman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbrainman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbrainman/subscriptions","organizations_url":"https://api.github.com/users/alexbrainman/orgs","repos_url":"https://api.github.com/users/alexbrainman/repos","events_url":"https://api.github.com/users/alexbrainman/events{/privacy}","received_events_url":"https://api.github.com/users/alexbrainman/received_events","type":"User","site_admin":false},"html_url":"https://github.com/alexbrainman/printer","description":"Windows printing","fork":false,"url":"https://api.github.com/repos/alexbrainman/printer","forks_url":"https://api.github.com/repos/alexbrainman/printer/forks","keys_url":"https://api.github.com/repos/alexbrainman/printer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexbrainman/printer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexbrainman/printer/teams","hooks_url":"https://api.github.com/repos/alexbrainman/printer/hooks","issue_events_url":"https://api.github.com/repos/alexbrainman/printer/issues/events{/number}","events_url":"https://api.github.com/repos/alexbrainman/printer/events","assignees_url":"https://api.github.com/repos/alexbrainman/printer/assignees{/user}","branches_url":"https://api.github.com/repos/alexbrainman/printer/branches{/branch}","tags_url":"https://api.github.com/repos/alexbrainman/printer/tags","blobs_url":"https://api.github.com/repos/alexbrainman/printer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexbrainman/printer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexbrainman/printer/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexbrainman/printer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexbrainman/printer/statuses/{sha}","languages_url":"https://api.github.com/repos/alexbrainman/printer/languages","stargazers_url":"https://api.github.com/repos/alexbrainman/printer/stargazers","contributors_url":"https://api.github.com/repos/alexbrainman/printer/contributors","subscribers_url":"https://api.github.com/repos/alexbrainman/printer/subscribers","subscription_url":"https://api.github.com/repos/alexbrainman/printer/subscription","commits_url":"https://api.github.com/repos/alexbrainman/printer/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexbrainman/printer/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexbrainman/printer/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexbrainman/printer/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexbrainman/printer/contents/{+path}","compare_url":"https://api.github.com/repos/alexbrainman/printer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexbrainman/printer/merges","archive_url":"https://api.github.com/repos/alexbrainman/printer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexbrainman/printer/downloads","issues_url":"https://api.github.com/repos/alexbrainman/printer/issues{/number}","pulls_url":"https://api.github.com/repos/alexbrainman/printer/pulls{/number}","milestones_url":"https://api.github.com/repos/alexbrainman/printer/milestones{/number}","notifications_url":"https://api.github.com/repos/alexbrainman/printer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexbrainman/printer/labels{/name}","releases_url":"https://api.github.com/repos/alexbrainman/printer/releases{/id}","deployments_url":"https://api.github.com/repos/alexbrainman/printer/deployments","created_at":"2015-03-18T08:46:08Z","updated_at":"2018-09-24T01:11:37Z","pushed_at":"2018-10-04T17:51:07Z","git_url":"git://github.com/alexbrainman/printer.git","ssh_url":"git@github.com:alexbrainman/printer.git","clone_url":"https://github.com/alexbrainman/printer.git","svn_url":"https://github.com/alexbrainman/printer","homepage":"","size":14,"stargazers_count":56,"watchers_count":56,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":17,"open_issues":3,"watchers":56,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/7"},"html":{"href":"https://github.com/alexbrainman/printer/pull/7"},"issue":{"href":"https://api.github.com/repos/alexbrainman/printer/issues/7"},"comments":{"href":"https://api.github.com/repos/alexbrainman/printer/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alexbrainman/printer/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/alexbrainman/printer/statuses/16a1d9b371590e177e5a59fc487f4f55e691d3ca"}},"author_association":"NONE"}}
{"actor":{"display_login":"alexbrainman"}}