2 * Copyright (c) 2016, S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include <curl/curl.h>
26 #include <yajl_parse.h>
31 int main(int argc
, char **argv
)
42 char *drop_lowest_arg
= 0;
43 long long drop_lowest_ll
= 0;
44 char *drop_lowest
= 0;
45 char *drop_highest_arg
= 0;
46 long long drop_highest_ll
= 0;
47 char *drop_highest
= 0;
50 struct curl_httppost
*post
= 0;
53 setlocale(LC_ALL
, "");
55 while ((opt
= getopt(argc
, argv
, "g:c:n:w:d:D:")) != -1) {
70 drop_lowest_arg
= optarg
;
73 drop_highest_arg
= optarg
;
82 fprintf(stderr
, "course-id is mandatory\n");
88 fprintf(stderr
, "group-id is mandatory\n");
93 weight_d
= strtod(weight_arg
, 0);
94 len
= snprintf(0, 0, "%lf", weight_d
);
97 ret
= errno
= EOVERFLOW
;
102 if (!(weight
= malloc(len
+ 1))) {
108 sprintf(weight
, "%lf", weight_d
);
111 if (drop_lowest_arg
) {
112 drop_lowest_ll
= strtoll(drop_lowest_arg
, 0, 0);
113 len
= snprintf(0, 0, "%lld", drop_lowest_ll
);
116 ret
= errno
= EOVERFLOW
;
121 if (!(drop_lowest
= malloc(len
+ 1))) {
127 sprintf(drop_lowest
, "%lld", drop_lowest_ll
);
130 if (drop_highest_arg
) {
131 drop_highest_ll
= strtoll(drop_highest_arg
, 0, 0);
132 len
= snprintf(0, 0, "%lld", drop_highest_ll
);
135 ret
= errno
= EOVERFLOW
;
140 if (!(drop_highest
= malloc(len
+ 1))) {
146 sprintf(drop_highest
, "%lld", drop_highest_ll
);
149 curl_global_init(CURL_GLOBAL_DEFAULT
);
151 if (!(url_base
= get_url_base())) {
154 /* Error should have already been printed */
158 if (!(auth_token
= get_auth_token())) {
161 /* Error should have already been printed */
165 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups/%s",
166 url_base
, course_id
, group_id
);
169 ret
= errno
= EOVERFLOW
;
174 if (!(built_uri
= malloc(len
+ 1))) {
180 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups/%s",
181 url_base
, course_id
, group_id
);
183 if (!(post
= make_agroup_post(name
, weight
, drop_lowest
,
185 /* XXX: pass back proper error code from make_agroup_post() */
189 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "PUT", 0))) {
202 curl_global_cleanup();