2 * Copyright (c) 2016-2019 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>
32 main(int argc
, char **argv
)
43 char *drop_lowest_arg
= 0;
44 long long drop_lowest_ll
= 0;
45 char *drop_lowest
= 0;
46 char *drop_highest_arg
= 0;
47 long long drop_highest_ll
= 0;
48 char *drop_highest
= 0;
51 struct curl_httppost
*post
= 0;
54 setlocale(LC_ALL
, "");
56 while ((opt
= getopt(argc
, argv
, "g:c:n:w:d:D:")) != -1) {
71 drop_lowest_arg
= optarg
;
74 drop_highest_arg
= optarg
;
83 fprintf(stderr
, "course-id is mandatory\n");
89 fprintf(stderr
, "group-id is mandatory\n");
94 weight_d
= strtod(weight_arg
, 0);
95 len
= snprintf(0, 0, "%lf", weight_d
);
98 ret
= errno
= EOVERFLOW
;
103 if (!(weight
= malloc(len
+ 1))) {
109 sprintf(weight
, "%lf", weight_d
);
112 if (drop_lowest_arg
) {
113 drop_lowest_ll
= strtoll(drop_lowest_arg
, 0, 0);
114 len
= snprintf(0, 0, "%lld", drop_lowest_ll
);
117 ret
= errno
= EOVERFLOW
;
122 if (!(drop_lowest
= malloc(len
+ 1))) {
128 sprintf(drop_lowest
, "%lld", drop_lowest_ll
);
131 if (drop_highest_arg
) {
132 drop_highest_ll
= strtoll(drop_highest_arg
, 0, 0);
133 len
= snprintf(0, 0, "%lld", drop_highest_ll
);
136 ret
= errno
= EOVERFLOW
;
141 if (!(drop_highest
= malloc(len
+ 1))) {
147 sprintf(drop_highest
, "%lld", drop_highest_ll
);
150 curl_global_init(CURL_GLOBAL_DEFAULT
);
152 if (!(url_base
= get_url_base())) {
155 /* Error should have already been printed */
159 if (!(auth_token
= get_auth_token())) {
162 /* Error should have already been printed */
166 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups/%s",
167 url_base
, course_id
, group_id
);
170 ret
= errno
= EOVERFLOW
;
175 if (!(built_uri
= malloc(len
+ 1))) {
181 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups/%s",
182 url_base
, course_id
, group_id
);
184 if (!(post
= make_agroup_post(name
, weight
, drop_lowest
,
186 /* XXX: pass back proper error code from make_agroup_post() */
190 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "PUT", 0))) {
203 curl_global_cleanup();